Debugging a Program With dbx

Using Predefined Variables

Certain read-only ksh predefined variables are provided. The following variables are always valid:

Variable 

Definition 

$pc

Current program counter address (hexadecimal) 

$ins

Disassembly of the current instruction 

$lineno

Current line number in decimal 

$line

Contents of the current line  

$func

Name of the current function 

$vfunc

Name of the current "visiting" function 

$class

Name of the class to which $func belongs

$vclass

Name of the class to which $vfunc belongs

$file

Name of the current file 

$vfile

Name of the current file being visited 

$loadobj

Name of the current loadable object 

$vloadobj

Name of the current loadable object being visited 

$scope

Scope of the current PC in back-quote notation 

$vscope

Scope of the visited PC in back-quote notation 

$funcaddr

Address of $func in hex

$caller

Name of the function calling $func

$dllist

After dlopen or dlclose event, contains the list of load objects just dlopened or dlclosed. The first word of dllist is actually a "+" or a "-" depending on whether a dlopen or a dlclose has occurred.

$newhandlerid

ID of the most recently created handler 

$proc

Process id of the current process being debugged 

$lwp

Lwp id of the current LWP  

$thread

Thread id of the current thread  

$prog

Full pathname of the program being debugged 

$oprog

Old, or original value of $prog. This is very handy for getting back to what you were debugging following an exec().

$exitcode

Exit status from the last run of the program. The value is an empty string if the process hasn't actually exited. 

As an example, consider that whereami can be roughly implemented as:


function whereami {
  echo Stopped in $func at line $lineno in file $(basename
$file)
  echo "$lineno\t$line"
}

Event-Specific Variables

The following variables are only valid within the body of a when.

$handlerid

During the execution of the body, $handlerid is the id of the when command to which the body belongs. These commands are equivalent:


when X -temp { do_stuff; }
when X  { do_stuff; delete $handlerid; }

$booting

Is set to true if the event occurs during the boot process. Whenever a new program is debugged, it is first run without the user's knowledge so that the list and location of shared libraries can be ascertained. The process is then killed. This sequence is termed booting.

While booting is occurring, all events are still available. Use this variable to distinguish the sync and the syncrtld events occurring during a debug and the ones occurring during a normal run.

Variables Valid for the Given Event

For Event sig

$sig

Signal number that caused the event 

$sigstr

Name of $sig 

$sigcode

Subcode of $sig if applicable 

$sigcodestr

Name of $sigcode 

$sigsender

Process id of sender of the signal, if appropriate 

For Event exit

$exitcode

Value of the argument passed to _exit(2) or exit(3) or the return value of main 

For Events dlopen and dlclose

$dlobj

Pathname of the load object dlopened or dlclosed 

For Events sysin and sysout

$syscode

System call number 

$sysname

System call name 

For Event proc_gone

$reason

One of signal, exit, kill, or detach