Tu Do
2017-Oct-05 15:48 UTC
[syslinux] How do I debug com32 modules with GDB using DWARF format?
Hi list, I ran a syslinux drive on a QEMU machine with a gdbstub opened. I tried the simplest modules: the hello.c in com32/samples/ directory, which is compiled into hello.c32 in bios/com32/samples/. I already compiled the module with debug info attached via -g option added to CFLAGS in the Makefile. However, the problem is that the generated module is a shared dynamic module, which only contains relative address. Because of this, the generated debug info is also wrong because the actual addresses are absolute addresses and the debug info must match them. How do I fix this problem? Is there a way to generate the correct mapping at compile time, so I can feed it to GDB when it starts? Thanks.
Gene Cumm
2017-Oct-09 17:11 UTC
[syslinux] How do I debug com32 modules with GDB using DWARF format?
On Thu, Oct 5, 2017 at 11:48 AM, Tu Do via Syslinux <syslinux at zytor.com> wrote:> Hi list, > > I ran a syslinux drive on a QEMU machine with a gdbstub opened. I tried the simplest modules: the hello.c in com32/samples/ directory, which is compiled into hello.c32 in bios/com32/samples/. I already compiled the module with debug info attached via -g option added to CFLAGS in the Makefile.I can't say I've ever tried using gdb against COM32 modules.> However, the problem is that the generated module is a shared dynamic module, which only contains relative address. Because of this, the generated debug info is also wrong because the actual addresses are absolute addresses and the debug info must match them.SYSLINUX v4.00 made it dynamic. COM32R means relocatable. I'd consider either using a breakpoint then, if gdb allows, realign to the new address, OR just use printf()/dprintf() calls as necessary. dprintf() use would require a SYSLINUX core with such enabled and a real serial port and probably only be applicable for BIOS. Care to elaborate on what you're attempting to debug?> How do I fix this problem? Is there a way to generate the correct mapping at compile time, so I can feed it to GDB when it starts? > > Thanks.Hope that helps. -- -Gene
Tu Do
2017-Oct-09 17:43 UTC
[syslinux] How do I debug com32 modules with GDB using DWARF format?
On 10/10/17 12:11 AM, Gene Cumm wrote:> > I can't say I've ever tried using gdb against COM32 modules. >Well, in syslinux v5.00 and above, com32 modules are effectively built as ELF. Btw, I already found a way, though not perfect: - Create a FAT bootable disk image using "syslinux --install". - Copy hello.c32 module and load it in syslinux.cfg. - Find the starting address of the sample module, hello.c32, in memory. For my case, it's 0x37b000 because the main function is at 0x37b210. 0x210 is the start of .text section in hello.c32. - With the starting address, I can reliably pass to gdb the correct starting address of .text section, so it can jump to the correct code when connecting to QEMU with a gdb stub. The only remaining problem is how to reliably find out the starting address of the first COM32R module, so I don't have to manually insert hello.c32 every time I build a different syslinux version. Any idea is highly appreciated, thanks. > Care to elaborate on what you're attempting to debug? Currently, I'm trying to debug a module that must run on a BIOS environment, boot by syslinux. So, it will need to switch to real mode temporary for using the services, then switch back to protected mode. At the moment, syslinux v5.00 and above seem to abandon BIOS and is forcing the modules to run in protected mode. But that'll be for another topic. Tu.
Apparently Analagous Threads
- How do I debug com32 modules with GDB using DWARF format?
- How do I debug com32 modules with GDB using DWARF format?
- some issues with modules/syslinux
- menu.c32 is not a COM32R image
- Acceptable version mismatch between syslinux 6.0N's MBR/ldlinux.sys and *.c32?