Preface
For students:
Programming is hard, writing a compiler is harder.
Debugging is hard, writing a debugger is harder.
Writing a compiler and a debugger at the same time? That's rocket science!
For a long while - that's how I thought. I think only big companies like Microsoft or Oracle can build programming languages and debuggers, except this is actually not true. While building a sophisticated programming language is hard, building a simple language can be easy. Similarly, writing a debugger without all the bells and whistles can be simple too!
In part one, we will demonstrate a simple compiler for a simple language.
In part two, we will demonstrate a simple debugger for the simple language.
In total, the compiler and the debugger has less than 10K line of code. But do not get deceived by that, this is made possible only because I side-stepped a lot of practical issues that one must solve in real settings.
For instructors:
I am hoping this is the book you were wishing for. These days, there are many books on compilers, most of them focusing on optimization, and rightfully so. So far, I haven't found myself one that talks about generating debuggable code, as if this is easy to do, not worth mentioning.
Except it is actually not. Getting a debugging scenario running requires diverse knowledge ranging from the processor, the operating system supports, the understanding of the Application Binary Interface, the compiler support for debugging information, and even knowledge about designing user interfaces.
This book contains a project that a student or group of students could do in settings where they can grab the basics of how debugging work in practice without having to deal with tons of uninteresting details.
On the other hand, this book will talk about the actual complication that one must face when building a real debugger, so this can be used as a practical reference too.
The book can be used as a supplement for a standard compiler course, or it could be used for self study.
Acknowledgement
To Mingming Zhao, for this book would not be possible without her endless support for me and for my family.