Next: , Previous: DL.h, Up: Interface


4.9 GDB.h: sending plain gdb commands to the debugger

`GDB.h' provides macros for generating user specified commands in the output of the `nana' command. They are not included by default in the `nana.h' file. Note that these macros have no effect unless you run your program under the debugger and read in the commands generated by the `nana' command. You also need to compile the program with the `-g' option.

— Macro: void GDB (command)

Emit a single line command when running this file through `nana'. Note that each line must be passed off separately to the `GDB' macro.

This could be used to set debugger options or to define procedures inside `gdb', e.g.

            GDB(define checkstack);
            GDB(  if 0 <= n && n <= 10);
            GDB(    print "stack ok");
            GDB(  else);
            GDB(    print "stack corrupted");
            GDB(  end);
            GDB(end);
     
— Macro: void GDBCALL (command)

Causes a single gdb command to be executed whenever control passes through this line of code. After the user's command is executed control automatically returns to the program.

            GDBCALL(set memory_check = 1)
     

These macros could used for instrumenting code or setting up test harnesses, e.g.

     
     GDB(set $siocall = 0);
     GDB(set $sioerr = 0);
     
     void sio_driver() {
       GDBCALL(set $siocall++)
       if(SIO_REQ & 0x010) {
         GDBCALL(set $sioerr++);
         ...
       }
     }