Skip to content
Advertisement

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

I’m trying to write some assembly programs using nasm on linux. Everything is good, but I make heavy use of local symbols (.loop, .else, etc.), which is a pain when debugging, because these symbols are emitted to the symbol table, e.g.:

JavaScript

will produce a disassembly that looks like:

JavaScript

which is a bit annoying just because gdb will think these are all separate functions, so when I ‘disas’ it will only disassemble a couple of instructions before it runs into another label and stops.

Is there a way to suppress emitting these symbols to the ELF symbol table using nasm under linux?

Advertisement

Answer

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:

JavaScript

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

JavaScript

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

JavaScript

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

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement