Sun Studio 12 Update 1: Debugging a Program With dbx

Setting Breakpoints

A breakpoint is a location in your program where you want the program to stop executing temporarily and give control to dbx. Set breakpoints in areas of your program where you suspect bugs. If your program crashes, determine where the crash occurs and set a breakpoint just before this part of your code.

When your program stops at a breakpoint, you can then examine the state of program and the values of variables. dbx allows you to set many types of breakpoints (see Using Ctrl+C to Stop a Process).

The simplest type of breakpoint is a stop breakpoint. You can set a stop breakpoint to stop in a function or procedure. For example, to stop when the main function is called:


(dbx) stop in main
(2) stop in main

For more information on the stop in command, see Setting a stop Breakpoint in a Function and stop Command.

Or you can set a stop breakpoint to stop at a particular line of source code. For example, to stop at line 13 in the source file t.c:


(dbx) stop at t.c:13
(3) stop at “t.c”:13

For more information on the stop at command, see Setting a stop Breakpoint at a Line of Source Code and stop Command.

You can determine the line at which you wish to stop by using the file command to set the current file and the list command to list the function in which you wish to stop. Then use the stop at command to set the breakpoint on the source line:


(dbx) file t.c
(dbx) list main
10    main(int argc, char *argv[])
11    {
12        char *msg = "hello world\n";
13        printit(msg);
14    }
(dbx) stop at 13
(4) stop at “t.c”:13

To continue execution of your program after it has stopped at a breakpoint, use the cont command (see Continuing Execution of a Program and cont Command).

To get a list of all current breakpoints use the status command:


(dbx) status
(2) stop in main
(3) stop at "t.c":13

Now if you run your program, it stops at the first breakpoint:


(dbx) run
...
stopped in main at line 12 in file "t.c"
12        char *msg = "hello world\n";