* Useful dbxrc set -o path # path searching is enabled and use common unix commands # enabled by default. ignore SIGUSR1 ignore SIGUSR2 dbxenv lookaside on Commands: search : search the current file for the string regex. bsearch : search backwards dalias : make an alias for a debugging command. kill : kill only the debugged process. detach: just detach from the process and allow the process to run further. dbx - pid : To attach to the process without specifying the exe file. pathmap : to specify the source file path modules -a : list the names of all prog modules module : print the name of current module modules -debug : print names of modules with debug info list : To visit a new function when you are at somewhere else. scope resolution for symbols: `var : global variable `a.c`var : file static variable or function name `a.c`func`var : variable in the function `a.c`func:20`var : variable at file a.c inside function func, line number 20. For block specific variable. stop in #.mul_func : Prefix # to specify the linker name print `foo.c`#staticvar : specify the linker name whatis var : Tells the type whereis var : Tells where in all modules the var is found whatis -t : prints type info whatis -e : prints type info of expression trace func : whenever this func is called, who called with what args trace lineno : echo when it is executed trace expr at lineno : stop modify &variable : stop when variable is modified stop variable : same as above with subtle diff, auto alloc of var is a change. stop if condition; stop event-spec; when event-spec { dbx-cmd; [...]} status, clear, handler -disable, delete, ... step up; : eqvt to: when returns { stop; echo returned to $func } cont or when in func { stop returns; } event-spec is one of the following events: in func, at lineno, at filename:lineno, infunction func (same as in func), expression (when it becomes true), returns, returns func, step (event when PC reaches the source line), next, sig , fault [FLTILL|FLTPE|...], stop, sync(process has execed. Doesn't work with "stop". Use with "when"). lastrites (process is about to die), dlopen, dlclose, modify addr-expr bytesize, (used to watch a block of memory being modified), sysin code|name (sys call about to be executed), sysout code|name (sys call about to be returned to usermode) omitting code|name will trace all syscalls. Event-spec modifiers could filter the events: -if cond, if cond, in func, -count n, -count infinity (stop at 10 -count 100, stops only 100th time of reaching the same line. ), -temp (temp handler. once stoped gets deleted), -instr (applies to instruction level), -thread tid, -lwp id Predefined variables: $pc, $ins, $lineno, $line, $func, $file, $caller, $proc, $thread, $lwp, $syscode, $sysname (for use with sysin,sysout events), Syntax for call: call func(par1,par2) Unconditional Go to line no: cont at assign =; #Saving and restoring a debug run: save file restore file up, down, frame, -h +/-number Show hidden frames, go up or down to get the current scope info for name resolution. #using examine command examine &main examine &addr1,&addr2 examine &addr1/ # e.g. examine &func/10i : 10asm instrs from func # e.g. examine &data/10d : 10dec ints from data Instead of examine you can also use dis where fmt is understood as "i". # listi 90,100 displays asm instructions for c source 90 to 100. To turn on runtime checking (for uninitialized memory access, etc.) dbx> check -all or invoke: dbx -C a.out dbx is ksh compatible for most purposes. Note that backquotes is not implemented. Use -xs (not -Xs) compiler option to put debug info into the executable. gdb syntax: break --- stop in function info breakpoints -- show status - dbx if encountered internal error, changes to /tmp, invokes dbx on itself to get the stack trace, then calls abort(); to core dump itself. Uses sigaction to capture the signal--> within the signal handler immediately set the handler to SIG_DFL, so that stack never overflows in case of multiple signal problems with in signal handler; - Use following useful commands: psig -- to print all the signals caught by a process pstack -- to get the stack trace pfiles -- all openfiles pmap -- to get process map Use: /usr/ucb/ps -wwagx ; Complete command however long. /usr/ucb/ps -aww ; /usr/ucb/ps auxww ; Complete env variables how ever long it is. gdb 4.4. Logging output You may want to save the output of gdb commands to a file. There are several commands to control gdb's logging. set logging on Enable logging. set logging off Disable logging. set logging file file Change the name of the current logfile. The default logfile is gdb.txt. set logging overwrite [on|off] By default, gdb will append to the logfile. Set overwrite if you want set logging on to overwrite the logfile instead. set logging redirect [on|off] By default, gdb output will go to both the terminal and the logfile. Set redirect if you want output to go only to the log file. show logging Show the current values of the logging settings. Use: gdb -tui for text user interface. info win SRC (23 lines) CMD (7 lines) winheight SRC +5 winheight CMD -3 until, u like step, run till current line changes to next line. but this will come out of single line loop. tty /dev/ttya sets controlling terminal for future run commands. ======================================================================== gdb tracepoint: Ideal when like to print without stopping. However supported only with gdbserver running: You need to set up a remote debugging session (which can still be done on a single machine): gdbserver :10000 ./a.out # start gdbserver listening on port 10000 In another window: gdb -ex 'target remote :10000' ./a.out ========================================================================