[lldb-dev] LLDB Expression Parser Name Mangling

Alex Pepper apepper at blueshiftinc.com
Mon Jun 30 14:18:46 PDT 2014


On 30/06/2014 11:44 AM, Greg Clayton wrote:
>> On Jun 30, 2014, at 10:52 AM, Alex Pepper <apepper at blueshiftinc.com> wrote:
>>
>> * I sent this earlier before I registered, sorry in advance if this shows up as a duplicate.
>>
>> I have been familiarizing myself with the expression parsing code in LLDB with the intention of finding and fixing several expression parser related bugs.
>>
>> The first issue that I have been investigating in detail is related to calling c_str() on a standard string.  The expression fails because LLDB is not able to match up the mangled function name with any names in the symbol table.  There is special handling for standard strings in IRForTarget::GetFunctionAddress to support two variants of the mangled name prefix of, _ZNKSbIc and _ZNKSs.  The _ZNKSbIc represents basic_string<char> whereas _ZNKSs represents string which is a typedef of basic_string<char>. In this case the full name in the g++ compiled dwarf symbols is _ZNKSs5c_strEv,  Clang also generates the same symbol.  The call to m_decl_map->GetFunctionAddress is failing because the mangled name that is being generated by the JIT compiled expression is actually the fully specified name, _ZNKSbIcSt17char_traits<char>St15allocator<char>E5c_strEv, which is equivalent to basic_string<char,char_traits<char>,allocator<char>>.
>> I have been walking through the expression parsing code but have not been able to locate where this name is actually generated.  I am guessing the name is generated during the ParseAST but I have not been able to track it down yet, any help would be appreciated.
> The compiler will generate this in the debug info. When we go looking for a symbol or function, the compiler will ask us where the function is, and we usually find this in the C++ standard library shared library. So you should do a:
>
> (lldb) image dump symtab
>
> This should dump all symbols from all shared libraries and look for std::basic_string somewhere in the mix and see what symbols. You _ZNKSbIcSt17char_traits<char>St15allocator<char>E5c_strEv detangles to:
>
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const
>
> on our system. I would check the symbols in your libstdc++ shared library and see what symbols are there for basic_string and see why things aren't matching up.
>
> Greg

In lldb I dumped the un-mangled symbol for:  std::string::c_str() 
const.  The address is: libstdc++.so.6[ *0x00000000000b9630*]. This 
address corresponds the the exported symbol _ZNKSs5c_strEv, that I 
dumped from libstdc++.so.6 at the same file address/value. Both the lldb 
I am debugging and the inferior a.out I am attached from lldb show 
dependencies on the same version and location of libstdc++.so.6.

I am still not clear if the mangled name, 
_ZNKSbIcSt17char_traits<char>St15allocator<char>E5c_strEv, is being 
generated from MCJIT within LLDB and where that happens in the source.  
As you described in your followup message, according to the name 
mangling compression rules I would expect this to be mangled as 
_ZNKSs5c_strEv.  On my system (Ubuntu 14.04, gcc.4.82, clang 3.5-1), the 
standalone compile of the test program mangles as _ZNKSs5c_strEv in 
dwarf symbols, but in LLDB the name extracted from the function passed 
to GetFunctionAddress() is mangled as 
_ZNKSbIcSt17char_traits<char>St15allocator<char>E5c_strEv, which is not 
compressed as I would have expected.

- Alex


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20140630/7e1c2bb1/attachment.html>


More information about the lldb-dev mailing list