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