Sun Logo


Debugging a Program With dbx

Suntrademark Studio 11

819-3683-10



Contents

Figures

Tables

Before You Begin

How This Book Is Organized

Typographic Conventions

Shell Prompts

Supported Platforms

Accessing Sun Studio Software and Man Pages

Accessing Sun Studio Documentation

Accessing Related Solaris Documentation

Resources for Developers

Contacting Sun Technical Support

Sending Your Comments

1. Getting Started With dbx

Compiling Your Code for Debugging

Starting dbx and Loading Your Program

Running Your Program in dbx

Debugging Your Program With dbx

Examining a Core File

Setting Breakpoints

Stepping Through Your Program

Looking at the Call Stack

Examining Variables

Finding Memory Access Problems and Memory Leaks

Quitting dbx

Accessing dbx Online Help

2. Starting dbx

Starting a Debugging Session

Debugging a Core File

Debugging a Core File in the Same Operating Environment

If Your Core File Is Truncated

Debugging a Mismatched Core File

Using the Process ID

The dbx Startup Sequence

Setting Startup Properties

Mapping the Compile-time Directory to the Debug-time Directory

Setting dbx Environment Variables

Creating Your Own dbx Commands

Compiling a Program for Debugging

Debugging Optimized Code

Code Compiled Without the -g Option

Shared Libraries Require the -g Option for Full dbx Support

Completely Stripped Programs

Quitting Debugging

Stopping a Process Execution

Detaching a Process From dbx

Killing a Program Without Terminating the Session

Saving and Restoring a Debugging Run

Using the save Command

Saving a Series of Debugging Runs as Checkpoints

Restoring a Saved Run

Saving and Restoring Using replay

3. Customizing dbx

Using the dbx Initialization File

Creating a .dbxrc File

Initialization File Sample

Setting dbx Environment Variables

The dbx Environment Variables and the Korn Shell

4. Viewing and Navigating To Code

Navigating To Code

Navigating To a File

Navigating To Functions

Printing a Source Listing

Walking the Call Stack to Navigate To Code

Types of Program Locations

Program Scope

Variables That Reflect the Current Scope

Visiting Scope

Qualifying Symbols With Scope Resolution Operators

Backquote Operator

C++ Double Colon Scope Resolution Operator

Block Local Operator

Linker Names

Locating Symbols

Printing a List of Occurrences of a Symbol

Determining Which Symbol dbx Uses

Scope Resolution Search Path

Relaxing the Scope Lookup Rules

Viewing Variables, Members, Types, and Classes

Looking Up Definitions of Variables, Members, and Functions

Looking Up Definitions of Types and Classes

Debugging Information in Object files and Executables

Object File Loading

Listing Debugging Information for Modules

Listing Modules

Finding Source and Object Files

5. Controlling Program Execution

Running a Program

Attaching dbx to a Running Process

Detaching dbx From a Process

Stepping Through a Program

Single Stepping

Continuing Execution of a Program

Calling a Function

Using Ctrl+C to Stop a Process

6. Setting Breakpoints and Traces

Setting Breakpoints

Setting a stop Breakpoint at a Line of Source Code

Setting a stop Breakpoint in a Function

Setting Multiple Breaks in C++ Programs

Setting Data Change Breakpoints

Setting Filters on Breakpoints

Tracing Execution

Setting a Trace

Controlling the Speed of a Trace

Directing Trace Output to a File

Setting a when Breakpoint at a Line

Setting a Breakpoint in a Shared Library

Listing and Clearing Breakpoints

Listing Breakpoints and Traces

Deleting Specific Breakpoints Using Handler ID Numbers

Enabling and Disabling Breakpoints

Efficiency Considerations

7. Using the Call Stack

Finding Your Place on the Stack

Walking the Stack and Returning Home

Moving Up and Down the Stack

Moving Up the Stack

Moving Down the Stack

Moving to a Specific Frame

Popping the Call Stack

Hiding Stack Frames

Displaying and Reading a Stack Trace

8. Evaluating and Displaying Data

Evaluating Variables and Expressions

Verifying Which Variable dbx Uses

Variables Outside the Scope of the Current Function

Printing the Value of a Variable, Expression, or Identifier

