TOC PREV NEXT

Chapter 3
A Guide to debug for dbx Users


This section details feature differences between dbx and debug, and offer help for those users who are used to a dbx-style debugger. For simplicity of presentation, we concentrate on the command line and do not discuss the differences between the graphical front-ends for the debuggers. Extra features offered by debug are detailed in the debug(CP) manual page and the debug help command.

3.1 Starting debug

Two common methods of starting debug:

  1. From the command line you can specify:
    
    	debug arglist
    
The arglist must contain an absolute or relative pathname to a binary file and the appropriate arguments for that binary. Then, the debug internal command

	run [-f]
starts execution of the binary.
  1. If you start debug with no arglist, then enter these commands at the debug prompt to start execution:
    
    	debug> create pathname_to_binary [arg...]
    	debug> run [-f]
    

The important thing to remember when specifying the pathname to the binary is that the PATH variable is not used to search for it; so, you must use a full pathname for any binary not in the current working directory (or below).

3.2 Command Line Options

dbx option debug option Description Notes
corefile -c corefile File name of the core file to be debugged
-r N/A Executes the object file and exits the debugger only if no error occurs
-x N/A Ignore cross-reference file when initializing dbx Not currently available in debug.
-F N/A dbx assumes that file scoped structure, union, enum definitions with the same name are identical Unnecessary
-I dir -s path Search path(s) for source files Under debug this sets the global path variable, %global_path
-c file N/A Execute the dbx commands in the file before reading from standard input debug offers the script internal command to do this from the debug prompt
-C++ N/A Assume C++ mode Set %lang to ``C++'' at the debug prompt to override the default value in %db_lang.
-C N/A Use C debugging only Set %lang to ``C'' at the debug prompt to override the default value in %db_lang.

3.3 Setup
dbx debug Description
$HOME/.dbxtrarc $HOME/.debugrc File containing commands that are executed at debugger startup

3.4 Configuration example

