AVR Studio source-line debugging in non .text linker section

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have found (and submitted to Atmel) a problem with source-line debugging in linker sections other than .text. Since the problem may be specific to GCC, I'm posting to this forum

In an ATmega2560, function pointers can be a problem since the pointers are all kept as 16-bit integers, but the function can reside in upper memory, thus requiring a 17th bit (actually, a third byte). This means that if the function is located in the top half of flash, the function call fails (horribly, in fact - usually I get a really nasty crash followed by a reset).

I decided to modify the linker script to create a new section in low flash so all functions pointed at by function pointers would resolve correctly. Example of linker script:

  /* Internal text space or external memory.  */
  .text :
  {
    *(.vectors)
    KEEP(*(.vectors))
    *(.length)
    /* KEEP(*(.length)) - don't need to keep if it isn't defined */
    /* For data that needs to reside in the lower 64k of progmem.  */
    *(.progmem.gcc*)
    *(.progmem*)
    . = ALIGN(2);
 . . .
    KEEP (*(.init7))
    *(.init8)
    KEEP (*(.init8))
    *(.init9)  /* Call main().  */
    KEEP (*(.init9))
    /* Interrupt Service Routine code needs to be in the lower 128K program */
    *(.isr)
    KEEP(*(.isr))
    /* Any code that is the target of a function pointer must also 
       reside in lower memory */
    *(.fptr_target)
    KEEP(*(.fptr_target))
    *(.text)
    . = ALIGN(2);
    *(.text.*)
    . = ALIGN(2);
    *(.fini9)  /* _exit() starts here.  */
. . .

When I say "non .text section", I mean the default code section .text inside the main section .text (whatever the nomenclature calls it).

At any rate, anything not within the *(.text) section cannot be used for source-line debugging. That means that you cannot go to the source and place breakpoints, nor can you step through code.

Yes, you can still assign breakpoints using the Disassembly mode. PITA, but it works.
You might have noticed that I also have a .isr section above. This may not be required by the gcc compiler, since the trampolines might work there, but it seems to be safer with my m2560.

At any rate, no comment required here. Just a heads-up for those who may play with different linker sections. No workaround either, other than linking "test" routines into the main .text sections, then moving them back when you're done debugging them.

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!