Skip to content
Andrew Bird edited this page Mar 2, 2024 · 6 revisions

Debugging with GDB

Running Dosemu under gdb

  • Add the following to your ~/.gdbinit file to avoid unnecessary stopping.
handle SIG34 nostop noprint
  • Use the -gdb argument to the dosemu script
dosemu -gdb
  • You can set breakpoints on Dosemu code easily
Reading symbols from /home/user1/dosemu2.git/2.0-pre9/bin/dosemu.bin...
(gdb) break mhp_dosbreak
Breakpoint 1 at 0x4f2880: file mhpdbgc.c, line 2959.
  • You can set breakpoints on FDPP code (late loading)
(gdb) break DosGetVolumeInfo
Function "DosGetVolumeInfo" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (DosGetVolumeInfo) pending.

FDPP tips and tricks

  • If using meson to build, then omit the --buildtype=release argument to configure.meson to enable debugging symbols

  • To dereference FAR pointers in FDPP, you can add this macro to ~/.gdbinit

macro define fp2unix(p) &lowmem_base[(p.ptr.seg<<4)+p.ptr.off]

Then use it as

(gdb) p fp2unix(cdsp)
$5 = (uint8_t *) 0x7fffc46c55a0 "C:\\"
  • To have some knowledge of structures
macro define asstruct(t, v) (struct t *) &lowmem_base[(v.ptr.seg<<4)+v.ptr.off]

Then use

(gdb) p asstruct(cds, cdsp)
$8 = (cds *) 0x7fffc46c55a0

(gdb) p *asstruct(cds, cdsp)
$11 = {cdsCurrentPath = "C:\\", '\000' <repeats 63 times>, cdsFlags = 49280, cdsDpb = {ptr = {off = 7074, seg = 64150}},
 _cdsUnion = {_cdsRedirRec = {ptr = {off = 0, seg = 65535}}, _cdsRedir = {_cdsStrtClst = 0, _cdsParam = 65535}},
 cdsStoreUData = 65535, cdsBackslashOffset = 2, cdsNetFlag1 = 0 '\000', cdsIfs = {ptr = {off = 0, seg = 0}}, cdsNetFlags2 = 0}