The Art of Debugging with GDB, DDD, and Eclipse

Book description

Debugging is crucial to successful software development, but even many experienced programmers find it challenging. Sophisticated debugging tools are available, yet it may be difficult to determine which features are useful in which situations. The Art of Debugging is your guide to making the debugging process more efficient and effective.

The Art of Debugging illustrates the use three of the most popular debugging tools on Linux/Unix platforms: GDB, DDD, and Eclipse. The text-command based GDB (the GNU Project Debugger) is included with most distributions. DDD is a popular GUI front end for GDB, while Eclipse provides a complete integrated development environment.

In addition to offering specific advice for debugging with each tool, authors Norm Matloff and Pete Salzman cover general strategies for improving the process of finding and fixing coding errors, including how to:

  • Inspect variables and data structures
  • Understand segmentation faults and core dumps
  • Know why your program crashes or throws exceptions
  • Use features like catchpoints, convenience variables, and artificial arrays
  • Avoid common debugging pitfalls

Real world examples of coding errors help to clarify the authors' guiding principles, and coverage of complex topics like thread, client-server, GUI, and parallel programming debugging will make you even more proficient. You'll also learn how to prevent errors in the first place with text editors, compilers, error reporting, and static code checkers.

Whether you dread the thought of debugging your programs or simply want to improve your current debugging efforts, you'll find a valuable ally in The Art of Debugging.

Publisher resources

View/Submit Errata

