LooPer
LooPer

Reputation: 1479

Debug assembly code using Kdbg

I have a project with one .c C source code and one .S assembly source code. Once compiled and linked, is there any way to debug .S code using Kdbg? I am calling one .S function from .c file but no code loads in Kdbg.

Upvotes: 3

Views: 2285

Answers (2)

Peter Cordes
Peter Cordes

Reputation: 364180

I I just tried kdbg (the KDE front-end for gdb, not the Linux kernel debugger kgdb of almost the same name).

It doesn't seem to have a proper disassembly mode like regular gdb's layout asm. You can set the "memory" window to disassembly and the address to $pc (and it updates as you single step), but that ties up the memory window and isn't very flexible for setting breakpoints or scrolling backwards to instructions before the current RIP/EIP.

Even if you're debugging asm source, you sometimes want to have the debugger show you the real disassembly, as well / instead of the asm source. For example in code that uses macros, or NASM %rep to repeat blocks.

AFAICT, kdbg is not a very good choice for asm debugging. text-mode GDB with layout asm / layout reg is ok; see the bottom of the tag wiki for tips. I've also tried https://github.com/cs01/gdbgui. It has a disassembly mode, but it's not very nice.


As @ivan says, kgdb will let you do source level debugging of asm source files if you add enough metadata for it to know what source file the object came from.

  • gcc: Build with gcc -g foo.S
  • NASM: Assemble with nasm -felf64 -g -Fdwarf to include DWARF debug info. (The NASM default is STABS debug info, which also works.)
  • YASM: Assemble with yasm -felf64 -gdwarf2.

See Assembling 32-bit binaries on a 64-bit system (GNU toolchain) for more about building static / dynamic binaries from asm source.

Upvotes: 3

ivan
ivan

Reputation: 31

Add a .file directive in your source, like: .file "sourceasm.s". Kdbg will then use it as expected.

Upvotes: 3

Related Questions