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:
- 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.
- 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
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_STATS3.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_dataAll 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
3.8 Printing Variables and Expressions
Please read debug(CP) or use the debug
help exprinternal command for specific information about debug expressions.
3.9 Accessing source files
3.10 Command Aliases
3.11 Machine Level Commands
3.12 Miscellaneous Commands
3.13 Common tasks
These are perhaps less commonly used but usually still available in some form: