Leanpub Header

Skip to main content

Inside the Debugger: Building a Source-Level Debugger in Rust

A Deep Dive into Processes, Memory, Breakpoints, and DWARF Debug Information

This book is 100% completeLast updated on 2026-07-13

Build a source-level debugger in Rust from the ground up while uncovering the operating system, CPU, and compiler mechanisms behind modern debugging. Through hands-on implementation, you'll learn how processes, memory, breakpoints, and DWARF debug information come together to make source-level debugging possible.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

A debugger is not magic. It is a careful orchestration of operating system primitives, CPU features, and compiler-generated metadata that together let you pause a running program, inspect its state, and control its execution one instruction at a time. This book teaches you how to build a fully functional source-level debugger from scratch in Rust. Starting from the fundamentals of processes, virtual memory, and executable formats, we progressively implement every feature a real debugger needs: process attachment, software and hardware breakpoints, single stepping, register inspection, memory read and write, symbol resolution, stack unwinding, call frame inspection, DWARF debug information parsing, source-level debugging, expression evaluation, watchpoints, multithreaded debugging, shared library support, signal handling, and remote debugging concepts. Every concept is accompanied by complete, production-quality Rust code that builds upon previous chapters into a cohesive debugger. By the end of this book, you will have built a capable debugger entirely in Rust and gained deep insight into how programs execute, how operating systems manage processes, and how compilers encode the information needed to map machine code back to source code.

Author

About the Author

Steve T. Publications

Steve T. Publications is a specialized book publishing company dedicated to delivering high-quality technical resources for IT professionals, students, educators, and technology enthusiasts. Our mission is to make complex technology concepts accessible through well-structured, practical, and industry-relevant publications.

We focus on publishing books across a wide range of information technology disciplines, including software development, cloud computing, cybersecurity, artificial intelligence, data science, networking, DevOps, databases, and enterprise technologies. Every publication is designed to bridge the gap between theory and real-world application, helping readers build the skills needed to succeed in today's rapidly evolving digital landscape.

At Steve T. Publications, we collaborate with experienced industry experts, educators, and technology professionals to produce accurate, up-to-date, and engaging content. We are committed to maintaining the highest editorial standards while empowering learners and professionals with trusted technical knowledge.

Whether you're beginning your IT journey, preparing for professional certifications, or advancing your expertise in emerging technologies, Steve T. Publications is your trusted source for authoritative and practical technical books.

Contents

Table of Contents

A Deep Dive into Processes, Memory, Breakpoints, and DWARF Debug Information

Introduction

  1. Why Build a Debugger?
  2. What This Book Covers
  3. Prerequisites
  4. How to Read This Book
  5. What About the Code?

Chapter 1: What Is a Debugger, Really?

  1. The Debugger as an Operating System Feature
  2. The Debugging Loop
  3. What We Will Build
  4. Why Rust for a Debugger?
  5. The Architecture of Our Debugger
  6. A Brief History of Debuggers

Chapter 2: The Building Blocks: Processes, Memory, and the CPU

  1. Processes and the Process Table
  2. Virtual Memory and Address Spaces
  3. The CPU Registers and Program Counter
  4. How Programs Start: Loading and Entry Points
  5. System Calls and the Kernel Boundary
  6. Putting It All Together: A Process in Motion

Chapter 3: The ptrace System Call: Your Gateway to Debugging

  1. ptrace Fundamentals
  2. Process Stop States and Wait
  3. Reading and Writing Registers
  4. Reading and Writing Memory
  5. Single Stepping and Instruction Control
  6. ptrace Security and Permissions
  7. The Complete ptrace Workflow

Chapter 4: Executable Formats and DWARF Debug Information

  1. The ELF File Format
  2. Symbol Tables and Relocations
  3. DWARF Debug Information Overview
  4. Line Number Program
  5. Variable Locations and Expressions
  6. Reading DWARF in Rust with gimli
  7. DWARF Version Differences
  8. Putting It Together: From Address to Source Line

Chapter 5: Project Setup and the Debugger Shell

  1. Project Structure and Dependencies
  2. The Debugger Core Trait and Architecture
  3. Command Parsing
  4. Process Fork and Trace
  5. The First Debug Session
  6. The First Debug Session

Chapter 6: Breakpoints: Stopping at Will

  1. Software Breakpoints and INT3
  2. The Breakpoint Lifecycle
  3. Breakpoint Data Structures
  4. Handling Breakpoint Hits
  5. Multiple Breakpoints and Conditional Execution
  6. Testing Breakpoints
  7. Common Pitfalls

Chapter 7: Single Stepping and Register Inspection

  1. Single Stepping with PTRACE_SINGLESTEP
  2. The x86_64 Register File
  3. Reading Registers After a Stop
  4. Writing Registers
  5. The Step Over Problem
  6. Register Display Formatting

Chapter 8: Memory Inspection and Modification

  1. Reading Process Memory
  2. Memory Display Formats
  3. Handling Page Faults and Invalid Addresses
  4. The /proc/[pid]/mem Alternative
  5. Memory Region Discovery
  6. Writing Memory Safely

Chapter 9: Symbol Resolution and Source-Level Debugging

  1. Symbol Lookup
  2. Demangling C++ and Rust Symbols
  3. Source File Discovery
  4. Displaying Source Code with Current Line Highlighting
  5. Step Over at the Source Level
  6. Frame Pointer Omission and Its Consequences

Chapter 10: Stack Unwinding and Call Frames

  1. The Call Stack Explained
  2. Frame Pointer-Based Unwinding
  3. DWARF Call Frame Information
  4. Displaying the Backtrace
  5. Local Variable Inspection

Chapter 11: Watchpoints, Hardware Breakpoints, and Advanced Tracing

  1. Hardware Debug Registers
  2. Setting Hardware Breakpoints
  3. The PTRACE_GETREGSET and NT_X86_DEBUGREGS Interface
  4. Limitations and Fallback Strategies
  5. Watchpoint Manager
  6. Tracepoints and Logging

Chapter 12: Multithreaded Debugging and Shared Libraries

  1. Thread Groups and ptrace
  2. PTRACE_SEIZE and Group Stop
  3. Debugging Existing Processes
  4. Shared Library Loading Events
  5. Symbol Resolution Across Shared Libraries
  6. Thread-Specific Data and Stack Layout

Chapter 13: Expression Evaluation and Variable Modification

  1. The Expression Evaluation Problem
  2. Building a Simple Expression Parser
  3. Type Resolution from DWARF
  4. The Set Command
  5. Limitations and Pragmatic Choices

Chapter 14: Signals, Exceptions, and Error Handling

  1. Signal Delivery During Tracing
  2. Distinguishing Breakpoint Signals from Real SIGTRAPs
  3. Signal Masking and Filtering
  4. Handling Common Signals
  5. Crash Dump Generation
  6. Debugger Error Handling

Chapter 15: Architecture, Testing, and Going Further

  1. The Complete Debugger Architecture
  2. Testing a Debugger
  3. Performance Considerations
  4. Portability: macOS ptrace and Windows Debug Active Process API
  5. Remote Debugging Concepts
  6. Extending Your Debugger

Conclusion: What We Built and What It Teaches Us

  1. The Layers of Understanding
  2. What Makes a Good Debugger?
  3. The Bigger Picture
  4. Final Thoughts

Appendix A: Complete Project Structure

  1. Directory Layout
  2. Module Dependencies
  3. Shared Types and Conventions
  4. Building and Running
  5. Testing Strategy
  6. Companion Repository

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub