<div dir="ltr"><div dir="ltr"><div>Hi David,</div><div><br></div><div>Sorry, I forget to attach the valgrind dump to this. I was not sure if my implementation was ok, so I wanted to ask if I've done something wrong first.</div><div><br></div><div> Process terminating with default action of signal 11 (SIGSEGV)<br> Access not within mapped region at address 0xB<br> at 0x54F4516: llvm::object::COFFObjectFile::moveSectionNext(llvm::object::DataRefImpl&) const (COFFObjectFile.cpp:267)<br> by 0x55A62FB: llvm::object::ObjectFile::isBerkeleyText(llvm::object::DataRefImpl) const (ObjectFile.cpp:80)<br> by 0x5538CF9: llvm::object::RelocationRef::getType() const (ObjectFile.h:543)<br> by 0x55AE53E: llvm::object::resolveARM(llvm::object::RelocationRef, unsigned long, unsigned long) (RelocationResolver.cpp:250)<br> by 0x502802B: llvm::DWARFDataExtractor::getRelocatedValue(unsigned int, unsigned int*, unsigned long*) const (DWARFDataExtractor.cpp:27)<br> by 0x5071C2F: llvm::DWARFUnitHeader::extract(llvm::DWARFContext&, llvm::DWARFDataExtractor const&, unsigned int*, llvm::DWARFSectionKind, llvm::DWARFUnitIndex const*, llvm::DWARFUnitIndex::Entr y const*) (DWARFUnit.cpp:254)<br> by 0x5070BAD: llvm::DWARFUnitVector::addUnitsImpl(llvm::DWARFContext&, llvm::DWARFObject const&, llvm::DWARFSection const&, llvm::DWARFDebugAbbrev const*, llvm::DWARFSection const*, llvm::DWARF Section const*, llvm::StringRef, llvm::DWARFSection const&, llvm::DWARFSection const*, llvm::DWARFSection const&, bool, bool, bool, llvm::DWARFSectionKind)::{lambda(unsigned int, llvm::DWARFSectionKind, llvm ::DWARFSection const*, llvm::DWARFUnitIndex::Entry const*)#1}::operator()(unsigned int, llvm::DWARFSectionKind, llvm::DWARFSection const*, llvm::DWARFUnitIndex::Entry const*) const (DWARFUnit.cpp:82)</div><div><br></div><div> by 0x50751E1: std::_Function_handler<std::unique_ptr<llvm::DWARFUnit, std::default_delete<llvm::DWARFUnit> > (unsigned int, llvm::DWARFSectionKind, llvm::DWARFSection const*, llvm::DWARFUnitInd ex::Entry const*), llvm::DWARFUnitVector::addUnitsImpl(llvm::DWARFContext&, llvm::DWARFObject const&, llvm::DWARFSection const&, llvm::DWARFDebugAbbrev const*, llvm::DWARFSection const*, llvm::DWARFSection c onst*, llvm::StringRef, llvm::DWARFSection const&, llvm::DWARFSection const*, llvm::DWARFSection const&, bool, bool, bool, llvm::DWARFSectionKind)::{lambda(unsigned int, llvm::DWARFSectionKind, llvm::DWARFSe ction const*, llvm::DWARFUnitIndex::Entry const*)#1}>::_M_invoke(std::_Any_data const&, unsigned int, llvm::DWARFSectionKind, llvm::DWARFSection const*, llvm::DWARFUnitIndex::Entry const*) (functional:2057)</div><div><br></div><div> by 0x507656E: std::function<std::unique_ptr<llvm::DWARFUnit, std::default_delete<llvm::DWARFUnit> > (unsigned int, llvm::DWARFSectionKind, llvm::DWARFSection const*, llvm::DWARFUnitIndex::Entry const*)>::operator()(unsigned int, llvm::DWARFSectionKind, llvm::DWARFSection const*, llvm::DWARFUnitIndex::Entry const*) const (functional:2471)</div><div><br></div><div> by 0x5070FE6: llvm::DWARFUnitVector::addUnitsImpl(llvm::DWARFContext&, llvm::DWARFObject const&, llvm::DWARFSection const&, llvm::DWARFDebugAbbrev const*, llvm::DWARFSection const*, llvm::DWARF Section const*, llvm::StringRef, llvm::DWARFSection const&, llvm::DWARFSection const*, llvm::DWARFSection const&, bool, bool, bool, llvm::DWARFSectionKind) (DWARFUnit.cpp:111)</div><div><br></div><div> by 0x50708CF: llvm::DWARFUnitVector::addUnitsForSection(llvm::DWARFContext&, llvm::DWARFSection const&, llvm::DWARFSectionKind) (DWARFUnit.cpp:44)<br> by 0x5000AAE: llvm::DWARFContext::parseNormalUnits()::{lambda(llvm::DWARFSection const&)#1}::operator()(llvm::DWARFSection const&) const (DWARFContext.cpp:881)</div><div><br></div><div>However, I can't see how this error can relate to the wrapping/unwrapping macros generating C structure?</div><div><br></div><div>Thanks a lot for your time</div><div><br></div><div><div><div><div dir="ltr" class="gmail_signature"><div dir="ltr">Son Tuan Vu</div></div></div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 24, 2019 at 11:03 PM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Might be worth running under valgrind or the LLVM sanitizers? (could<br>
help diagnose what's going wrong more specifically than a segfault)<br>
<br>
On Wed, Apr 24, 2019 at 1:57 PM Son Tuan VU via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hi folks,<br>
><br>
> 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)<br>
><br>
> I've started with creating C structure for DebugInfo::DWARF::DWARFContext which contains all DWARF DIEs in the object file. For this I used<br>
> ```<br>
> DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DWARFContext, LLVMDWARFContextRef)<br>
> ```<br>
> then defined some C functions<br>
> ```<br>
> LLVMDWARFContextRef LLVMCreateDWARFContext(LLVMBinaryRef Bin) {<br>
> std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*unwrap(Bin));<br>
> return wrap(DICtx.release());<br>
> }<br>
><br>
> void LLVMPrintDWARFContext(LLVMDWARFContextRef C) {<br>
> DIDumpOptions DumpOpts;<br>
> DumpOpts.DumpType = DIDT_DebugInfo; // I only care about the .debug_info section<br>
> unwrap(C)->dump(outs(), DumpOpts);<br>
> }<br>
> ```<br>
> 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.<br>
><br>
> I tried to do this instead to see if the wrapping/unwrapping has bugs<br>
> ```<br>
> LLVMDWARFContextRef LLVMCreateDWARFContext(LLVMBinaryRef Bin) {<br>
> std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*unwrap(Bin));<br>
> LLVMDWARFContextRef C = wrap(DICtx.release());<br>
> LLVMPrintDWARFContext(C);<br>
> return C;<br>
> }<br>
> ```<br>
> and the call to LLVMPrintDWARFContext did not segfault this time.<br>
><br>
> Can anybody who knows about DWARFContext and DWARFDie tell me what I did wrong? Or is it a bug in DWARFDie::dump() method?<br>
><br>
> Thank you very much for your help,<br>
><br>
> Son Tuan Vu<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>