Debugging a Program with Dbx
Total Page:16
File Type:pdf, Size:1020Kb
Debugging a Program With dbx Forte Developer 7 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. 650-960-1300 Part No 816-2453-10 May 2002, Revision A Send comments about this document to: [email protected] Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. and in other countries. This document and the product to which it pertains are distributed under licenses restricting their use, copying, distribution, and decompilation. No part of the product or of this document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and in other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun logo, Forte, Java, Solaris, iPlanet, NetBeans, and docs.sun.com are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon architecture developed by Sun Microsystems, Inc. Netscape and Netscape Navigator are trademarks or registered trademarks of Netscape Communications Corporation in the United States and other countries. Sun f90/f95 is derived in part from Cray CF90™, a product of Cray Inc. libdwarf and lidredblack are Copyright 2000 Silicon Graphics Inc. and are available under the GNU Lesser General Public License from http://www.sgi.com. Federal Acquisitions: Commercial Software—Government Users Subject to Standard License Terms and Conditions. DOCUMENTATION IS PROVIDED “AS IS” AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits réservés. Sun Microsystems, Inc. a les droits de propriété intellectuels relatants à la technologie incorporée dans le produit qui est décrit dans ce document. En particulier, et sans la limitation, ces droits de propriété intellectuels peuvent inclure un ou plus des brevets américains énumérés à http://www.sun.com/patents et un ou les brevets plus supplémentaires ou les applications de brevet en attente dans les Etats - Unis et dans les autres pays. Ce produit ou document est protégé par un copyright et distribué avec des licences qui en restreignent l’utilisation, la copie, la distribution, et la décompilation. Aucune partie de ce produit ou document ne peut être reproduite sous aucune forme, parquelque moyen que ce soit, sans l’autorisation préalable et écrite de Sun et de ses bailleurs de licence, s’il y en a. Le logiciel détenu par des tiers, et qui comprend la technologie relative aux polices de caractères, est protégé par un copyright et licencié par des fournisseurs de Sun. Des parties de ce produit pourront être dérivées des systèmes Berkeley BSD licenciés par l’Université de Californie. UNIX est une marque déposée aux Etats-Unis et dans d’autres pays et licenciée exclusivement par X/Open Company, Ltd. Sun, Sun Microsystems, le logo Sun, Forte, Java, Solaris, iPlanet, NetBeans, et docs.sun.com sont des marques de fabrique ou des marques déposées de Sun Microsystems, Inc. aux Etats-Unis et dans d’autres pays. Toutes les marques SPARC sont utilisées sous licence et sont des marques de fabrique ou des marques déposées de SPARC International, Inc. aux Etats-Unis et dans d’autres pays. Les produits protant les marques SPARC sont basés sur une architecture développée par Sun Microsystems, Inc. Netscape et Netscape Navigator sont des marques de fabrique ou des marques déposées de Netscape Communications Corporation aux Etats- Unis et dans d’autres pays. Sun f90/f95 est deriveé d’une part de Cray CF90™, un produit de Cray Inc. libdwarf et lidredblack sont Copyright 2000 Silicon Graphics Inc., et sont disponible sur GNU General Public License à http://www.sgi.com. LA DOCUMENTATION EST FOURNIE “EN L’ÉTAT” ET TOUTES AUTRES CONDITIONS, DECLARATIONS ET GARANTIES EXPRESSES OU TACITES SONT FORMELLEMENT EXCLUES, DANS LA MESURE AUTORISEE PAR LA LOI APPLICABLE, Y COMPRIS NOTAMMENT TOUTE GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A L’APTITUDE A UNE UTILISATION PARTICULIERE OU A L’ABSENCE DE CONTREFAÇON. Contents Before You Begin xxv How This Book Is Organized xxv Typographic Conventions xxvii Shell Prompts xxviii Accessing Forte Developer Development Tools and Man Pages xxviii Accessing Forte Developer Documentation xxx Accessing Related Solaris Documentation xxxii Sending Your Comments xxxiii 1. Getting Started With dbx 1 Compiling Your Code for Debugging 1 Starting dbx and Loading Your Program 2 Running Your Program in dbx 4 Debugging Your Program With dbx 5 Examining a Core File 5 Setting Breakpoints 7 Stepping Through Your Program 8 Looking at the Call Stack 9 Examining Variables 10 iii Finding Memory Access Problems and Memory Leaks 11 Quitting dbx 12 Accessing dbx Online Help 12 2. Starting dbx 13 Starting a Debugging Session 13 Debugging a Core File 14 Debugging a Core File in the Same Operating Environment 14 If Your Core File is Truncated 15 Debugging a Mismatched Core File 15 Using the Process ID 18 The dbx Startup Sequence 19 Setting Startup Properties 19 Mapping the Compile-time Directory to the Debug-time Directory 20 Setting dbx Environment Variables 20 Creating Your Own dbx Commands 21 Compiling a Program for Debugging 21 Debugging Optimized Code 21 Code Compiled Without the -g Option 22 Shared Libraries Require the -g Option for Full dbx Support 22 Completely Stripped Programs 23 Quitting Debugging 23 Stopping a Process Execution 23 Detaching a Process From dbx 23 Killing a Program Without Terminating the Session 24 Saving and Restoring a Debugging Run 24 Using the save Command 24 Saving a Series of Debugging Runs as Checkpoints 26 iv Debugging a Program With dbx • May 2002 Restoring a Saved Run 26 Saving and Restoring Using replay 27 3. Customizing dbx 29 Using the dbx Initialization File 29 Creating a .dbxrc File 30 Initialization File Sample 30 Setting dbx Environment Variables 30 The dbx Environment Variables and the Korn Shell 36 4. Viewing and Navigating Through Code 37 Mapping to the Location of the Code 37 Scope 38 Changing the Current Scope 38 Relaxing the Scope Lookup Rules 39 Navigating Through Code 39 Navigating Through a File 39 Navigating Through Functions 40 Printing a Source Listing 41 Walking the Call Stack to Navigate Through Code 41 Qualifying Symbols With Scope Resolution Operators 42 Backquote Operator 42 C++ Double Colon Scope Resolution Operator 42 Block Local Operator 43 Linker Names 43 Scope Resolution Search Path 44 Locating Symbols 44 Printing a List of Occurrences of a Symbol 45 Determining Which Symbol dbx Uses 45 Contents v Viewing Variables, Members, Types, and Classes 46 Looking Up Definitions of Variables, Members, and Functions 46 Looking Up Definitions of Types and Classes 48 Using the Auto-Read Facility 50 Debugging Without the Presence of .o Files 51 Listing Debugging Information for Modules 51 Listing Modules 52 5. Controlling Program Execution 53 Running a Program 53 Attaching dbx to a Running Process 54 Detaching dbx From a Process 55 Stepping Through a Program 56 Single Stepping 56 Continuing Execution of a Program 57 Calling a Function 58 Using Ctrl+C to Stop a Process 59 6. Setting Breakpoints and Traces 61 Setting Breakpoints 61 Setting a stop Breakpoint at a Line of Source Code 62 Setting a stop Breakpoint in a Function 63 Setting Multiple Breaks in C++ Programs 64 Setting Data Change Breakpoints 66 Setting Filters on Breakpoints 69 Tracing Execution 71 Setting a Trace 71 Controlling the Speed of a Trace 71 Directing Trace Output to a File 72 vi Debugging a Program With dbx • May 2002 Setting a when Breakpoint at a Line 72 Setting a Breakpoint in a Shared Library 72 Listing and Clearing Breakpoints 73 Listing Breakpoints and Traces 73 Deleting Specific Breakpoints Using Handler ID Numbers 73 Enabling and Disabling Breakpoints 74 Efficiency Considerations 74 7. Using the Call Stack 77 Finding Your Place on the Stack 77 Walking the Stack and Returning Home 78 Moving Up and Down the Stack 78 Moving Up the Stack 78 Moving Down the Stack 79 Moving to a Specific Frame 79 Popping the Call Stack 79 Hiding Stack Frames 80 Displaying and Reading a Stack Trace 81 8. Evaluating and Displaying Data 83 Evaluating Variables and Expressions 83 Verifying Which Variable dbx Uses 83 Variables Outside the Scope of the Current Function 84 Printing the Value of a Variable, Expression, or Identifier 84 Printing C++ 84 Dereferencing Pointers 86 Monitoring Expressions 86 Turning Off Display (Undisplaying) 87 Assigning