How does LLDB get a declaration of a variable from DWARF debug info?


I’m looking to solve a problem where I need to get C+±style variable declaration from dwarf debug info. I asked about it in this topic and was pointed towards LLDB as that is probably solving a very similar issue, if not the same.

I poked around LLDB a little bit and found DWARFASTParserClang::ParseTypeFromDWARF which appears to be doing the kind of traversal that I’m looking for. Can somebody confirm whether this is the function I need to look at?

In general I would like to know whether that kind of functionality exists for me to reuse or whether I would have to implement it myself?

If you have an object file in a format lldb supports with DWARF debug information, then you should be able to load it into lldb with the SBTarget API’s, then read the type information out using the SBTarget::FindTypes API. Then you can use the SBType & SBTypeMember API’s to access details about the type. lldb doesn’t have an explicit “write out an equivalent header for this type”, the type Description is pretty close, falling short if it does because it was intended for human comprehension rather than recompilation.

The SB API’s are the stable public API’s and should be used for “I’m trying to use lldb to analyze X” problems. The lldb_private API’s (like the DWARFParser API you sited) are the internal API’s, and should only be used if you are adding features to lldb.