views:

171

answers:

1

I cannot figure out how to get GAS to emit line number debugging information for gdb in assembly. Note that I'm using the avr-gcc cross compiler, but doubt that is relevant.

I'm using the following command line options to assemble: avr-gcc -g -ggdb -Os -mmcu=atmega644 -ffunction-sections -fsigned-char -Winvalid-pch -Wall -Wno-long-long -x assembler-with-cpp -Wa,-ggdb -c -o z813.o z813.s

When I use a nearly identical set of arguments to compile C code, I can see the line number and source file augmentation using 'objdump -l -d'.

However the assembly objects have none. ie


000000d4 <run_timetable>:
      d4:       0e 94 57 00     call    0xae    ; 0xae <run_timetable_row>
      d8:       0e 94 b4 00     call    0x168   ; 0x168 <delay>

vs

00000f9c :
main():
/home/braddock/work/tviki/tviki/scratch/z813-vid.c:68
     f9c:       0e 94 ae 07     call    0xf5c   ; 0xf5c <init>
/home/braddock/work/tviki/tviki/scratch/z813-vid.c:70
     fa0:       0e 94 6a 00     call    0xd4    ; 0xd4 <run_timetable>

When in avr-gdb (via simulavr remote gdb connection), I cannot get the debugger to single step through my assemble code, although it does recognize the symbol names and information. I assume this is related.

I put in good effort trying to find this in info/man/google and permuting the likely flags. Any help appreciated!

+3  A: 

When you "compile" assembler source code, invoking the C compiler is somewhat overkill. The compiler will recognize that the input is a C file, and ignore any options that you pass it that affect C compilation, such as -g and -Os. Pass "-v" to the compiler line to see the options that get actually passed to the assembler.

When I assemble with

avr-as --gstabs -mmcu=atmega644 a.s -o a.o

then I get nice-looking source line information in the object file. My version of avr-as (2.18.0) doesn't support a -ggdb option at all, it only has -g, --gstabs, --gstabs+, --gdwarf-2. With stabs, objdump is able to display the lines. With dwarf-2, it's not - I'm not sure whether that's a bug in objdump or in as.

If you absolutely insist on invoking the assembler as "gcc", you should pass -Wa,--gstabs.

Martin v. Löwis
Thank you! The --gstabs option did it. Not sure why I didn't get a complaint about the invalid -ggdb option I was trying (which I think I had changed from the --dwarf-2 setting, which as you note really didn't work - I think I saw some option for a seperate line number file for that mode later). I am running as via gcc because I need the full preprocessor, and also wasn't sure which flags were ignored or passed. Can't figure out how to invoke cpp from gas directly, but you've inspired to me to take the time to trim my flags... :)
braddock
braddock