How to Not Emit Local Symbols in Nasm So That Gdb Disas Won't Stop at Them

How to not emit local symbols in NASM so that GDB disas won't stop at them?

I haven't found a way to do it directly with nasm, however if you link your object with ld, then you have at your disposal a very handy switch.
Quoting from ld's man page:

-x --discard-all
Delete all local symbols.

-X --discard-locals
Delete all temporary local symbols. (These symbols start with
system-specific local label prefixes, typically .L for ELF
systems or L for traditional a.out systems.)

so if you have, for example, this:

section .data
hello: db 'Hello world!',10
helen: equ $-hello
hi: db 'Hi!',10
hilen: equ $-hi
section .text
global _start
_start:
mov eax,4
mov ebx,1
mov ecx,hello
mov edx,helen
int 80h
.there:
mov eax,4
mov ebx,1
mov ecx,hi
mov edx,hilen
int 80h
.end:
mov eax,1
mov ebx,0
int 80h

and then build, link (and run) it like this:

$ nasm -g -f elf32 prog.asm && ld -x prog.o -o prog && ./prog
Hello world!
Hi!

then, when you load it in gdb, you get this:

$ gdb prog
.....
Reading symbols from prog...done.
(gdb) disas _start
Dump of assembler code for function _start:
0x08048080 <+0>: mov $0x4,%eax
0x08048085 <+5>: mov $0x1,%ebx
0x0804808a <+10>: mov $0x80490b8,%ecx
0x0804808f <+15>: mov $0xd,%edx
0x08048094 <+20>: int $0x80
0x08048096 <+22>: mov $0x4,%eax
0x0804809b <+27>: mov $0x1,%ebx
0x080480a0 <+32>: mov $0x80490c5,%ecx
0x080480a5 <+37>: mov $0x4,%edx
0x080480aa <+42>: int $0x80
0x080480ac <+44>: mov $0x1,%eax
0x080480b1 <+49>: mov $0x0,%ebx
0x080480b6 <+54>: int $0x80
End of assembler dump.
(gdb)

where the disassembly is not hindered by the local symbols any more.

How to generate gdb symbol file with nasm?

It would say try it like this:

  1. use "-f elf -F dwarf -g" switches when assembling. This should produce elf file that contains debug symbols (and code and everything else).
  2. Use objcopy to generate binary file.
  3. Load binary file to your system.
  4. Attach debugger, then tell it to load symbols from your .elf file (symbol-file yourfile.elf)

You need to solve why nasm can't generate .elf file with .org you have in there. I have no idea. GNA as is fine with this.



Related Topics



Leave a reply



Submit