Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

The Bag of Holding

A bottomless satchel once possessed by a knight-errant.

Source-Level Debugging For Epoch Programs

This weekend marks a major milestone for the development of the Epoch programming language. For the first time, Windows debuggers such as Visual Studio and WinDbg can perform source-level debugging on Epoch programs.

In a nutshell, this means that the comfortable modern development features of setting breakpoints and stepping through code are now available to Epoch programmers.

One notable thing left to achieve is runtime state inspection. There is currently not enough data generated by the Epoch compiler to reliably inspect variables, function parameters, and so on in the debugger. This will be my next major point of focus.

Visual Studio 2015 Debugging a Simple Epoch Program
WinDbg Debugging the Same Epoch Program

How We Got Here

Attaining this functionality was not easy, but it was definitely worth the investment. It all started almost exactly a year ago, when I decided that being unable to debug the self-hosting process for 64-bit Epoch was unacceptable.

Initially debug information was generated via piping some bogus line numbers into LLVM and then routing the generated block of CodeView symbols into MSPDB140.dll to generate a somewhat-working PDB file on disk. This implementation took about two weeks.

That wasn’t enough, though; it introduced a heavy dependency on Visual Studio (something I’ve been keen to avoid, despite strongly encouraging use of VS with Epoch) and also had limitations via the API of MSPDB140.dll that were…​ inscrutable, to say the least.

So I set out in search of a complete understanding of the PDB file format and how to generate my own debug information for it. The intervening year wasn’t all dedicated to PDB work; a fair amount of time went into Visual Studio integration and other tidbits of self-hosting effort. (Not to mention there were a few major spans of downtime. This gets exhausting after a while!)

The Epoch repo commit log shows the gory details of how everything came together, but the high-level is pretty simple; using a suite of tools, I reverse engineered large sections of the PDB format and developed an Epoch implementation of code to write them out.

Noteworthy projects:

Target debuggers have been VS2015 and WinDbg, both of which work now with source-level breakpoints and stepping. x64dbg also sort-of works, although it doesn’t like to display source for some reason; everything else seems to be fine, so I don’t know the tool well enough to say if it’s my bug or theirs.

What Comes Next

As alluded to above, my next major project is to get variable data inspection working. This is a dark corner of the PDB format that seems poorly understood in the community, so it should be exciting to try and forge ahead here.

At a minimum, I’ll need to start generating types data in the PDBs, so that debuggers know how to interpret various memory addresses correctly. There’s probably some other voodoo too, but that’ll have to wait until I discover what’s in store.

About the author

Mike Lewis

Bellevue, WA

Guild Wars 2 Project Technical Director @arenanet and author of the Epoch programming language.