alexcrichton transferred Issue #350:
DWARF line table support may be a good way to get started with the broader topic of producing debug info, as it's relatively straightforward, and quite valuable.
Briefly surveying the landscape, the three main options appear to be:
- Add dwarf writing support to the gimli crate. The gimli crate doesn't have any support for writing DWARF, and I don't know whether the maintainers would be interested in accepting patches for that, but it's worth exploring.
- Write a new DWARF producer library.
- Create Rust bindings to an existing C/C++ dwarf producer library, such as libdwarf. It'd be fun to pursue a pure-Rust solution instead, however using a C/C++ library might be a quicker way to get something working without delving into the lowest level of DWARF encoding.
(There is also the dwarf crate has rudimentary support for writing, though not yet writing .debug_line sections. Judging by this comment, it seems no longer maintained, in favor of gimli.)
Regardless of how we implement it, the code for consuming cretonne IR and emitting DWARF should be in a new crate, as other users of the cretonne-codegen crate won't need it. It will need to emit the binary data for the section, plus relocation records telling the linker where to fix up program addresses.
The first step is to write a minimal
.debug_info
section, containing aDW_TAG_compile_unit
, and aDW_TAG_subprogram
entry for each function. Chapter 2 "General Description" of the dwarf spec defines the overall structure of these. I also recommend either the dwarfdump utility and/orreadelf --debug-dump=info,lines
for examining DWARF output from other compilers to get a sense of what this needs to look like. Then, we can implement the line table. Section 6.2 "Line Number Information" defines the line table format. I'll flesh out these steps more when we're ready; right now I'm just sketching out the major areas that would be covered.
Last updated: Dec 23 2024 at 14:03 UTC