[Lldb-commits] [lldb] r233336 - [DWARF] Generate qualified names of functions if linkage names are missing.

Siva Chandra sivachandra at google.com
Thu Mar 26 17:10:04 PDT 2015


Author: sivachandra
Date: Thu Mar 26 19:10:04 2015
New Revision: 233336

URL: http://llvm.org/viewvc/llvm-project?rev=233336&view=rev
Log:
[DWARF] Generate qualified names of functions if linkage names are missing.

Summary:
This is similar to the change introduced for variable DIEs in r233098. If the
linkage names of functions are missing in the DWARF, then their fully qualified
names (similar to the name that would be got by demangling their linkage name)
is generated using the decl context.

This change fixes TestNamespace when the test case is compiled with GCC, hence
it is enabled for GCC. The test and the test case are also enhanced to cover
variadic functions.

Test Plan: dotest.py -C <clang|gcc> -p TestNamespace

Reviewers: clayborg

Reviewed By: clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D8623

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/test/lang/cpp/namespace/TestNamespace.py
    lldb/trunk/test/lang/cpp/namespace/main.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=233336&r1=233335&r2=233336&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Mar 26 19:10:04 2015
@@ -1095,7 +1095,54 @@ SymbolFileDWARF::ParseCompileUnitFunctio
             Mangled func_name;
             if (mangled)
                 func_name.SetValue(ConstString(mangled), true);
-            else if (name)
+            else if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
+                     LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()) &&
+                     strcmp(name, "main") != 0)
+            {
+                // If the mangled name is not present in the DWARF, generate the demangled name
+                // using the decl context. We skip if the function is "main" as its name is
+                // never mangled.
+                bool is_static = false;
+                bool is_variadic = false;
+                unsigned type_quals = 0;
+                std::vector<ClangASTType> param_types;
+                std::vector<clang::ParmVarDecl*> param_decls;
+                const DWARFDebugInfoEntry *decl_ctx_die = NULL;
+                DWARFDeclContext decl_ctx;
+                StreamString sstr;
+
+                die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
+                sstr << decl_ctx.GetQualifiedName();
+
+                clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE(dwarf_cu,
+                                                                                           die,
+                                                                                           &decl_ctx_die);
+                ParseChildParameters(sc,
+                                     containing_decl_ctx,
+                                     dwarf_cu,
+                                     die,
+                                     true,
+                                     is_static,
+                                     is_variadic,
+                                     param_types,
+                                     param_decls,
+                                     type_quals);
+                sstr << "(";
+                for (size_t i = 0; i < param_types.size(); i++)
+                {
+                    if (i > 0)
+                        sstr << ", ";
+                    sstr << param_types[i].GetTypeName();
+                }
+                if (is_variadic)
+                    sstr << ", ...";
+                sstr << ")";
+                if (type_quals & clang::Qualifiers::Const)
+                    sstr << " const";
+
+                func_name.SetValue(ConstString(sstr.GetData()), false);
+            }
+            else
                 func_name.SetValue(ConstString(name), false);
 
             FunctionSP func_sp;

Modified: lldb/trunk/test/lang/cpp/namespace/TestNamespace.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/namespace/TestNamespace.py?rev=233336&r1=233335&r2=233336&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/namespace/TestNamespace.py (original)
+++ lldb/trunk/test/lang/cpp/namespace/TestNamespace.py Thu Mar 26 19:10:04 2015
@@ -21,7 +21,6 @@ class NamespaceTestCase(TestBase):
         self.namespace_variable_commands()
 
     # rdar://problem/8668674
-    @expectedFailureGcc # llvm.org/pr15302: lldb does not print 'anonymous namespace' when the inferior is built with GCC (4.7)
     @dwarf_test
     def test_with_dwarf_and_run_command(self):
         """Test that anonymous and named namespace variables display correctly."""
@@ -117,6 +116,9 @@ class NamespaceTestCase(TestBase):
         self.expect("p myanonfunc",
             patterns = ['\(anonymous namespace\)::myanonfunc\(int\)'])
 
+        self.expect("p variadic_sum",
+            patterns = ['\(anonymous namespace\)::variadic_sum\(int, ...\)'])
+
 if __name__ == '__main__':
     import atexit
     lldb.SBDebugger.Initialize()

Modified: lldb/trunk/test/lang/cpp/namespace/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/cpp/namespace/main.cpp?rev=233336&r1=233335&r2=233336&view=diff
==============================================================================
--- lldb/trunk/test/lang/cpp/namespace/main.cpp (original)
+++ lldb/trunk/test/lang/cpp/namespace/main.cpp Thu Mar 26 19:10:04 2015
@@ -7,6 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <cstdarg>
+
 namespace {
     typedef unsigned int my_uint_t;
     int i; // Find the line number for anonymous namespace variable i.
@@ -15,6 +17,20 @@ namespace {
     {
         return a + a;
     }
+
+    int
+    variadic_sum (int arg_count...)
+    {
+        int sum = 0;
+        va_list args;
+        va_start(args, arg_count);
+
+        for (int i = 0; i < arg_count; i++)
+            sum += va_arg(args, int);
+
+        va_end(args);
+        return sum;
+    }
 }
 
 namespace A {
@@ -67,6 +83,7 @@ int Foo::myfunc(int a)
     j = 4;
     printf("::i=%d\n", ::i);
     printf("A::B::j=%d\n", A::B::j);
+    printf("variadic_sum=%d\n", variadic_sum(3, 1, 2, 3));
     myanonfunc(3);
     return myfunc2(3) + j + i + a + 2 + anon_uint + a_uint + b_uint + y_uint; // Set break point at this line.
 }





More information about the lldb-commits mailing list