Printing C++

Dereferencing Pointers

Monitoring Expressions

Turning Off Display (Undisplaying)

Assigning a Value to a Variable

Evaluating Arrays

Array Slicing

Slices

Strides

9. Using Runtime Checking

Capabilities of Runtime Checking

When to Use Runtime Checking

Runtime Checking Requirements

Limitations

Using Runtime Checking

Turning On Memory Use and Memory Leak Checking

Turning On Memory Access Checking

Turning On All Runtime Checking

Turning Off Runtime Checking

Running Your Program

Using Access Checking

Understanding the Memory Access Error Report

Memory Access Errors

Using Memory Leak Checking

Detecting Memory Leak Errors

Possible Leaks

Checking for Leaks

Understanding the Memory Leak Report

Fixing Memory Leaks

Using Memory Use Checking

Suppressing Errors

Types of Suppression

Suppressing Error Examples

Default Suppressions

Using Suppression to Manage Errors

Using Runtime Checking on a Child Process

Using Runtime Checking on an Attached Process

Using Fix and Continue With Runtime Checking

Runtime Checking Application Programming Interface

Using Runtime Checking in Batch Mode

bcheck Syntax

bcheck Examples

Enabling Batch Mode Directly From dbx

Troubleshooting Tips

Runtime Checking's 8 Megabyte Limit

Runtime Checking Errors

Access Errors

Memory Leak Errors

10. Fixing and Continuing

Using Fix and Continue

How Fix and Continue Operates

Modifying Source Using Fix and Continue

Fixing Your Program

Continuing After Fixing

Changing Variables After Fixing

Modifying a Header File

Fixing C++ Template Definitions

11. Debugging Multithreaded Applications

Understanding Multithreaded Debugging

Thread Information

Viewing the Context of Another Thread

Viewing the Threads List

Resuming Execution

Understanding Thread Creation Activity

Understanding LWP Information

12. Debugging Child Processes

Attaching to Child Processes

Following the exec Function

Following the fork Function

Interacting With Events

13. Debugging OpenMP Programs

How Compilers Transform OpenMP Code

dbx Functionality Available for OpenMP Code

Using Stack Traces With OpenMP Code

Using the dump Command on OpenMP Code

Execution Sequence of OpenMP Code

14. Working With Signals

Understanding Signal Events

Catching Signals

Changing the Default Signal Lists

Trapping the FPE Signal (Solaris Platforms Only)

Sending a Signal to a Program

Automatically Handling Signals

15. Debugging C++ With dbx

Using dbx With C++

Exception Handling in dbx

Commands for Handling Exceptions

Examples of Exception Handling

Debugging With C++ Templates

Template Example

Commands for C++ Templates

16. Debugging Fortran Using dbx

Debugging Fortran

Current Procedure and File

Uppercase Letters

Sample dbx Session

Debugging Segmentation Faults

Using dbx to Locate Problems

Locating Exceptions

Tracing Calls

Working With Arrays

Fortran 95 Allocatable Arrays

Showing Intrinsic Functions

Showing Complex Expressions

Showing Interval Expressions

Showing Logical Operators

Viewing Fortran 95 Derived Types

Pointer to Fortran 95 Derived Type

17. Debugging a Java Application With dbx

Using dbx With Java Code

Capabilities of dbx With Java Code

Limitations of dbx With Java Code

Environment Variables for Java Debugging

Starting to Debug a Java Application

Debugging a Class File

Debugging a JAR File

Debugging a Java Application That Has a Wrapper

Attaching dbx to a Running Java Application

Debugging a C Application or C++ Application That Embeds a Java Application

Passing Arguments to the JVM Software

Specifying the Location of Your Java Source Files

Specifying the Location of Your C Source Files or C++ Source Files

Specifying a Path for Class Files That Use Custom Class Loaders

Setting Breakpoints on Code That Has Not Yet Been Loaded by the JVM Software

Customizing Startup of the JVM Software

Specifying a Path Name for the JVM Software

Passing Run Arguments to the JVM Software

Specifying a Custom Wrapper for Your Java Application

Specifying 64-bit JVM Software

dbx Modes for Debugging Java Code

Switching from Java or JNI Mode to Native Mode

