gdb vs. dbx: commands mapping and feature comparison

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

Gdb vs. dbx feature comparison


gdb dbx

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 file dbx ... < 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 command ksh 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 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 debuginfo 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
pwd pwd
- any other ksh command (with certainlimitations; 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 [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 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
restart checkpoint-id
delete checkpoint checkpoint-id
-
Note: dbx has different mechanism for that; see “helpsave/restore/replace” commands for more information.

Breakpoints

break function stop in function
break +offset
break -offset
stop at $[$lineno+offset]
stop at $[$linenooffset]
Note: you can define helper function in .dbxrc thatwill 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
break ... if cond
condition bnum expression
stop ... -if cond
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
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 stop stop 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 mode stop 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 count stop ... -count count
handler -count count bnum
break linespec thread threadno stop ... -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 location cont at line

Signals

info signalsinfo 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 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 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]
down [n]
up [n]
down [n]
up-silently [n]
down-silently [n]
> /dev/null up [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
show listsize
dbxenv output_list_size count
dbxenv output_list_size
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
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 regexp bsearch [string]

Specifying Source Directories

directory dirname ...
dir dirname ...
directory
use [dirname]
Note: “use” is deprecated and replaced withpathmap.
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]
(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 ownrendition of anexpressions value through a function call, see “helpprettyprint”).
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 ...
delete display dnums ...
undisplay dnums ...
disable display dnums ...
enable display dnums ...
-
display display
- 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/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
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 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 -
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', showsallocation 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
info functions regexp funcs regexp
info variables
(All global and static variable names, or those matching 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
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 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 dbxhelp. Use “help FAQ” and navigate to seciton A.1.

你可能感兴趣的:(function,File,command,Solaris,Signal,output)