[Lldb-commits] [PATCH] D10744: Fix demangling of names if required by language

Dawn Perchik dawn+llvm at burble.org
Tue Jul 7 18:07:56 PDT 2015


Thank you very much for your reply.

Consider the following.
Suppose we have the following source written in Delphi that we want to debug (translated to C++ here for the purposes of explaination):

  #include <stdio.h>
  namespace ns {
      int func(int i) {
          return ++i;
      }
  }
  int main() {
      int y;
      y = ns::func(x);
      printf("y=%d\n", y);
      return 0;
  }

In lldb, set a breakpoint at program load (before main) via 'b func'.
We first try to get the symbol as a linker symbol; the lldb calls look something like (comments added with #):

  BreakpointResolverName::SearchCallback
      ->Module::FindFunctions
      ->SymbolVendor::GetSymtab
      ->ObjectFileMachO::ParseSymtab
          # Reading thru linker symbols, cu-lang unknown.
      ->Mangled::GetDemangledName
          # This stores the demangled counterpart of '__ZN2ns4funcEi' in
          # the string pool as 'ns::func' because the language is unknown
          # and defaults to C++ syntax due to the Itanium mangling scheme.
  # The match fails.
  # Lldb continues the search and tries to match using the unqualified
  # name, at which time the DWARF for the CU is read; the lldb calls look
  # something like:
  BreakpointResolverName::SearchCallback
      ->Module::FindFunctions
          # name_type_mask=56
      ->SymbolFileDWARF::ResolveFunction
      ->SymbolFileDWARF::ParseCompileUnit
          # DWARF for CU is read and language is now known.
  # After reading the DWARF, the match is checked against the demangled
  # name; the lldb calls look something like:
  BreakpointResolverName::SearchCallback
      ->Module::FindFunctions
      ->Symtab::FindAllSymbolsWithNameAndType
      ->Mangled::GetDemangledName
          # This returns the previously saved counterpart from the string
          # pool 'ns::func' which fails to match since '::' is not
          # recognized as a namespace separator in Delphi.

This patch forces the demangling to be fixed up to 'ns.func' once the language for the CU is known (when the CU's DWARF is parsed), and the match in FindAllSymbolsWithNameAndType can then succeed.  Since lldb demangles the name before the language is known, there is simply no way around having to replace the demangled name in the string pool.

BTW, I have implemented your suggested changes to the DWARF reader - thank you for those.


================
Comment at: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp:883
@@ -882,2 +882,3 @@
                     {
+                        LanguageType cu_language = LanguageTypeFromDWARF(die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_language, 0));
                         Mangled mangled (ConstString(mangled_cstr), true);
----------------
dawn wrote:
> clayborg wrote:
> > You are accidentally taking the current DIE and thinking it is the compile unit DIE? This is wrong. You should calculate it once at the top using:
> > 
> > ```
> >     const LanguageType cu_language = GetLanguageType();
> > ```
> > Then use that everywhere. So remove this line of code.
> Thanks for this.  I didn't think GetLanguageType would work for some reason but it's been a while since I worked on this patch - need to have another look.
This change was made, tested, and will be in the final patch - thank you.

================
Comment at: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp:906
@@ -904,2 +905,3 @@
                     {
+                        LanguageType cu_language = LanguageTypeFromDWARF(die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_language, 0));
                         Mangled mangled (ConstString(mangled_cstr), true);
----------------
dawn wrote:
> clayborg wrote:
> > Remove this and use the one that is calculated once at the top.
> Thanks - will do.
This change was made, tested, and will be in the final patch - thank you.

================
Comment at: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp:954
@@ -951,2 +953,3 @@
                 {
+                    LanguageType cu_language = LanguageTypeFromDWARF(die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_language, 0));
                     Mangled mangled (ConstString(mangled_cstr), true);
----------------
dawn wrote:
> clayborg wrote:
> > Remove this and use the one that is calculated once at the top.
> Thanks - will do.
This change was made, tested, and will be in the final patch - thank you.


Repository:
  rL LLVM

http://reviews.llvm.org/D10744







More information about the lldb-commits mailing list