您的位置:首页 > 移动开发

gdb vs. dbx: commands mapping and feature comparison

2011-07-22 10:45 295 查看

GDB and DBX usage reference. very useful when debug program on Linux and AIX

Gdb vs. dbx feature comparison

gdbdbx
Invocation

gdb program

gdb program core

gdb program pid
dbx progam

dbx program core

dbx program pid
gdb -c core

gdb -p pid

Note: need to specify program explicitly
dbx - core

dbx - pid

(program is foundautomatically)

Note: dbx cannot debugcore files and live processes without access to program file,i.e. a.out
gdb -s file

(read symbols from file)
-
gdb -x filedbx ... < file

dbx -s file ...
-tty device

(Runusing device for your program’s standard input and output)
dbxenvrun_io pty

dbxenv run_pty device
-write

(open executable and core file for writing)
-
Exiting

quit

Ctrl-d
exit
Executing shell commands
shell commandksh command

/bin/sh command

Note: you can use any ksh command,including function definition. See “help ksh differences”for limitations.
Logging
set logging

show logging
dbxenv session_log_file_name file

dbxenv session_log_file_name
-dbxenv output_log_file_name file

dbxenv output_log_file_name

(logs only commands, not theiroutput)
set logging redirect [on|off]-

Note: equivalent to off
set logging overwrite [on|off]-

Note: equivalent to on
Commands (general)
Abbreviation - automatic (can use 's' instead of 'step')Need to use ksh 'alias' command to define aliases
Auto-completion with TabNo auto-completion
Command repeat with RetCommand repeat with '!' and UpArrow Ret
Built-in help
help [command]help [command]
apropos keywordhelp -k keyword
Debugging information support
stabs (GNU), dwarf2, -g -Ostabs (SUN), dwarf2, -g -O
Macro support (-g3)Macro support (-g3); Sun Studio compilers don't generate debuginfo for macros, though.
(status unknown).ldynsym support (symbols in stripped loadobject)
Starting a program
run [arguments][ < input_file] [ >output_filerun [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 argsrunargs args
show argsdebug
path dirPATH=dir:$PATH
show pathsecho $PATH
set environment varname [=value ]varname=value
unset environment varnameunset varname
cd directorycd directory
pwdpwd
-any other ksh command (with certainlimitations; see “help ksh differences”)
Attaching
attach pidattach pid

debug program pid

debug - pid
detachdetach
-detach -stop
Killing the child process
killkill (builtin)

/usr/bin/kill
Debugging Multithreaded Applications
info threadsthreads
thread threadnothread threadid
-thread -info [threadid]
-thread -blocks [threadid]thread -blockedby [threadid]
-syncs

(list all synchronization objects).

Note: available on Solaris only.
-sync -info addr

(show information about the 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

lwp [lwpid] -resetfp

(temporarily set frame pointer tospecified value)
-OpenMP support.
Debugging Programs with Multiple Processes

set follow-fork-mode parentdbxenv follow_fork_mode parent
set follow-fork-mode childdbxenv 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

restart checkpoint-id

delete checkpoint checkpoint-id
-

Note: dbx has different mechanism for that; see “helpsave/restore/replace” commands for more information.
Breakpoints
break functionstop in function
break +offset

break -offset
stop at $[$lineno+offset]

stop at $[$lineno – offset]

Note: you can define helper function in .dbxrc thatwill save you from typing all that stuff.
break [filename:]linenumstop at [filename:]linenum
break filename:function-
break \*addressstopi 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
break ... if cond

condition bnum expression
stop ... -if cond
condition bnum

(removes condition)
-
tbreak argsstop ... -temp
-stop inmethod func

stop inmember func

stop infunction func

stop inclass classname [ -recurse | -norecurse ]

inobject object_address [ -recurse | -norecurse ]
step; cont

next; cont
stop step

stop next
catch signal [signame ]stop sig signal [code]
-stop fault <fault>
catch throw [ exceptname]

Note: not very useful since stop after exception is thrown;doesn't work in code called from gdb
intercept [-all] [-x] [-set] [typename]

stop throw [-unhandled] [-unexpected] [typename]
catch catch [exceptname]-

Note: use “whocatches” command
catch stopstop stop
-stop attachstop detach
-stop sync
-stop syncrtld
-stop lastrites (Solaris only)
catch load [ lib-path ]

catch unload [ lib-path ]

Note: unavailable on Linux and Solaris
stop dlopen [ lib-path ]

stop dlclose [ lib-path ]
-stop exit [ exitcode ]
catch fork

catch vfork

catch exec

Note: no other system calls are supported
stop sysin [sysin code|name]

stop sysout [sysin code|name]
finish

Note: can't specify function to catch return from
stop returns [func]

Note: has bug(s), still unresolved.
-stop lwp_exit (Solaris only)
catch exit

catch start

Note: not implemented on Linux and Solaris
stop proc_gone

stop prog_new
tcatch ...stop ... -temp
-stop timer seconds
watch variable

Note: need to re-enable manually
stop change variable
watch expr

Note: need to re-enable manually
stop if expr

stop cond expr
mem addr-expr addr-expr modestop access mode addr-expr [ , byte-size-expr
rwatch <expr>

awatch <expr>

Note: need to re-enable manually, doen't work on Solaris andLinux.
-
catch thread_start

catch thread_exit
stop thr_exit [-thread tid]

stop thr_create [ tid ]
catch thread_join-
-stop ... -resumeone

(when evaluating stop condition, resume only one thread).
-stop ... -in func
ignore bnum countstop ... -count count

handler -count count bnum
break linespec thread threadnostop ... -thread tid
-stop ... -lwp lwpid
hbreak args

thbreak args
-
rbreak regex-

Note: need to use funcs command and manually set breakpointswith “stop in”
info breakpoints [n]

info watchpoints [n]
status [n]
clear

clear linenum

clear filename:linenum
clear

clear 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 -loadlib” and set breakpoints after that or run yourprogram once without any breakpoints so that dbx become aware ofall 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 ]

... command-list ...

end
when ... { cmd; }

wheni ... { cmd; }
-trace next

trace at lineno

trace in func

trace modify addr-expr [ ,byte-size-expr ]

trace ...
Continuing and Stepping
continue [ignore-count ]

fg [ignore-count ]
cont
step [count]step [count] [tid | lwpid]
next [count]next [count] [tid | lwpid]
set step-mode on

stepi [count]
stepi [count] [tid | lwpid]
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 currentor specified location).
-
advance locationcont at line
Signals
info signalsinfo handlecatch, ignore
handle signal stopcatch signal
handle signal nostopignore signal
handle signal printwhen sig signal { print $signal; print $sigstr; }

trace sig signal
handle signal noprint-

Note: no information is printed about ignored signals
handle signal pass

handle signal noignore
ignore signal
handle signal nopass

handle signal ignore
-

Note: use cont with no -sig to cancel current signal afterstopping because of it
Examining the Stack
backtrace [n]

bt [n]
where [n]
backtrace [-n]

bt [-n]
-
backtrace full [n]-
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

set backtrace limit 0

(default is unlimited)
dbxenv stack_max_size n

Note: default is 100; no “unlimited” option
show backtrace limitdbxenv 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]

down [n]
up [n]

down [n]
up-silently [n]

down-silently [n]
> /dev/null up [n]

> /dev/null down [n]
framewhere 1
info frame-
info localsdump
info catchwhocatches type
Examining Source Files
list linenumlist -w linenum
list functionlist function
-list -a function

(lists entire function)
listlist
list -list -10
set listsize count

show listsize
dbxenv output_list_size count

dbxenv output_list_size
list first,lastlist first,last
list ,lastlist last, - [n]
list first,list first,+[n]
list +list [+N]
list -list - [N]
list \*address-
-file [filename]

(view or set current file)
edit

edit number

edit function

edit filename:number

edit filename:function

edit \*address
$EDITOR filename

Note: need to find source file manually with 'whereis [-a]'command.
forward-search regexp

search regexp
search [string]
reverse-search regexpbsearch [string]
Specifying Source Directories
directory dirname ...

dir dirname ...

directory
use [dirname]

Note: “use” is deprecated and replaced withpathmap.
set substitute-path from topathmap 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]

(intermix source lines and assembly code)
Examining Data
print /f exprprint -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 ownrendition of anexpressions value through a function call, see “helpprettyprint”).
x/nfu addrx addr [/nf]

examine addr [/nf]

Note: unit size is governed by format, 'f'
display[/fmt] exprdisplay [-f fmt] expr
undisplay dnums ...

delete display dnums ...
undisplay dnums ...
disable display dnums ...

enable display dnums ...
-
displaydisplay
-watch

(same as display, but expression is re-parsed at each stoppingpoint)
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)
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/offprint -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

Example: set $foo = \*object_ptr

Note: these variables are typed.
Environment variables

Example: foo=$[\*object_ptr]

Note: type of expression is not recorded in the variable.
show convenienceset
init-if-undefined $variable = expression-
info registersregs
info all-registersregs -f | -F
info registers regname ...print $regname
info float

(floating point registers only)
-
info vector-
info udot-
info auxv-
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 addrwhereis -a addr

Note: with 'check -memuse', showsallocation stack for heap-allocated memory region.
whatis argwhatis [-e] arg
ptype argwhatis [-e] arg
info types [regexp]whatis -t [typename]
info scope location-
info sourcemodule -v

file

Note: dwarf info is not displayed correctly for object files.
info sourcesmodules -v

files
info functions regexpfuncs regexp
info variables

(All global and static variable names, or those matching REGEXP)
-
Altering execution
set var=valueassign var=value
assign $reg=valueassign $reg=value
jump linespeccont at linespec
jump \*addressassign $pc=address; cont
signal signalcont -sig signal
returnpop
return expression-
print expr

call expr

Note: abnormal termination affects debuggee
print expr

call expr

Note: abnormal termination doesn't affect debuggee; 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 directorydbxenv debug_file_directory directory
show debug-file-directorydbxenv debug_file_directory
Miscellaneous
set prompt newpromptPS1=newprompt

PS2=secondprompt
There's similar table in built-in dbxhelp. Use “help FAQ” and navigate to seciton A.1.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: