Writing a Linux Debugger (2017)

https://news.ycombinator.com/rss Hits: 1
Summary

This series has been expanded into a book! It covers many more topics in much greater detail. You can now pre-order Building a Debugger. Debuggers are one of the most valuable tools in any developer’s kit. However, although these tools are in such widespread use, there aren’t a lot of resources which tell you how they work and how to write one, especially when compared to other toolchain technologies like compilers. In this post series we’ll learn what makes debuggers tick and write one for debugging Linux programs. This tutorial is split into 10 parts and you can find the final code, along with branches for each part, on GitHub. If you’re on Windows, you can still follow along using WSL. Our debugger will support the following features: Launch, halt, and continue execution Set breakpoints on Memory addresses Source code lines Function entry Read and write registers and memory Single stepping Instruction Step in Step out Step over Print current source location Print backtrace Print values of simple variables In the final part I’ll also outline how you could add the following to your debugger: Remote debugging Shared library and dynamic loading support Expression evaluation Multi-threaded debugging support I’ll be focusing on C and C++ for this project, but it should work just as well with any language which compiles down to machine code and outputs standard DWARF debug information (if you don’t know what that is yet, don’t worry, this will be covered soon). Additionally, my focus will be on getting something up and running which works most of the time, so things like robust error handling will be eschewed in favour of simplicity. Series index Setup Breakpoints Registers and memory Elves and dwarves Source and signals Source-level stepping Source-level breakpoints Stack unwinding Handling variables Advanced topics Getting set up Before we jump into things, let’s get our environment set up. I’ll be using two dependencies in this tutorial: Linenoise for handling our co...

First seen: 2025-04-25 14:55

Last seen: 2025-04-25 14:55