[lldb-dev] Accessing DWARF information from C++

Greg Clayton via lldb-dev lldb-dev at lists.llvm.org
Tue Oct 13 15:15:53 PDT 2015


> On Oct 13, 2015, at 2:42 AM, Stefan Kratochwil via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> 
> Hi altogether,
> 
> I currently am developing an application where I need to access the DWARF debugging information of my target process and its loaded .so files.
> 
> In more detail, I need to match type information of certain entities within my code and its dynamically linked libraries.
> 
> 
> I already use the lldb scripting bridge in my application, hence I would like to use lldb's DWARF parsing capabilities in my application, too.
> 
> Now, there is no (obvious) way to extract DIEs using the C++ API, so I need a few hints where to start. Does anyone have a minimal example for simply dumping DWARF info in a 'readelf -w' manner?

We don't dump DWARF unless it is done by enabling DWARF logging, but that won't help you. So if you want to just dump dwarf, use lldb-dwarfdump.

> I further  discovered another DWARF implementation within the llvm sources. After some investigation I found this discussion on lldb-dev:
> http://lists.cs.uiuc.edu/pipermail/lldb-dev/2014-June/004197.html
> 
> Does anybody know if there is already some effort made to implement a lldwarf solution as a replacement for both mentioned implementations?

LLDB provides a debug info agnostic abstraction. If you want actual raw DWARF, then you should use llvm's DWARF parser. llvm's DWARF parser was created by copying the LLDB version and trimming it down. It was initially done to get to file and line info in the .debug_info, but it has been expanded since.

> And, after going through the discussion, is it probably better for me to use the llvm fork?

So this depends on how DWARF specific you need things. With LLDB, you can lookup types by name and get a SBType back that can give you all of the info that DWARF will give you. You can get SBFunction objects that describe functions, you can lookup an address and get a SBSymbolContext which will give you access to the SBModule (object file), SBCompileUnit, SBFunction, SBBlock, SBLineEntry and SBSymbol. So you will be able to use LLDB to do specific queries, but we won't give you exact DWARF access. So if you use LLDB depends on what you are looking to get from the debug info. Can you clarify what kinds of queries you will be making? I might be able to tell you if you will be able to do them with our public API.

Greg




More information about the lldb-dev mailing list