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

Stefan Kratochwil via lldb-dev lldb-dev at lists.llvm.org
Fri Oct 30 03:35:54 PDT 2015


Hi Greg,

thanks for your reply.

I am developing a dynamic software updating tool for dynamically linked 
C libraries (in short: I want to patch dynamic libraries in-memory).

My goal is to achieve that without any code instrumentation. The main 
problem is the state transformation between the old and the new version 
- here I need as much type (and location) information as possible.

I am currently unaware of what types of information I _really_ need, so 
for now, getting as much information as possible is my way to go. I 
guess that the most important types of information will be:
- size of primitives
- size of pointers
- type hierarchies and
- the in memory-structure of compound data types

At the moment I am concentrating on the Linux / UNIX domain, so DWARF is 
my preferred format.

Cheers,
Stefan



On 10/14/2015 12:15 AM, Greg Clayton wrote:
>
>> 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