gdb dbx
Invocation
gdb program dbx progam
gdb program core dbx program core
gdb program pid dbx program pid
gdb -c core dbx - core
gdb -p pid dbx - pid
Note: need to specify program explicitly (program is found automatically)
Note: dbx cannot debug core files and live process
es without access to program file, i.e. a.out
gdb -s file -
(read symbols from file)
gdb -x file dbx ... < file
dbx -s file ...
-tty device dbxenv run_io pty
(Run using device for your program’s standard inp dbxenv run_pty device
ut and output)
-write (open executable and core file for writing) -
Exiting
quit exit
Ctrl-d
Executing shell commands
shell command ksh/sh command
Note: you can use any ksh command, including
function definition. See “help ksh differences” for
limitations.
Logging
set logging dbxenv session_log_file_name file
show logging dbxenv session_log_file_name
- dbxenv output_log_file_name file
dbxenv output_log_file_name
(logs only commands, not their output)
set logging redirect [on|off] -
Note: equivalent to off
gdb dbx
set logging overwrite [on|off] -
Note: equivalent to on
Commands (general)
Abbreviation - automatic (can use 's' instead of Need to use ksh 'alias' command to define aliases
'step')
Auto-completion with Tab No auto-completion
Command repeat with Ret Command repeat with '!' and UpArrow Ret
Built-in help
help [command] help [command]
apropos keyword help -k keyword
Debugging information support
stabs (GNU), dwarf2, -g -O stabs (SUN), dwarf2, -g -O
Macro support (-g3) Macro support (-g3); Sun Studio compilers don't
generate debug info for macros, though.
(status unknown) .ldynsym support (symbols in stripped loadobject)
Starting a program
run [arguments][ < input_file] [ > output_file run [arguments][ < input_file] [ > output_file]
start -
(run and stop in “main”) Note: only available in GUI mode when used from
Sun Studio IDE
Program environment
set args args runargs args
show args debug
path dir PATH=dir:$PATH
show paths echo $PATH
set environment varname [=value ] varname=value
unset environment varname unset varname
cd directory cd directory
gdb dbx
pwd pwd
- any other ksh command (with certain limitations;
see “help ksh differences”)
Attaching
attach pid attach pid
debug program pid
debug - pid
detach detach
- detach -stop
Killing the child process
kill kill (builtin)
/usr/bin/kill
Debugging Multithreaded Applications
info threads threads
thread threadno thread threadid
- thread -info [threadid]
- thread -blocks [threadid] thread -blockedby [threa
did]
- syncs
(list all synchronization objects).
Note: available on Solaris only.
- sync -info addr
(show information about synchronization object).
Note: available on Solaris only.
thread apply [threadno] [all] command -
- lwps
- lwp lwpid
- lwp [lwpid] -info
(displays the name, home, and masked signals)
- lwp [lwpid] -setfp addr
gdb dbx
lwp [lwpid] -resetfp
(temporarily set frame pointer to specified value)
- OpenMP support.
Debugging Programs with Multiple Processes
set follow-fork-mode parent dbxenv follow_fork_mode parent
set follow-fork-mode child dbxenv follow_fork_mode child
- dbxenv follow_fork_mode ask
set detach-on-fork on/off -
Note: always detaches; it is possible to debug both
processes, but only using Sun Studio IDE
info forks -
fork fork-id
detach fork fork-id
delete fork fork-id
Process snapshots
checkpoint -
info checkpoints Note: dbx has different mechanism for that; see
restart checkpoint-id “help save/restore/replace” commands for more
delete checkpoint checkpoint-id information.
Breakpoints
break function stop in function
break +offset stop at $[$lineno+offset]
break -offset stop at $[$lineno – offset]
Note: you can define helper function in .dbxrc that
will save you from typing all that stuff.
break [filename:]linenum stop at [filename:]linenum
break filename:function -
break \*address stopi at address
stop at address -instr
break -
(stop on next instruction in current stack frame) Note: Can use “stopi at $npc”, but on sparc only
gdb dbx
break ... if cond stop ... -if cond
condition bnum expression
condition bnum -
(removes condition)
tbreak args stop ... -temp
- stop inmethod func
stop inmember func
stop infunction func
stop inclass classname [ -recurse | -norecurse ]
inobject object_address [ -recurse | -norecurse ]
step; cont stop step
next; cont stop next
catch signal [signame ] stop sig signal [code]
- stop fault <fault>
catch throw [ exceptname] intercept [-all] [-x] [-set] [typename]
Note: not very useful since stop after exception is stop throw [-unhandled] [-unexpected] [typename]
thrown; doesn't work in code called from gdb
catch catch [exceptname] -
Note: use “whocatches” command
catch stop stop stop
- stop attach stop detach
- stop sync
- stop syncrtld
- stop lastrites (Solaris only)
catch load [ lib-path ] stop dlopen [ lib-path ]
catch unload [ lib-path ] stop dlclose [ lib-path ]
Note: unavailable on Linux and Solaris
- stop exit [ exitcode ]
catch fork stop sysin [sysin code|name]
catch vfork stop sysout [sysin code|name]
catch exec
Note: no other system calls are supported
gdb dbx
finish stop returns [func]
Note: can't specify function to catch return from Note: has bug(s), still unresolved.
- stop lwp_exit (Solaris only)
catch exit stop proc_gone
catch start stop prog_new
Note: not implemented on Linux and Solaris
tcatch ... stop ... -temp
- stop timer seconds
watch variable stop change variable
Note: need to re-enable manually
watch expr stop if expr
Note: need to re-enable manually stop cond expr
mem addr-expr addr-expr mode stop access mode addr-expr [ , byte-size-expr
rwatch <expr> -
awatch <expr>
Note: need to re-enable manually, doen't work on
Solaris and Linux.
catch thread_start stop thr_exit [-thread tid]
catch thread_exit stop thr_create [ tid ]
catch thread_join -
- stop ... -resumeone
(when evaluating stop condition, resume only one
thread).
- stop ... -in func
ignore bnum count stop ... -count count
handler -count count bnum
break linespec thread threadno stop ... -thread tid
- stop ... -lwp lwpid
hbreak args -
thbreak args
rbreak regex -
gdb dbx
Note: need to use funcs command and manually set
breakpoints with “stop in”
info breakpoints [n] status [n]
info watchpoints [n]
clear clear
clear linenum clear linenum
clear filename:linenum clear filename:linenum
clear function -
clear filename:function
delete [breakpoints] [range ...] delete [breakpoints]
delete all
Pending breakpoints -
Note: you can load shared library with “loadobject
-load lib” and set breakpoints after that or run your
program once without any breakpoints so that dbx
become aware of all libraries.
set breakpoint auto-hw on/off -
disable [breakpoints] [range ...] handler -disable [breakpoints]
enable [breakpoints] [range ...] handler -enable [breakpoints]
enable [breakpoints] once range ... -
enable [breakpoints] delete range ...
commands [bnum ] when ... { cmd; }
... command-list ... wheni ... { cmd; }
end
- trace next
trace at lineno
trace in func
trace modify addr-expr [ , byte-size-expr ]
trace ...
Continuing and Stepping
continue [ignore-count ] cont
fg [ignore-count ]
step [count] step [count] [tid | lwpid]
gdb dbx
next [count] next [count] [tid | lwpid]
set step-mode on stepi [count] [tid | lwpid]
stepi [count]
nexti [count] nexti [count] [tid | lwpid]
- step to [func]
- step ... -sig signal
until [location] -
(Execute until the program reaches a source line
greater than the current or specified location).
advance location cont at line
Signals
info signals info handle catch, ignore
handle signal stop catch signal
handle signal nostop ignore signal
handle signal print when sig signal { print $signal; print $sigstr; }
trace sig signal
handle signal noprint -
Note: no information is printed about ignored signa
ls
handle signal pass ignore signal
handle signal noignore
handle signal nopass -
handle signal ignore Note: use cont with no -sig to cancel current signal
after stopping because of it
Examining the Stack
backtrace [n] where [n]
bt [n]
backtrace [-n] -
bt [-n]
backtrace full [n] -
gdb dbx
set backtrace past-main on/off -
set backtrace past-entry on/off -
- hide [ regular_expression ]
unhide [ number | regular_expression ]
unhide
(hide stack frames in “where” command output)
set backtrace limit n dbxenv stack_max_size n
set backtrace limit 0
(default is unlimited) Note: default is 100; no “unlimited” option
show backtrace limit dbxenv stack_max_size
echo $DBX_stack_max_size
frame [args] frame [n]
Note: can't use address to identify stack frame
select-frame [args] > /dev/null frame [n]
up [n] up [n]
down [n] down [n]
up-silently [n] > /dev/null up [n]
down-silently [n] > /dev/null down [n]
frame where 1
info frame -
info locals dump
info catch whocatches type
Examining Source Files
list linenum list -w linenum
list function list function
- list -a function (lists entire function)
list list
list - list -10
set listsize count dbxenv output_list_size count
show listsize dbxenv output_list_size
gdb dbx
list first,last list first,last
list ,last list last, - [n]
list first, list first,+[n]
list + list [+N]
list - list - [N]
list \*address -
- file [filename] (view or set current file)
edit $EDITOR filename
edit number
edit function
edit filename:number Note: need to find source file manually with 'where
edit filename:function is [-a]' command.
edit \*address
forward-search regexp search [string]
search regexp
reverse-search regexp bsearch [string]
Specifying Source Directories
directory dirname ... use [dirname]
dir dirname ... Note: “use” is deprecated and replaced with pathm
directory ap.
set substitute-path from to pathmap from to
unset substitute-path [path] pathmap -d [path]
show substitute-path [path] pathmap
Source and Machine Code
info line linespec -
Note: need to look at “list -i linespec” output
disassemble [addr] dis [addr]
- dis -a [addr]
(disassemble entire function)
- list -i [linespec]
gdb dbx
(intermix source lines and assembly code)
Examining Data
print /f expr print -f expr
print /f -
- > FILE print ...
(print to a file)
Artifcial arrays (p \*array@len) -
- Array slicing (p array[2..5])
- Pretty-printing (allows an application to provide it's
own rendition of an expressions value through a
function call, see “help prettyprint”).
x/nfu addr x addr [/nf]
examine addr [/nf]
Note: unit size is governed by format, 'f'
display[/fmt] expr display [-f fmt] expr
undisplay dnums ... undisplay dnums ...
delete display dnums ...
disable display dnums ... -
enable display dnums ...
display display
- watch
(same as display, but expression is re-parsed at eac
h stopping point)
set print address on/off -
set print symbol-filename on/off -
set print max-symbolic-offset max-offset -
set print array on/off -
(equivalent to off)
set print array-indexes on/off -
(equivalent to off)
gdb dbx
set print elements number-of-elements -
set print repeats -
set print null-stop -
set print pretty on/off -
Note: equivalent to “on”
set print sevenbit-strings on/off -
set print union on/off -
set print demangle on/off -
set print asm-demangle on/off Note: usually both forms are displayed
set print object on/off print -d ...
Note: equivalent to “on”
set print static-members on/off -
set print vtbl on/off -
$ (previously printed expression) -
show values (values history) -
Convenience variables Environment variables
Example: set $foo = \*object_ptr Example: foo=$[\*object_ptr]
Note: these variables are typed. Note: type of expression is not recorded in the vari
able.
show convenience set
init-if-undefined $variable = expression -
info registers regs
info all-registers regs -f | -F
info registers regname ... print $regname
info float (floating point registers only) -
info vector -
info udot -
info auxv -
gdb dbx
cache/nocache (cache target memory) -
Memory access checking
set mem inaccessible-by-default [on|off] -
- check -access
- check -memuse
- check -leaks
C Preprocessor Macros
macro expand expression -
macro exp expression
macro expand-once expression -
info macro macro -
macro define macro [(arglist)] replacement-list -
macro undef macro
macro list -
Examining the Symbol Table
info address symbol -
Note: “print &symbol” should suffice.
info symbol addr whereis -a addr
Note: with 'check -memuse', shows allocation stack
for heap-allocated memory region.
whatis arg whatis [-e] arg
ptype arg whatis [-e] arg
info types [regexp] whatis -t [typename]
info scope location -
info source module -v
file
Note: dwarf info is not displayed correctly for
object files.
info sources modules -v
files
gdb dbx
info functions regexp funcs regexp
info variables -
(All global and static variable names, or those mat
ching REGEXP)
Altering execution
set var=value assign var=value
assign $reg=value assign $reg=value
jump linespec cont at linespec
jump \*address assign $pc=address; cont
signal signal cont -sig signal
return pop
return expression -
print expr print expr
call expr call expr
Note: abnormal termination affects debuggee Note: abnormal termination doesn't affect debugge
e; use “pop -c” to “cancel” call.
set unwindonsignal -
Note: equivalent to off
set write on/off -
(open executable or core for writing) Note: equivalent to off
- fix
Debugging Information in Separate Files
set debug-file-directory directory dbxenv debug_file_directory directory
show debug-file-directory dbxenv debug_file_directory
Miscellaneous
set prompt newprompt PS1=newprompt
PS2=secondprompt
There's similar table in built-in dbx help. Use “help FAQ” and navigate to seciton A.1.