Setting Breakpoints and Traces |
7 |
![]() |
The chapter is organized into the following sections:
Basic Concepts
The stop, when, and trace commands are called event management commands. Event management refers to the general capability of dbx to perform certain actions when certain events take place in the program being debugged.
Setting Breakpoints
There are three types of breakpoint action commands:
(dbx) stop at filename: n |
(dbx) stop at main.cc:3 |
If the line specified in a stop or when command is not an executable line of source code, dbx sets the breakpoint at the next executable line.
Setting a when Breakpoint at a Line
A when breakpoint command accepts other dbx commands like list, allowing you to write your own version of trace.
(dbx) when at 123 { list $lineno;}
Setting a Breakpoint in a Dynamically Linked Library
dbx provides full debugging support for code that makes use of the programmatic interface to the run-time linker; code that calls dlopen(), dlclose() and their associated functions. The run-time linker binds and unbinds shared libraries during program execution. Debugging support for dlopen()/dlclose() allows you to step into a function or set a breakpoint in functions in a dynamically shared library just as you can in a library linked when the program is started.
In the Blocks demo program, a member function draw(), is defined in each of five different classes: hand, brick, ball, wedge, table.
To set a when breakpoint, use when inclass.
In the Blocks demo program, to set a breakpoint in all member functions of the class draw:
(dbx) stop inmember draw |
Breakpoints are inserted in only the class member functions defined in the class. It does not include those that it may inherit from base classes.
Setting Multiple Breakpoints in Nonmember Functions
To set multiple breakpoints in nonmember functions with overloaded names (same name, different type or number of arguments), use the stop in function command.
(dbx) when infunction sort {cmd;} |
Tracing Code
Tracing displays information about the line of code about to be executed or a function about to be called. Setting trace Commands
Set trace commands from the command line. The following table shows the command syntax for the types of traces that you can set. The information a trace provides depends on the type of event associated with it.
Controlling the Speed of a Trace
In many programs, code execution is too fast to view the code. The dbxenv trace_speed allows you to control the delay after each trace is printed. The default delay is 0.5 seconds.
dbxenv trace_speed number |
Listing and Clearing Event Handlers
Often, you set more than one breakpoint or trace handler during a debugging session. dbx supports commands for listing and clearing them. Listing Breakpoints and Traces
To display a list of all active breakpoints, use the status command to print ID numbers in parenthesis, which can then be used by other commands. Deleting Specific Breakpoints Using Handler ID Numbers
When you list breakpoints using the status command, dbx prints the ID number assigned to each breakpoint when it was created. Using the delete command, you can remove breakpoints by ID number, or use the keyword all to remove all breakpoints currently set anywhere in the program.
(dbx) delete 3 5 |
To delete all breakpoints set in the program currently loaded in dbx:
(dbx) delete all |
Watchpoints
Watchpointing is the capability of dbx to note when the value of a variable or expression has changed. Stopping Execution When Modified
To stop program execution when the contents of an address gets written to:
(dbx) stop modify &variable |
Keep these points in mind when using stop modify:
(dbx) stop change variable |
Keep these points in mind when using stop change:
user_routine calls library_routine, which calls user_routine2, which changes variable |
(dbx) stop cond condition |
The Faster modify Event
A faster way of setting watchpoints is to use the modify command. Instead of automatically single-stepping the program, it uses a page protection scheme which is much faster. The speed depends on how many times the page on which the variable you are watching is modified, as well as the overall system call rate of the program being debugged.
Setting Breakpoint Filters
In dbx, most of the event management commands also support an optional event filter modifier statement. The simplest filter instructs dbx to test for a condition after the program arrives at a breakpoint or trace handler, or after a watch condition occurs.
These two filters are not the same:
Note - With location-based breakpoints like in or at, the scope is that of the breakpoint location. Otherwise, the scope of the condition is the scope at the time of entry, not at the time of the event. You may have to use syntax to specify the scope precisely.
stop in foo -if a>5 stop cond a>5 |
The former will breakpoint at foo and test the condition. The latter automatically single-steps and tests for the condition.
(dbx) stop modify &speed -if speed==fast_enough |
This command instructs dbx to monitor the variable, speed; if the variable speed is written to (the "watch" part), then the -if filter goes into effect. dbx checks to see if the new value of speed is equal to fast_enough. If it is not, the program continues on, "ignoring" the stop.
stop in function [-if condition] |
Efficiency Considerations
Various events have varying degrees of overhead in respect to the execution time of the program being debugged. Some events, like the simplest breakpoints have practically no overhead. Events based on a single breakpoint, like have minimal overhead.
The slowest events are those that utilize automatic single stepping. This might be explicit and obvious as in the trace step command, which single steps through every source line. Other events, like the watchpoints stop change expression or trace cond variable not only single step automatically but also have to evaluate an expression or a variable at each step.
Note - In the case of step and next, by default all breakpoints are taken out before the process is resumed and reinserted once the step completes. If you are using many breakpoints or multiple breakpoints on prolific classes the speed of step and next slows down considerably. Use the dbxenv step_events to control whether breakpoints are taken out and reinserted after each step or next.
trace next -in mumble stop change clobbered_variable -in lookup |
Do not use trace -in main because the trace is effective in the functions called by main as well. Do use in the cases where you suspect that the lookup() function is clobbering your variable.