I'm currently toying around with a simple LLVM frontend written in Rust. I'm now trying to emit debug information.
How can I emit this debug information (source locations and variables) through the C bindings? Is it even possible? Do I need to write a C++ wrapper?
There seems to be a function for inserting source locations (LLVMSetCurrentDebugLocation; LLVM; Rust), but I don't know how to construct a proper LLVMValue
containing this information. I guess it needs some kind of metadata.
See DebugInfo.h for the mappings from the C++ LLVM debug info APIs to the C bindings. Examples that you'll need are:
(use those functions to setup the dwarf context for your compiler)
The LLVMSetCurrentDebugLocation() function you mentioned is the equivalent of IRBuilder<>::SetCurrentDebugLocation()
For each debug expression, you want a debug location, and DWARF metadata for the expression. That's done like the following (C++ fragment):
auto loc_glc = DebugLoc::get( line, column, dwFunc );
m_dwBuilder->insertDeclare( r, dwVar_gr, m_dwBuilder->createExpression(), loc_glc, fooBB );
m_builder.SetCurrentDebugLocation( loc_glc );
you'll want to associate the debug location with the DWARF expression, and then "anchor" that to your IRBuilder using LLVMSetCurrentDebugLocation().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With