0

I'm trying to remote debug compiled code for arm on qemu. But I cannot set breakpoints based on symbols.

Below is my mk script:

ARM=arm-none-eabi
QEMU=qemu-system-arm

$ARM-as -o ts.o ts.s -g
$ARM-ld -T t.ld -o t.elf ts.o
$ARM-nm t.elf
$ARM-objcopy -O binary t.elf t.bin

dd if=t.bin of=flash.bin bs=4096 conv=notrunc

$QEMU -s -S -M realview-pbx-a9 -kernel t.bin -nographic -serial /dev/null

I actually got ts.o with symbols, since the output of arm-none-eabi-nm -a ts.o is:

00000000 n .ARM.attributes
00000004 d Array
00000000 b .bss
00000000 d .data
00000000 N .debug_abbrev
00000000 N .debug_aranges
00000000 N .debug_info
00000000 N .debug_line
00000000 N .debug_str
00000018 t loop
00000000 d N
0000002c d Result
00000000 T start
00000004 t stop
00000008 t sum
00000000 t .text

But the output of arm-none-eabi-nm -a t.elf is:

00010048 t Array
00010018 t loop
00010044 t N
00010070 t Result
00011160 T stack_top
00010000 T start
00010004 t stop
00010008 t sum
00010000 t .text
00000000 a ts.o

You can see that t.elf doesn't have symbols. So I guess something was wrong.

By the way, I tried gdb ts.o to debug, actually I could use symbols in this situation but the position of breakpoint was wrong since I changed the start section location. See t.ld:

ENTRY(start)
SECTIONS
{
  . = 0x10000;
  .text : { ts.o }
  .text : { *(.text) }
  .data : { *(.data) }
  .bss  : { *(.bss)  }
  . = ALIGN(8);
  . = . + 0x1000; /* 4kB of stack memory */
  stack_top = .;
  .debug_aranges  0 : { *(.debug_aranges) }
  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
  .debug_abbrev   0 : { *(.debug_abbrev) }
  .debug_line     0 : { *(.debug_line) }
  .debug_frame    0 : { *(.debug_frame) }
  .debug_str      0 : { *(.debug_str) }
  .debug_loc      0 : { *(.debug_loc) }
  .debug_macinfo  0 : { *(.debug_macinfo) }
}

EDIT: I found that if I link another .o file generated by .c file like below:

arm-none-eabi-as -mcpu=arm926ej-s -g ts.s -o ts.o
arm-none-eabi-gcc -c -mcpu=arm926ej-s -g t.c -o t.o

arm-none-eabi-ld -T t.ld ts.o t.o -o t.elf

Then t.elf has debug symbols for the c file, but why I can't get debug symbols for the assembly file?

shino
  • 71
  • 7

1 Answers1

0

You can see that t.elf doesn't have symbols.

We can see that it does have symbols. It just doesn't have debug sections.

See t.ld

Well, your linker script tells the linker to ignore all the .debug_* sections, so that's exactly what it did.

See the DWARF2 section here on how to preserve these sections instead.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • I added all the code in `DWARF2` section in my linker script, but it seemed still not work, maybe I did something wrong? – shino May 26 '23 at 05:19