Table of contents

  1. THE ART OF DEBUGGING WITH GDB, DDD, AND ECLIPSE
    1. PREFACE
    2. 1. SOME PRELIMINARIES FOR BEGINNERS AND PROS
      1. Debugging Tools Used in This Book
      2. Programming Language Focus
      3. The Principles of Debugging
        1. The Essence of Debugging: The Principle of Confirmation
        2. Of What Value Is a Debugging Tool for the Principle of Confirmation?
        3. Other Debugging Principles
      4. Text-Based vs. GUI-Based Debugging Tools, and a Compromise Between Them
        1. Brief Comparison of Interfaces
          1. GDB: Plain Text
          2. DDD: a GUI Debugging Tool
          3. Eclipse: A GUI Debugger and Much More
          4. Eclipse vs. DDD
          5. Advantages of the GUIs
          6. Advantages of GDB
          7. The Bottom Line: Each Has Its Value
        2. Compromises
          1. GDB in TUI Mode
          2. CGDB
      5. Main Debugger Operations
        1. Stepping Through the Source Code
        2. Inspecting Variables
        3. Issuing an "All Points Bulletin" for Changes to a Variable
        4. Moving Up and Down the Call Stack
      6. Online Help
      7. Introductory Debugging Session
        1. The GDB Approach
        2. The Same Session in DDD
        3. The Session in Eclipse
      8. Use of Startup Files
    3. 2. STOPPING TO TAKE A LOOK AROUND
      1. Mechanisms for Pause
      2. Overview of Breakpoints
      3. Keeping Track of Breakpoints
        1. Breakpoint Lists in GDB
        2. Breakpoint Lists in DDD
        3. Breakpoint Lists in Eclipse
      4. Setting Breakpoints
        1. Setting Breakpoints in GDB
        2. Setting Breakpoints in DDD
        3. Setting Breakpoints in Eclipse
      5. Extended GDB Example
      6. Persistence of Breakpoints
      7. Deleting and Disabling Breakpoints
        1. Deleting Breakpoints in GDB
        2. Disabling Breakpoints in GDB
        3. Deleting and Disabling Breakpoints in DDD
        4. Deleting and Disabling Breakpoints in Eclipse
        5. "Moving" Breakpoints in DDD
        6. Undoing/Redoing Breakpoint Actions in DDD
      8. More on Viewing Breakpoint Attributes
        1. GDB
        2. DDD
        3. Eclipse
      9. Resuming Execution
        1. In GDB
          1. Single-stepping with step and next
          2. Resuming Program Execution with continue
          3. Resuming Program Execution with finish
          4. Resuming Program Execution with until
        2. In DDD
          1. Standard Operations
          2. Undo/Redo
        3. In Eclipse
      10. Conditional Breakpoints
        1. GDB
        2. DDD
        3. Eclipse
      11. Breakpoint Command Lists
      12. Watchpoints
        1. Setting Watchpoints
        2. Expressions
    4. 3. INSPECTING AND SETTING VARIABLES
      1. Our Main Example Code
      2. Advanced Inspection and Setting of Variables
        1. Inspection in GDB
        2. Inspection in DDD
        3. Inspection in Eclipse
        4. Inspecting Dynamic Arrays
          1. Solutions in GDB
          2. Solutions in DDD
          3. Solutions in Eclipse
        5. What About C++?
        6. Monitoring Local Variables
        7. Examining Memory Directly
        8. Advanced Options for Print and Display
      3. Setting Variables from Within GDB/DDD/Eclipse
      4. GDB's Own Variables
        1. Making Use of the Value History
        2. Convenience Variables
    5. 4. WHEN A PROGRAM CRASHES
      1. Background Material: Memory Management
        1. Why Does a Program Crash?
        2. Program Layout in Memory
        3. The Notion of Pages
        4. Details on the Role of the Page Table
        5. A Slight Memory-Access Bug Might Not Cause a Seg Fault
        6. 4.1.6 Seg Faults and Unix Signals
        7. Other Types of Exceptions
      2. Core Files
        1. How Core Files Are Created
        2. Your Shell May Suppress the Creation of a Core File
      3. Extended Example
        1. First Bug
        2. Don't Leave GDB During a Debugging Session
        3. Second and Third Bugs
        4. Fourth Bug
        5. Fifth and Sixth Bugs
    6. 5. DEBUGGING IN A MULTIPLE-ACTIVITIES CONTEXT
      1. Debugging Client/Server Network Programs
      2. Debugging Threaded Code
        1. Review of Processes and Threads
        2. Basic Example
        3. A Variation
        4. GDB Threads Command Summary
        5. Threads Commands in DDD
        6. Threads Commands in Eclipse
      3. Debugging Parallel Applications
        1. Message-Passing Systems
        2. Shared-Memory Systems
          1. True Shared Memory
          2. Software Distributed Shared-Memory Systems
      4. Extended Example
        1. OpenMP Overview
        2. OpenMP Example Program
    7. 6. SPECIAL TOPICS
      1. What If It Doesn't Even Compile or Load?
        1. Phantom Line Numbers in Syntax Error Messages
        2. Missing Libraries
          1. Example
          2. Library Usage in Open Source Software
      2. Debugging GUI Programs
        1. Debugging Curses Programs
          1. Using GDB
          2. Using DDD
          3. Using Eclipse
    8. 7. OTHER TOOLS
      1. Making Good Use of a Text Editor
        1. Syntax Highlighting
        2. Matching Brackets
        3. Vim and Makefiles
        4. Makefiles and Compiler Warnings
        5. Final Thoughts on a Text Editor as an IDE
      2. Making Good Use of the Compiler
      3. Error Reporting in C
        1. Using errno
      4. Better Living with strace and ltrace
      5. Static Code Checkers: lint and Friends
        1. How to Use splint
        2. Last Words
      6. Debugging Dynamically Allocated Memory
        1. Strategies for Detecting DAM Problems
        2. Electric Fence
        3. Debugging DAM Problems with GNU C Library Tools
          1. The MALLOC_CHECK_ Environment Variable
          2. Using the mcheck() Facility
          3. Using mtrace() to Catch Memory Leaks and Double Frees
    9. 8. USING GDB/DDD/ECLIPSE FOR OTHER LANGUAGES
      1. Java
        1. TestLL.java
          1. TestLL.java
          2. LinkedList.java
          3. Node.java
        2. Direct Use of GDB for Debugging Java
        3. Using DDD with GDB to Debug Java
        4. Using DDD as a GUI for JDB
        5. Debugging Java in Eclipse
      2. Perl
        1. Debugging Perl via DDD
        2. Debugging Perl in Eclipse
      3. Python
        1. Debugging Python in DDD
        2. Debugging Python in Eclipse
      4. Debugging SWIG Code
      5. Assembly Language
    10. COLOPHON

Product information

  • Title: The Art of Debugging with GDB, DDD, and Eclipse
  • Author(s): Norman Matloff, Peter Jay Salzman
  • Release date: September 2008
  • Publisher(s): No Starch Press
  • ISBN: 9781593271749