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.
- 
                    Why kdbg rather than WinDbg? And which compiler? And what build options? Details please! – David Heffernan Aug 21 '11 at 20:58
- 
                    please add gcc and ubuntu tags otherwise you question is ambiguous. Kdbg is a kernel debugger on windows. – David Heffernan Aug 22 '11 at 07:21
2 Answers
Add a .file directive in your source, like: .file "sourceasm.s". Kdbg will then use it as expected.
 
    
    - 31
- 2
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 x86 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 -Fdwarfto 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.
 
    
    - 328,167
- 45
- 605
- 847
- 
                    `kdbg is not a very good choice for asm debugging` Is *ddd* the only good choice for a GUI asm debugger on Linux? – MWB Oct 05 '20 at 04:06
- 
                    @MaxB: IDK, I haven't gone looking. `gdbgui` is not bad, and has probably improved since I last checked. There might be something decent built-in to one of the IDEs, too, bug again I haven't checked. – Peter Cordes Oct 05 '20 at 04:13
 
    