[lldb-dev] STABS

Jim Ingham via lldb-dev lldb-dev at lists.llvm.org
Fri Jul 26 11:43:20 PDT 2019


Amplifying Fred's comments:

Most of the code in ParseSymtab is parsing the nlist records in the binary.  Only a tiny subset of those nlist records are "stabs".  Most are just the format by which MachO expresses its symbol table.  So all that needs to be there.

Over the past couple of years, the linker on MachO has switched from using nlist records to using the dyld trie data structure.  You can also see evidence of that in ParseSymtab.  At this point the nlist records are there because there are lots of analysis tools that haven't been updated to support the new dyld trie.  At some point, everything will be updated and the linker will switch over to only emitting the dyld trie, and not emitting the symbol table in nlist form.  When that is done and we convince ourselves we no longer need to support older binaries that still use nlist records, we can then remove the nlist parsing code.  But until then, this is how the symbol table is expressed.  The symbol parsing is actually the majority of the code in ParseSymtab.

Not all nlist records are stabs.  Stabs, per se, are the nlist records that have the is_debug flag set.  As Fred said, MachO uses the debug nlist records as the format for it's "debug map" which tells us where symbols from .o files ended up in the final linked product.  This is definitely NOT a stabs parser, we only support a tiny subset of the full stabs debug format, just what is needed for the debug map.  We've talked on and off about coming up with a dedicated format for the debug map, but so far there's been no strong motivation to actually do that, so we've continued to borrow a subset of stabs for the purpose.  

There is one bit of ugliness, which is that the debug map parsing is essentially duplicated.  Look for: "if (is_debug)" and you will see two very similar blocks (2860 and 3826 in the current sources.)  Jason will remember the details better, but there was something gnarly about how libraries in the "shared cache" on Darwin systems work that made it awkward to use the same code for it and normal libraries.  Some ambitious person could probably go through and unify the two sections, but this is code that doesn't see much active development, it pretty much does what's needed, so it's not clear what the benefit would be at this point.

 Jim


                    
> On Jul 26, 2019, at 9:13 AM, Frédéric Riss via lldb-dev <lldb-dev at lists.llvm.org> wrote:
> 
> 
> 
>> On Jul 26, 2019, at 4:42 AM, Pavel Labath via lldb-dev <lldb-dev at lists.llvm.org> wrote:
>> 
>> Hello everyone,
>> 
>> I recently found myself looking at ObjectFileMachO.cpp. I noticed that nearly half of that file (2700 LOC) is taken up by the ParseSymtab function, and that maybe one third of that is taken up by what appears to be STABS parsing code.
>> 
>> Is anyone still using STABS debug info? If not, can we remove it?
> 
> STABS nlist entries are the way the linker leaves breadcrumbs to the debugger to find the objectifies containing debug info. I haven’t checked whether the code you see is this one, but it seems likely.
> 
> Fred
> 
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev



More information about the lldb-dev mailing list