Here is a useful set of entries to put in $HOME/.debugrc to tailor debug commands and initial behaviour to be similar to dbx.

   #---- UW7 debug ~/.debugrc file for migrating from dbx style usage ----
   #
   # default cmdline editing
   set %mode "emacs"
   # where/stack trace
   alias w stack
   # Continue
   alias c run -f
   # swap +/- up/down for gdebug - depends on %frame_numbers
   alias up set %frame %frame +1; list -c 1
   alias down set %frame %frame -1 ; list -c 1
   # status
   alias st events
   #remove existing alias
   alias unalias alias -r
   # breakpoints
   #alias b stop
   alias d delete
   alias dis disable
   alias di disable
   alias en enable
   # rerun - load and run
   alias load create
   unalias rr
   alias rr create -f none $* ; run -u main
   # general useful
   alias a alias
   unalias h; alias h history
   alias H help $* |$PAGER
   alias P $* |$PAGER
   alias mem dump -b
   alias echo {print -f "%s\n" $*; }
   #disassemble with as much info as poss
   set %dis_mode="source"
   alias dasm dis
   # don't follow any forked processes - does this actually work ??
   set %follow "none"
   set %thread_change="ignore"
   #set %thread_change="announce"
   # shutup signals we don't normally care about
   signal -d -i sigcld sigalrm
   # Where to look for src
   set %global_path="/tmp/vtcl"
   alias path {if ($# > 0) set  %global_path $* ""; print %global_path; }
   #
   # User variables
   set $MALLOC_CHECKS=6
   set $MALLOC_STATS=6
   # into env
   alias EMC export $MALLOC_CHECKS ; stop malloc.c@checkmsg
   alias EMS export $MALLOC_STATS

3.5 General Tips

The following are general usage differences between dbx and debug:

  • For help on any command or usage of debug, use the help command to display a list of commands and internal help topics (such as for help on specific debug internal variables). Some examples:
    
    	help
    	help expr
    	help release
    	help %db_lang
    	help C++
    
  • debug internal variables are preceded with a % character. So %lang is used to identify the debug internal variable for setting the current language.
  • debug command line editing can be improved by switching it to vi or emacs mode by setting the %mode variable (for example: set %mode=vi).
  • The debug command line can have redirection symbols and pipes used with any command. dbx only offers redirection with certain commands such as run and dump.
  • You can specify breakpoints on static fns (or reference static data) but you must explicitly specify the filename the fn/variable resides in in the expression or already have the debugger stopped in the file in question.
    
    	stop malloc.c@checkmsg
    	stop file.c@static_fn
    	print file.c@static_data
    
  • All signals are trapped by default (suppress sigcld, sigalrm):
    
    	signal -d -i sigcld sigalrm
    
and forked processes are followed by default.

	{debug|create} -f none
	run -f
	set %follow "none"
	release
  • When a process is not loaded or a process is completed, many commands that are irrelevant to a process are disabled along with those that are not. For example: listing a file, and listing breakpoints.
  • debug runs by default in its own X window; suppressable with -ic or by unsetting $DISPLAY; not specifiable from defaults file so can tweak it permanently. You can use a shell alias; for example:
    
    alias dbg='debug -ic'
    
  • In the command debug cmdline, the first token is a filename that is not searched for in PATH; i.e., it must be specified as an absolute (or relative) pathname if the binary is not in the current working directory. This also applies to the internal create command.
  • Print "v" -> outputs "v" (quoted - instead of v)
  • ^D doesn't exit the debugger; use quit or exit.
  • debug uses two expression parsers: one for the command line constructs and another for C/C++ expressions. The combination of the two can lead to unexpected effects and demand non-obvious syntax (e.g., empty string inclusion).
  • Aliases are set and removed in unique ways (that is, more like macro replacement than other assignments). To set:
    
    alias name list_of_replacement_tokens
     
    
To remove:

	alias -r
  • Substituting args are not expanded inside quoted strings or specifiable with brackets or parentheses (in disambiguating ${} forms):
    
    	$[0-9]
    	$*
    	$#
    
  • In debug, use aliases and blocks (enclosed in brackets: {...}) to define user functions.
  • By default debug will attempt to also debug forked child processes. The %follow system variable controls this behaviour and should be set to none (from the default all) to disable this.
  • The threads of control of a process that debug knows about can be displayed with the ps command and the current switched by setting the %proc system variable or the -p switch on many commands.
Notification of thread state change (create, exit, suspend, continue, etc.) can be controlled with the %thread_change variable. The default value is stop, indicating to print a message and stop the thread if possible. To disable both notification and stopping set it to ignore.

3.6 Debugger Variables

The debug-specific variables are substantially different from those with special meaning for dbx. There are four types of debug variables, each with a distinct purpose:

  • ``code'' variables; variables defined by the code being debugged (unadorned name): var
  • ``system'' variables; variables that affect or modify some aspect of debug behaviour: %var
  • ``user'' variables; generic debug internal variables defined by the user to store temporary values: $var
  • environment variables are handled as a subset of user variables, and are defined by exporting them: export $var

3.7 Execution and Tracing Commands
dbx command debug command Description Notes
run [args] [< filename][>[> filename]] run [-p proc_list][-bfr][-u location] Run the current program being debugged Debug treats the run command also as continue, so by using run when the execution of a program has been halted will continue from that point. This is different from dbx's run as it restarts program. Note that the redirection symbols in debug can be used with any command. Debug also offers pipes.
rerun [args] [< filename][>[> filename]] create [-f none | procs | all] [-dr][-l start_loc] [command_line] Rerun the program and append the arguments to the previous arguments passed to the program Debug's create command (with no arguments) offers a similar functionality to dbx's rerun command. Note that debug does not append given arguments with the create command, but treats it as a request to debug a new program.
setenv name value set [-p proc_list] debug_or_user_var [=] expr [,expr] export $username Set the value of an environment variable in the environment of the debugged program. In debug, the set command must be used with a user variable to set the value and then exported to the environment of the debugged program with the export command. Note that this has to be done before the execution of the debugged program.
unsetenv name N/A Unset the value of the variable.
trace [inst][in routine][if condition] trace [inst] line-number|address [if condition] trace routine [in routine2][if condition] (various) Display source lines (or machine instructions) when executed, display the arguments and results of routines There are a number of ways of emulating the trace functionality. Aliases can be created on the variations of: alias trace = onstop { step }debug variables %func, %frame, etc. can be used to determine the current execution location.
trace [inst][change] variable [in routine][if condition] trace [inst] change address [in routine][if condition] trace [inst] access variable [in routine][if condition] trace [inst] access address [in routine][if condition] (various) Display when changes (or accesses) are made to variables or memory locations. This functionality can be reasonably matched by debug's stop command used with expressions.
stop in routine [if condition] stop [inst] access variable [if condition] stop [inst] [change] address [if condition] stop [inst] [change] variable [if condition] stop [inst] if condition stop [inst] at line_number|address [if condition] stop [inst] access address [if condition] stop [-p proc_list] [[-q] [-c count] stop_expr] Stop execution when execution reaches a given location, or when a variable or memory location is changed or accessed. All the various forms of the dbx stop command can be matched by the debug stop command used with expressions.
when [inst] at line_number|address [if condition] {command; [command; ... ]} when in routine [if condition] {command; [command; ... ]} when [inst] condition {command; [command; ... ]} when [inst] change variable [if condition] {command; [command; ... ]} when [inst] change address [if condition] {command; [command; ... ]} when [inst] access variable [if condition] {command; [command; ... ]} when [inst] access address [if condition] {command; [command; ... ]} stop [-p proc_list] [[-q] [-c count] stop_expr [command]]
Execute a series of commands when execution reaches a given location, when a condition is true, or when a variable or memory location is changed or accessed.

status [> filename] events [-p proc_list] [event_num ...] List the user specified events for the current program (break points, etc..) and their current status. The debug events command also provides information about system calls, signals and exceptions)
delete event_num ... delete event_num ... The event corresponding to event_num is removed. Debug provides another variation of this command for deletion of event types.
disable event_num ... disable event_num ... Disable the specified events. Debug provides another variation of this command to disable event types.
enable event_num ... enable event_num ... Enable previously disabled events. Debug provides another variation of this command to enable event types.
catch number|signal_name signal -d [signal ....] signal [-p proc_list][[-q] signal ... [cmd]] Trap a specified signal. Debug offers greater control over signals. Refer to the relevant documentation.
ignore number|signal_name signal -d -i [signal ....] signal [-p proc_list] [[-iq] signal ... [cmd]] Stop trapping a specified signal. Debug offers greater control over signals. Refer to the relevant documentation. Note that the -i option can be also used to re-establish the default action for a signal.
cont integer run [-p proc_list][-bfr][-u location] Continue execution from where the program stopped.
cont signal_name kill [-p proc_list][signal] followed by run [-p proc_list][-bfr][-u location] Process continues as though it received the given signal Debug needs to have the run command executed after the kill command is given.
skip [n] (alias) Continue execution from where stopped. If n is specified, that many breakpoints are ignored before the program stops. If n is not given, one breakpoint is skipped. This functionality can be emulated with debug's onstop command, e.g. if ($# == 0) set $skip=1; else set $skip=$1 +0; onstop { if ($skip > 0) { set $skip=$skip - 1; run } else delete %thisevent}; run Note that the "+0" is required when no parameters are passed to skip.
step [n] step [-p proc_list] [-bfq] [-c count] Execute a number of source lines (default is 1) Debug provides more control to the user for stepping.
next [n] step [-p proc_list] [-bfq] -o [-c count] Execute a number of source lines (default is 1). If a line contains a call to a procedure or function the command does not stop at the beginning of that block. Debug provides more control to the user for stepping. Note that there is a standard alias, next, for debug.
return [procedure] run -r Continue until a return to procedure is executed, or until the current procedure returns if none is specified. Debug's run -r continues execution until a the return address of the current function is reached. Note that you cannot specify a procedure name with the -r option.
call procedure(parameters) (various) Execute the object code associated with the named procedure or function. A call to a function or procedure under debug can be done using any command that allows an expression for an argument. For example: print procedure(a, b, c) or set $MYRET=function(a, b).
jump line_number jump [-p proc_list] location Continue until a return to procedure is executed, or until the current procedure returns if none is specified. Debug's jump command can be used with any valid location.
goto line_number run -u location Continue execution and stop before the fist instruction at the specified line number is executed. Debug's run command with the -u option can be used with any valid location.

3.8 Printing Variables and Expressions

Please read debug(CP) or use the debug


help expr

internal command for specific information about debug expressions.
dbx command debug command Description Notes
assign variable=expression set [-p proc_list] [-v] debug_or_user_var [=] expr [,expr...] set [-p proc_list] [-v] language_expression Assign the value of an expression to a variable. Debug's set can be used to evaluate any language expression, typically and assignment.
assign register=expression assign eax=6 print %eax=(void *)6 Assign the value of an expression to a register. The type casting is required; otherwise debug returns a warning which is not otherwise suppressible.
assign memloc=expression assign 0x8049478=5 print *(int *)0x8049478=5 Assign the value of an expression to a memory location. The type casting is required; otherwise debug returns a warning which is not otherwise suppressible.
dump [procedure] [> filename] functions [-s] [-p proc_list] [-o object] [-f filename] [pattern] symbols [-p proc_list] [-o object] [-n filename] [-dfgltuv] [pattern] Print the names and values of variables in a procedure. Debug's functions and symbols commands can provide information to match dbx's dump command and more.
print expression [, expression ...] print [-p proc_list] [-f format] [-v] expr, ... Print the expression. The -f format option to debug's print command allows the user to use a "C" style format output of the expression, e.g. print -f "0x%x\n" main
whatis expression whatis [-p proc_list] expr Print the declaration of the expression. Debug's whatis command provides all known information about the expression.
which identifier N/A Print the full qualification of the given identifier. Unavailable cross reference information required for this command.
up [count] down [count] set %frame = frame_number Move the current frame up and down the stack. Debug's %frame variable contains the current frame number. By setting this variable a user can traverse the stack. These can be aliased with: alias up set %frame = %frame + 1 alias down set %frame = %frame - 1
where identifier stack [-p proc_list] [-f frame] [-c count] [-a address ] [ -s stack ] Print the list of the active procedures and functions. Debug's stack command offers more functionality that dbx's where command.
whereis identifier N/A Print the full qualification of all the symbols whose name matches the given identifier. Unavailable cross reference information required for this command.
dbxref [-i][-o file][options][files] N/A Generate the cross-reference file for dbx's xref, whatis and whereis commands.
xref identifier N/A Print a cross-reference for the given symbol. Unavailable cross reference information required for this command.

3.9 Accessing source files
dbx command debug command Description Notes
/regular expression[/] ?regular expression[?] list [-p proc_list] [-c count] /regexp/ list [-p proc_list] [-c count] ?regexp? Search forward or backward in the current source file for the given pattern. In debug / and ? when %mode is set to vi will search forward and backward in the command line history.
edit [filename] edit procedure_name edit function_name N/A Invoke an editor on filename or the current source file if none is specified. The shell command (!) with the appropriate executable can be used to edit a file.
file [filename] set %list_file=filename Change the current source file name to filename. Debug's current file is also contained in %file
func [procedure/function] N/A Change the current function.
list . list procedure/function list [source_line number [, source_line_number]] list [-p proc_list] [-c count] [thread id@][file_name@][header_file@]func_name list [-p proc_list] [-c count] [thread id@][file_name@][header_file@]line_num list [-p proc_list] [-c count] List the lines in the current source file.
use directory_list set %path="directory_list" set %global_path="directory_list" Set the list of directories to be searched when looking for source files.

3.10 Command Aliases
dbx command debug command Description Notes
alias alias name name alias name "string" alias name (parameters) "string" alias name tokens ... alias [name] Establish a new alias. Debug alias parameters are available as $1, $2, etc... $# is the number of arguments passed and $* represents all the arguments passed.
unalias name alias -r name Remove the alias with the given name.
set name [= expression] set [-p proc_list] [-v] debug_or_user_var [=] expr [,expr... Define the values for debugger variables. Debug specific variables are preceded with a %, e.g. %file. User specific (and environment) variables are preceded with a $, e.g. $DISPLAY.
unset name N/A Delete the debugger variable associated with name.

3.11 Machine Level Commands
dbx command debug command Description Notes
stepi step [-p proc_list] [-bfq] -i [-c count] Single step as in step, but at a single machine instruction. Debug has a default alias for this functionality, si.
nexti step [-p proc_list] [-bfq] -io [-c count] Single step as in next, but at a single machine instruction. Debug has a default alias for this functionality. ni.
regs regs [-p proc_list] Display the contents of the register set.
fpregs regs [-p proc_list] Display the contents of the register set. Debug display's the floating point registers only if they have been used.
address, address/ [mode] address / [count] [mode] dump [-p proc_list] [-c byte_count] [-b] expression Print the contents of memory Debug's dump command allows starting points to be defined by expressions as well as addresses. Debug's dump output is printed in ASCII and hexadecimal.

3.12 Miscellaneous Commands
dbx command debug command Description Notes
cc set %db_lang="C" or set %db_lang="C++" Toggle between C++ and C output modes.
help [command] help [string] help [topic] Obtain a list of help topics or help on a topic.
quit quit Exit the debugger. Debug's quit kills all created processes or releases them if they had been grabbed.
sh [command_line] ! command_line ! command_line !! Pass the command line to the shell for execution. Debug's !! command executes the last shell command.
source filename script [-q] filename Read debugger commands from a file.
kill kill [-p proc_list] Kill the current or specified process. Debug's kill command can also be used to send signals to a process.
detach release [-s] [-p proc_list] Release the current process. Debug's release command allows the process to be released in a stopped state with the -s option.
exec filename (automatic) If the process being debugged does an exec system call, this tells the debugger that a new symbol table should be read in. Debug is capable of debugging several processes and threads at the same time, so this functionality is executed automatically.
version version Print the version information for the debugger.

3.13 Common tasks
Task dbx cmd debug equiv
Breakpoints

setting b, break, bp stop
clearing d, del delete
showing status, st events
temp disable dis disable
reenable en enable
Single stepping

into fns s, step step, s
over fns n, next step -o, n, next
Running run, r run [-f]
rerunning process rerun, rr create [-f none]; run none
Continuing c, cont run [-f]
Viewing

print variables print print, p
dump memory mem, print dump locn
stack trace where stack [-c count]

These are perhaps less commonly used but usually still available in some form:
Task debug equiv
Current Stack frame modify %frame system variable: alias down set %frame = %frame - 1; list -c 1 alias up set %frame = %frame + 1; list -c 1
Setting variables set v[=]value
Source
Specifying where the source files are %global_path - all processes %path - for a single process set -p <proc> %path whatever - after process is running
Changing srcFile to Browse set %list_file filename
Execution
run to return fm current fn run -r
execute from an address jump loc
run upto address run -u loc
rerun current process create [-f none]; run [-f]
viewing/changing argv list rerun and specify a new command line
enabling command line editing set %mode vi set %mode emacs (emacs mode deficient - no handling arrow keys; occasional dropout)
Displaying paged output (help) must pipe through pager: ... | more
Watchpoints not provided, but buildable with onstop command


TOC PREV NEXT