# DEBNT: Debugging

GDB:

NT09B contains the GDB. This version of the GDB allows to debug Win32 and bound programs under Win95 and WinNT.

You can debug normal emx programs with the command “RSX GDB„. This command starts the GDB under DOS (DPMI).

Prepare for debugging:

Debug switches:

You should use the GCC switch ‘-g‚ and the Win32 switches -Zwin32 or -Zrsx32.

Example for GUI programs:

        gcc -g -Zwin32 gui-test.c

Example for bound programs:

        gcc -g -Zrsx32 boundprg.c

### Debugging with GDB:

Sample session:

    C:\RSXNT\SAMPLE\CONSOLE\ARGVENV>gdb argvenv.exe
    GDB is free software and you are welcome to distribute copies of it
     under certain conditions; type "show copying" to see the conditions.
    There is absolutely no warranty for GDB; type "show warranty" for details.
    GDB 4.15 (rsxnt), Copyright 1995 Free Software Foundation, Inc...

    (gdb) list main        <- lists the main function

    19          }
    20          return 0;
    21      }
    22
    23      int main(int argc, char **argv, char **env)
    24      {
    25          int i;
    26
    27      #if 0
    28      #if defined (__EMX__)

    (gdb) tb 25            <- break point at line 25

    Breakpoint 1 at 0x410107: file argvenv.c, line 25.

    (gdb) run arg1 arg2        <- runs program with 2 arguments

    Starting program: c:/rsxnt/sample/console/argvenv/argvenv.exe arg1 arg2
    main (argc=3, argv=0x71fa94, env=0x71fa28) at argvenv.c:35
    35          printf("Environment:\n");

    (gdb) print argv[1]        <- prints variable

    $1 = 0x71faa7 "arg1"

    (gdb) next            <- execute program one line

    36          for (i=0;env[i]!=NULL;++i)
    (gdb) n            <- execute program one line

    37              printf("%02d: %s\n",i,env[i]);

    (gdb) c            <- continue program execution
    Continuing.

    Program exited normally.

    (gdb) quit            <- exit gdb

    C:\RSXNT\SAMPLE\CONSOLE\ARGVENV>

### Debugging with DEBNT:

You should use DEBNT only for low-level debugging.

Output from debugger:

`C:\RSXNT\SAMPLE\DUAL>debnt rshell.exe`

    child PID 3
    debugging file rshell.exe
    GNUAOUT HEADER
    text   = 00007000
    data   = 00001000
    bss    = 00001440
    entry  = 00410000
    syms   = 00003864

    eip=00410000 eflags=00000a86
    eax=00410000 ebx=005c0000 ecx=0061ff68 edx=bffc2a10
    esp=0061fe3c ebp=0061ff78 esi=81530ff0 edi=8153133c
    cs=0137 ds=013f es=013f ss=013f
    __text():
    00410000: 6800004200     push    __data
    cmd:

First command:

    cmd:go main
    _main() (rshell.c#319): {
    00410dd0: 55             push    ebp
    cmd:list
    _main() (rshell.c#319): {
    00410dd0: 55             push    ebp
    00410dd1: 89e5           mov     ebp,esp
    00410dd3: 81ec04030000   sub     esp,0x304
    00410dd9: e83e0a0000     call    ___main

Help:

cmd:help

    go <v>       g - go or continue execution
    cont <v>     c - continue execution
    step         s - step through instruction
    next         n - step to next instruction
    list <v>     l - list instructions at <v>
    dump <v>     d - dump memory at <v>
    disp v         - display symbol v
    reg <m> <v>  r - show/set registers
    where        w - display list of active functions
    find         f - find a symbol/location (wildcard)
    bp v           - set breakpoint at v
    bx no          - x=List/Clear/Dis-/Enable breakpoint no
    set m v <s>    - memory to value; size=byte/word
    process        - show process data
    sel s <n>      - show n selectors start with s
    shell argv     - execute other program
    quit         q - terminate debugger
    help         ? - this text