simulator: breakpoint not hit on main()

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

minor issue:

normally, i set a breakpoint on the opening "{" of a function in order to break there. it does not work for the main() function.

int main(void)
{//main
  int i=0;
  while(1)
  {
    i++;
    i--;
  }
}

1) set to Debug mode, build
2) set breakpoints on every line
3) "run" in simulator
4) simulator will break on "int i=0;" and not on "{//main"

btw: breakpoint on line "int main(void)" says "unable to set breakpoint". bp on "{//main" does not complain.

setting breakpoint on opening "{" for all other functions seems to work.

EDIT: I am talking about Debug mode.

Last Edited: Wed. Mar 23, 2011 - 01:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That entire function will be optimized to a single "RET" so there won't be any other code to break on. Suggest you make 'i' volatile and if you don't understand why read my article about this in the Tutorial Forum.

(as that tutorial will tell you, the way to debug optimised code is to work with the interleaved C+Asm view where you can see code re-ordering and discards, if you'd done that this time you'd have seen that main() has been discarded - well everything but a RET)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would be surprised, if this function was compiled into a single RET - even in Release mode. Look closely ;)

I am talking about debug mode in that OP. I will change the OP to reflect that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah yes, your lack of indentation or code tags (which I edited in above) meant that I missed the point. Of course it compiles (with optimisation) to be:

0000006c 
: #include int main(void) {//main 6c: ff cf rjmp .-2 ; 0x6c

So an single RJMP rather than a single RET. Obviously 'i' never exists and any line referring to it will not be break-pointable as there will be no associated code.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All optimization higher than -O0 will produce a single rjmp to itself. Have you looked at the disassembly?

Hans-Christian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For completeness sake here is the Makefile (it is necessary to use this custom makefile, I have posted an issue with the build system in another thread):

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init
SHELL := cmd.exe
RM := rm -rf

USER_OBJS :=

LIBS := 
PROJ := 

O_SRCS := 
C_SRCS := 
S_SRCS := 
S_UPPER_SRCS := 
OBJ_SRCS := 
ASM_SRCS := 
PREPROCESSING_SRCS := 
OBJS := 
OBJS_AS_ARGS := 
C_DEPS := 
C_DEPS_AS_ARGS := 
EXECUTABLES := 
OUTPUT_FILE_PATH :=
OUTPUT_FILE_PATH_AS_ARGS :=
HEX_FLASH_FILE_PATH :=
HEX_FLASH_FILE_PATH_AS_ARGS :=
HEX_EEPROM_FILE_PATH :=
HEX_EEPROM_FILE_PATH_AS_ARGS :=
LSS_FILE_PATH :=
LSS_FILE_PATH_AS_ARGS :=
MAP_FILE_PATH :=
MAP_FILE_PATH_AS_ARGS :=
AVR_APP_PATH :=C:/Programme/Atmel/AVR Studio 5.0/extensions/Application/Avr ToolChain/bin/
QUOTE := "
ADDITIONAL_DEPENDENCIES:=

# Every subdirectory with source files must be described here
SUBDIRS := 


# Add inputs and outputs from these tool invocations to the build variables 
C_SRCS +=  \
../attiny10_gcc.c


PREPROCESSING_SRCS += 


ASM_SRCS += 


OBJS +=  \
attiny10_gcc.o


OBJS_AS_ARGS +=  \
attiny10_gcc.o


C_DEPS +=  \
attiny10_gcc.d


C_DEPS_AS_ARGS +=  \
attiny10_gcc.d


OUTPUT_FILE_PATH +=attiny10_gcc.elf

OUTPUT_FILE_PATH_AS_ARGS +=attiny10_gcc.elf

HEX_FLASH_FILE_PATH +=attiny10_gcc.hex

HEX_FLASH_FILE_PATH_AS_ARGS +=attiny10_gcc.hex

HEX_EEPROM_FILE_PATH +=attiny10_gcc.eep

HEX_EEPROM_FILE_PATH_AS_ARGS +=attiny10_gcc.eep

LSS_FILE_PATH +=attiny10_gcc.lss

LSS_FILE_PATH_AS_ARGS +=attiny10_gcc.lss

MAP_FILE_PATH =attiny10_gcc.map

MAP_FILE_PATH_AS_ARGS =attiny10_gcc.map

ADDITIONAL_DEPENDENCIES:= size

# AVR/GNU C Compiler



./%.o: .././%.c ../attiny10_gcc.avrgccproj
	@echo Building file: $<
	@echo Invoking: AVR/GNU C Compiler
	$(QUOTE)$(AVR_APP_PATH)avr-gcc.exe$(QUOTE) -funsigned-char -funsigned-bitfields -O0 -fpack-struct -fshort-enums -g2 -Wall -c  -mmcu=attiny10   -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
	@echo Finished building: $<



# AVR/GNU Assembler




ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 

# All Target
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)

# AVR/GNU C Linker
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS)
	@echo Building target: $@
	@echo Invoking: AVR/GNU C Linker
	$(QUOTE)$(AVR_APP_PATH)avr-ld.exe$(QUOTE)  -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS)
	@echo Finished building target: $@



$(HEX_FLASH_FILE_PATH): $(OUTPUT_FILE_PATH)
	$(QUOTE)$(AVR_APP_PATH)avr-objcopy.exe$(QUOTE) -O ihex -R .eeprom -R .fuse -R .lock -R .signature  $(QUOTE)$<$(QUOTE) $(QUOTE)$@$(QUOTE)

$(HEX_EEPROM_FILE_PATH): $(OUTPUT_FILE_PATH)
	-$(QUOTE)$(AVR_APP_PATH)avr-objcopy.exe$(QUOTE) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex $(QUOTE)$<$(QUOTE) $(QUOTE)$@$(QUOTE) || exit 0

$(LSS_FILE_PATH): $(OUTPUT_FILE_PATH)
	$(QUOTE)$(AVR_APP_PATH)avr-objdump.exe$(QUOTE) -h -S $(QUOTE)$<$(QUOTE) > $(QUOTE)$@$(QUOTE)

size: $(OUTPUT_FILE_PATH)
	@$(QUOTE)$(AVR_APP_PATH)avr-size.exe$(QUOTE) -C --mcu=attiny10 $(OUTPUT_FILE_PATH_AS_ARGS)

# Other Targets
clean:
	-$(RM) $(OBJS_AS_ARGS)$(C_DEPS_AS_ARGS) $(QUOTE)$(EXECUTABLES)$(QUOTE) $(OUTPUT_FILE_PATH_AS_ARGS) $(HEX_FLASH_FILE_PATH_AS_ARGS) $(HEX_EEPROM_FILE_PATH_AS_ARGS) $(LSS_FILE_PATH_AS_ARGS) $(MAP_FILE_PATH_AS_ARGS)

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

and this is the file being compiled:

/*
 * attiny10_gcc.c
 *
 * Created: 23.03.2011 12:32:45
 *  Author: Besitzer
 */ 

#include 

int main(void)
{
	int i=0;
    while(1)
    {
		i++;
		i--;
        //TODO:: Please write your application code 
    }
}

Maybe someone can verify/falsify the issue with AVRStudio5? ;)

EDIT for clarification:
The simulator will break on "int i=0;" and NOT on "{//main". Expected behaviour is: break on "{//main".