Switching Modes When You Interrupt Execution

Using dbx Commands in Java Mode

The Java Expression Evaluation in dbx Commands

Static and Dynamic Information Used by dbx Commands

Commands With Identical Syntax and Functionality in Java Mode and Native Mode

Commands With Different Syntax in Java Mode

Commands Valid Only in Java Mode

18. Debugging at the Machine-Instruction Level

Examining the Contents of Memory

Using the examine or x Command

Using the dis Command

Using the listi Command

Stepping and Tracing at Machine-Instruction Level

Single Stepping at the Machine-Instruction Level

Tracing at the Machine-Instruction Level

Setting Breakpoints at the Machine-Instruction Level

Setting a Breakpoint at an Address

Using the adb Command

Using the regs Command

Platform-Specific Registers

x86 Register Information

AMD64 Register Information

19. Using dbx With the Korn Shell

ksh-88 Features Not Implemented

Extensions to ksh-88

Renamed Commands

Rebinding of Editing Functions

20. Debugging Shared Libraries

Dynamic Linker

Link Map

Startup Sequence and .init Sections

Procedure Linkage Tables

Fix and Continue

Setting Breakpoints in Shared Libraries

Setting a Breakpoint in an Explicitly Loaded Library

A. Modifying a Program State

Impacts of Running a Program Under dbx

Commands That Alter the State of the Program

assign Command

pop Command

call Command

print Command

when Command

fix Command

cont at Command

B. Event Management

Event Handlers

Creating Event Handlers

Manipulating Event Handlers

Using Event Counters

Setting Event Specifications

Breakpoint Event Specifications

Data Change Event Specifications

System Event Specifications

Execution Progress Event Specifications

Other Event Specifications

Event Specification Modifiers

Parsing and Ambiguity

Using Predefined Variables

Variables Valid for when Command

Variables Valid for Specific Events

Setting Event Handler Examples

Setting a Breakpoint for Store to an Array Member

Implementing a Simple Trace

Enabling a Handler While Within a Function (in function)

Determining the Number of Lines Executed

Determining the Number of Instructions Executed by a Source Line

Enabling a Breakpoint After an Event Occurs

Resetting Application Files for replay

Checking Program Status

Catch Floating Point Exceptions

C. Command Reference

adb Command

assign Command

attach Command

bsearch Command

call Command

cancel Command

catch Command

check Command

clear Command

collector Command

collector archive Command

collector dbxsample Command

collector disable Command

collector enable Command

collector heaptrace Command

collector hwprofile Command

collector limit Command

collector mpitrace Command

collector pause Command

collector profile Command

collector resume Command

collector sample Command

collector show Command

collector status Command

collector store Command

collector synctrace Command

collector version Command

cont Command

dalias Command

dbx Command

dbxenv Command

debug Command

delete Command

detach Command

dis Command

display Command

down Command

dump Command

edit Command

examine Command

exception Command

exists Command

file Command

files Command

fix Command

fixed Command

frame Command

func Command

funcs Command

gdb Command

handler Command

hide Command

ignore Command

import Command

intercept Command

java Command

jclasses Command

joff Command

jon Command

jpkgs Command

kill Command

language Command

line Command

list Command

listi Command

loadobject Command

loadobject -dumpelf Command

loadobject -exclude Command

loadobject -hide Command

loadobject -list Command

loadobject -load Command

loadobject -unload Command

loadobject -use Command

lwp Command

lwps Command

mmapfile Command

module Command

modules Command

native Command

next Command

nexti Command

pathmap Command

pop Command

print Command

proc Command

prog Command

quit Command

regs Command

replay Command

rerun Command

restore Command

rprint Command

rtc -showmap Command

run Command

runargs Command

save Command

scopes Command

search Command

showblock Command

showleaks Command

showmemuse Command

source Command

status Command

step Command

stepi Command

stop Command

stopi Command

suppress Command

sync Command

syncs Command

thread Command

threads Command

trace Command

tracei Command

uncheck Command

undisplay Command

unhide Command

unintercept Command

unsuppress Command

up Command

use Command

whatis Command

when Command

wheni Command

where Command

whereami Command

whereis Command

which Command

whocatches Command

Index