Andrew Kelley via llvm-dev
2018-Aug-23 07:19 UTC
[llvm-dev] How does LLDB locate the DWARF information stored inside MACH-O .o files produced by LLVM and LLD?
When I make a simple test program and call abort() and use LLDB to debug it, it has address-to-line mapping. If I then delete the .o file and run LLDB again, it loses the address-to-line mapping. So there must be DWARF info, or otherwise address-to-line info in the .o file. I'm parsing the MACH-O executable, which has a LC_SYMTAB entry, and one of the entries is the file path of the .o file. So I can find the file that way. Then I parse the MACH-O .o file, which also has the LC_SYMTAB, as well as an LC_SEGMENT_64 and LC_DATA_IN_CODE, and then finally a LC_DYSYMTAB. But I don't see where the address-to-line information is, or any DWARF information. Where is LLDB getting this address-to-line info? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180823/a5cf277a/attachment.html>
David Blaikie via llvm-dev
2018-Aug-23 19:14 UTC
[llvm-dev] How does LLDB locate the DWARF information stored inside MACH-O .o files produced by LLVM and LLD?
You'll need to go a bit further than the load commands - I don't know much about MachO files, so I'm just reading: https://lowlevelbits.org/parsing-mach-o-files/ and https://samhuri.net/posts/2010/01/basics-of-the-mach-o-file-format - so inside the section (described by the LC_SEGMENT_64) are probably a bunch of sections, including debug info sections. Tools like llvm-objdump will show you those (llvm-objdump -h), and also tools like llvm-dwarfdump can print the contents of the debug info sections (those with names starting with "__debug") in human-readable form. On Thu, Aug 23, 2018 at 12:19 AM Andrew Kelley via llvm-dev < llvm-dev at lists.llvm.org> wrote:> When I make a simple test program and call abort() and use LLDB to debug > it, it has address-to-line mapping. If I then delete the .o file and run > LLDB again, it loses the address-to-line mapping. So there must be DWARF > info, or otherwise address-to-line info in the .o file. > > I'm parsing the MACH-O executable, which has a LC_SYMTAB entry, and one > of the entries is the file path of the .o file. So I can find the file that > way. Then I parse the MACH-O .o file, which also has the LC_SYMTAB, as well > as an LC_SEGMENT_64 and LC_DATA_IN_CODE, and then finally a LC_DYSYMTAB. > But I don't see where the address-to-line information is, or any DWARF > information. > > Where is LLDB getting this address-to-line info? > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180823/aab9f33f/attachment.html>
Andrew Kelley via llvm-dev
2018-Aug-23 19:19 UTC
[llvm-dev] How does LLDB locate the DWARF information stored inside MACH-O .o files produced by LLVM and LLD?
Thanks David. I figured it out. Here's the scoop: The executable has a LC_SYMTAB. One of those nlist_64 entries has the string set to the .o file path, and the n_type set to N_OSO. So you can go from symbol to .o file. Then you go read the .o file, and the first load command is LC_SEGMENT_64. That has some number of sections following it, among which are the DWARF sections. I had tried this, but I forgot to increment a pointer in a loop, so I thought all the sections were the same as the first one. D'oh! Regards, -Andrew On Thu, Aug 23, 2018 at 3:15 PM David Blaikie <dblaikie at gmail.com> wrote:> You'll need to go a bit further than the load commands - I don't know much > about MachO files, so I'm just reading: > https://lowlevelbits.org/parsing-mach-o-files/ and > https://samhuri.net/posts/2010/01/basics-of-the-mach-o-file-format - so > inside the section (described by the LC_SEGMENT_64) are probably a bunch of > sections, including debug info sections. Tools like llvm-objdump will show > you those (llvm-objdump -h), and also tools like llvm-dwarfdump can print > the contents of the debug info sections (those with names starting with > "__debug") in human-readable form. > > On Thu, Aug 23, 2018 at 12:19 AM Andrew Kelley via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> When I make a simple test program and call abort() and use LLDB to debug >> it, it has address-to-line mapping. If I then delete the .o file and run >> LLDB again, it loses the address-to-line mapping. So there must be DWARF >> info, or otherwise address-to-line info in the .o file. >> >> I'm parsing the MACH-O executable, which has a LC_SYMTAB entry, and one >> of the entries is the file path of the .o file. So I can find the file that >> way. Then I parse the MACH-O .o file, which also has the LC_SYMTAB, as well >> as an LC_SEGMENT_64 and LC_DATA_IN_CODE, and then finally a LC_DYSYMTAB. >> But I don't see where the address-to-line information is, or any DWARF >> information. >> >> Where is LLDB getting this address-to-line info? >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180823/c5b073a1/attachment.html>
Reasonably Related Threads
- [LLVMdev] CLang/LLVM SVN for today no longer works on OS X 10.7.4
- [LLVMdev] CLang/LLVM SVN for today no longer works on OS X 10.7.4
- [LLVMdev] CLang/LLVM SVN for today no longer works on OS X 10.7.4
- Cross-compiling asterisk-1.4 for Debian on a slug
- SourceMgr vs EXPENSIVE_CHECKS