[llvm-dev] [DebugInfo] DWARF C API

David Blaikie via llvm-dev llvm-dev at lists.llvm.org
Wed Apr 24 14:03:28 PDT 2019


Might be worth running under valgrind or the LLVM sanitizers? (could
help diagnose what's going wrong more specifically than a segfault)

On Wed, Apr 24, 2019 at 1:57 PM Son Tuan VU via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>
> Hi folks,
>
> I am trying to implement the C bindings API for DebugInfo::DWARF::DWARFDie. My goal is to have a C library that reads and parses DWARF debugging format (just like how llvm-dwarfdump does, but maybe more than just dumping debug info)
>
> I've started with creating C structure for DebugInfo::DWARF::DWARFContext which contains all DWARF DIEs in the object file. For this I used
> ```
> DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DWARFContext, LLVMDWARFContextRef)
> ```
> then defined some C functions
> ```
> LLVMDWARFContextRef LLVMCreateDWARFContext(LLVMBinaryRef Bin) {
>   std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*unwrap(Bin));
>   return wrap(DICtx.release());
> }
>
> void LLVMPrintDWARFContext(LLVMDWARFContextRef C) {
>   DIDumpOptions DumpOpts;
>   DumpOpts.DumpType = DIDT_DebugInfo; // I only care about the .debug_info section
>   unwrap(C)->dump(outs(), DumpOpts);
> }
> ```
> However, I got a segfault when trying to dump the LLVMDWARFContextRef using the second function. More precisely, it segfaulted when dumping the attribute of the DWARFDie.
>
> I tried to do this instead to see if the wrapping/unwrapping has bugs
> ```
> LLVMDWARFContextRef LLVMCreateDWARFContext(LLVMBinaryRef Bin) {
>   std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*unwrap(Bin));
>   LLVMDWARFContextRef C = wrap(DICtx.release());
>   LLVMPrintDWARFContext(C);
>   return C;
> }
> ```
> and the call to LLVMPrintDWARFContext did not segfault this time.
>
> Can anybody who knows about DWARFContext and DWARFDie tell me what I did wrong? Or is it a bug in DWARFDie::dump() method?
>
> Thank you very much for your help,
>
> Son Tuan Vu
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list