Controlling Program Execution |
4 |
![]() |
This chapter is organized into the following sections:
Basic Concepts
The commands used for running, stepping, and continuing (run, rerun, next, step, and cont) are called process control commands.
Running a Program in dbx
When you first load a program into dbx, dbx visits the program's "main" block (main for C, C++, and Fortran 90, MAIN for FORTRAN 77 and program for Pascal). dbx waits for you to issue further commands; you can visit code or use event management commands.
(dbx) run |
To run a program with command line arguments, type:
(dbx) run -o <my_input_file |
(dbx) run [arguments][input_file | > output_file] |
Output from the run command overwrites an existing file even if you have set noclobber for the shell in which you are running dbx.
Attaching dbx to a Running Process
You may need to debug a program that is already running. For example, you may want to debug a running server and you do not want to stop or kill it; or a program may be looping indefinitely and you would like to examine it under the control of dbx without killing it. You can attach dbx to a running program by using the program's pid number as an argument to the dbx start-up command.
% dbx program_name process_ID
To detach a process from running under the control of dbx, use the dbx detach command:
(dbx) detach |
Executing a Program
dbx supports two basic single-step commands: next and step, plus a variant of step, called step up. Both next and step let the program execute one source line before stopping again.
(dbx) step n |
pop pops the top frame off the stack and adjusts the frame pointer and the stack pointer accordingly. The pop command also changes the program counter to the beginning of the source line at the call site.
Calling a Function
When a program is stopped, you can call a function using the dbx call command, which accepts values for the parameters that must be passed to the called function.
(dbx) call change_glyph(1,3) |
(dbx) call type_vehicle() |
If the source file in which the function is defined was compiled with the -g flag, or if the prototype declaration is visible at the current scope, dbx checks the number and type of arguments and issues an error message if there is a mismatch. Otherwise, dbx does not check the number of parameters.
Continuing a Program
To continue a program, just use the cont command:
(dbx) cont |
The cont command has a variant, cont at line_number, which allows you to specify a line other than the current program location line at which to resume program execution. This allows you to skip over one or more lines of code that you know are causing problems, without having to recompile.
(dbx) cont at 124 |
The line number is evaluated relative to the file in which the program is stopped; the line number given must be within the scope of the function.
(dbx) assign speed = 180; cont at 124; |
(dbx) when at 123 { assign speed = 180; cont at 124;} |
Using Ctrl+C to Stop a Process
You can stop a process running in dbx using Ctrl+C (^C). When you stop a process using ^C, dbx ignores the ^C, but the child process sees it as a SIGINT and stops. You can then inspect the process as if it had been stopped by a breakpoint.
Command Reference
run
Use the run command by itself to execute the program with the current arguments:
run |
To begin executing the program with new arguments:
run args |
rerun
To re-execute the program with no arguments:
rerun |
next
The next command with no arguments steps one line stepping over calls:
next |
To step n lines skipping over calls:
next n |
To deliver the given signal while executing the next command:
next ... -sig sig |
The dbxenv variable step_events controls whether breakpoints are enabled during a step.
next tid |
next lwpid |
This will not implicitly resume all LWPs when skipping a function. When an explicit tid or lwpid is given, the deadlock avoidance measure of the generic next is defeated.
cont
Use the cont command to continue execution. In a multithreaded process, all threads are resumed.
cont |
To continue execution at line line. id is optional.
cont line id |
cont ... -sig signo |
To continue execution with the signal signo:
To continue execution from a specific thread or LWP:
cont ... id |
To continue execution and follow a forked process:
cont ... -follow parent|child |
step
The step command with no arguments steps one line stepping into calls:
step |
To step n lines stepping into calls:
step n |
To step n lines stepping into calls and out of the current function:
step up n |
To deliver the given signal while executing the step command:
step ... -sig sig |
The dbxenv variable step_events controls whether breakpoints are enabled during a step.
step ... tid |
step ... lwpid |
This will not implicitly resume all LWPs when skipping a function. When an explicit tid or lwpid is given, the deadlock avoidance measure of the generic step is defeated.
debug
The debug command prints the name and arguments of the program being debugged.
debug |
To begin debugging a program with no process or core:
debug program |
To begin debugging a program with corefile core:
debug -c core program -or- debug program core |
To begin debugging a program with process ID pid:
debug -p pid program -or- debug program pid |
To force the loading of a corefile; even if it doesn't match:
debug -f ... |
debug -r |
To start debugging a program even if the program name begins with a dash:
debug [options] -- prog |
detach
The detach command detaches dbx from the target, and cancels any pending signals:
detach |
To detach while forwarding the given signal:
detach -sig sig |