JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.3: Debugging a Program With dbx     Oracle Solaris Studio 12.3 Information Library
search filter icon
search icon

Document Information

Preface

1.  Getting Started With dbx

2.  Starting dbx

3.  Customizing dbx

4.  Viewing and Navigating To Code

5.  Controlling Program Execution

6.  Setting Breakpoints and Traces

7.  Using the Call Stack

8.  Evaluating and Displaying Data

9.  Using Runtime Checking

10.  Fixing and Continuing

Using Fix and Continue

How Fix and Continue Operates

Modifying Source Using Fix and Continue

Fixing Your Program

To Fix Your File

Continuing After Fixing

Changing an Executed Function

Changing a Function Not Yet Called

Changing a Function Currently Being Executed

Changing a Function Presently on the Stack

Changing Variables After Fixing

Modifying a Header File

Fixing C++ Template Definitions

11.  Debugging Multithreaded Applications

12.  Debugging Child Processes

13.  Debugging OpenMP Programs

14.  Working With Signals

15.  Debugging C++ With dbx

16.  Debugging Fortran Using dbx

17.  Debugging a Java Application With dbx

18.  Debugging at the Machine-Instruction Level

19.  Using dbx With the Korn Shell

20.  Debugging Shared Libraries

A.  Modifying a Program State

B.  Event Management

C.  Macros

D.  Command Reference

Index

Changing Variables After Fixing

Changes made to global variables are not undone by the pop command or thefix command. To reassign correct values to global variables manually, use the assign command. (See assign Command.)

The following example shows how a simple bug can be fixed. The application gets a segmentation violation in line 6 when trying to dereference a NULL pointer.

dbx[1] list 1,$
    1    #include <stdio.h>
    2    
    3    char *from = “ships”;
    4    void copy(char *to)
    5    {
    6        while ((*to++ = *from++) != ’\0’);
    7        *to = ’\0’;
    8    }
    9    
    10    main()
    11    {
    12        char buf[100];
    13    
    14        copy(0);
    15        printf("%s\n", buf);
    16        return 0;
    17    }
(dbx) run
Running: testfix
(process id 4842)
signal SEGV (no mapping at the fault address) in copy at line 6 in file “testfix.cc”
    6        while ((*to++ = *from++) != ’\0’);

Change line 14 to copy to buf instead of 0 and save the file, then do a fix:

    14        copy(buf);      <=== modified line
(dbx) fix
fixing “testfix.cc” .....
pc moved to “testfix.cc”:6
stopped in copy at line 6 in file “testfix.cc”
    6        while ((*to++ = *from++) != ’\0’)

If the program is continued from here, it still gets a segmentation fault because the zero-pointer is still pushed on the stack. Use the pop command to pop one frame of the stack:

(dbx) pop
stopped in main at line 14 in file “testfix.cc”
      14 copy(buf);

If the program is continued from here, it runs, but does not print the correct value because the global variable from has already been incremented by one. The program would print hips and not ships. Use the assign command to restore the global variable and then use the cont command. Now the program prints the correct string:

(dbx) assign from = from-1
(dbx) cont
ships