jyn514 / saltwater

A C compiler written in Rust, with a focus on good error messages.
BSD 3-Clause "New" or "Revised" License
293 stars 27 forks source link

Emit debug info #152

Open jyn514 opened 4 years ago

jyn514 commented 4 years ago

Related to https://github.com/jyn514/rcc/issues/16, but at the object file level instead of assembly level: We should emit debug info for the binary we emit.

I think https://docs.rs/cranelift-frontend/0.51.0/cranelift_frontend/struct.FunctionBuilder.html?search=#method.set_srcloc is the API we want?

jyn514 commented 4 years ago

This looks helpful: https://github.com/bjorn3/rustc_codegen_cranelift/commit/5873127ec2b1d748bb673c0193682a563fcb6fe0

philipc commented 4 years ago

Currently cranelift only provides minimal debuginfo support:

But for both of these, it is up to the user to then generate the debuginfo. For examples of doing that, rustc_codegen_cranelift can generate .debug_line information from the srcloc as you have seen (as well as incomplete .debug_info support), and https://github.com/bytecodealliance/cranelift/pull/902 can generate .eh_frame information from the frame layout. Both of these use https://github.com/gimli-rs/gimli to do the writing.

Eventually there will probably be something that makes this all easier for users, but for now it's a bit experimental.

jyn514 commented 4 years ago

@philipc thanks for the tips! For now, this is fairly low on the todo-list, so I'm fine with waiting a little to see if a better API pops up. If not, I may get to it in a month or so.

Currently, the debug info is mostly so I can debug my own bad codegen, since no one is using my compiler for their own projects yet.