Hi clayborg,

This commit adds this alternate route only when parsing variable dies
corresponding to global or static variables. The motivation for this is that GCC
does not emit linkage names for functions and variables declared/defined in
anonymous namespaces. Having this alternate route fixes one part of
TestNamespace which fails when the test case is compiled with GCC.

An alternate route to get fully qualified names of functions whose linkage names
are missing will be added with a followup change. With that, the other failing
part of TestNamespace will also be fixed.

http://reviews.llvm.org/D8569

Files:
  include/lldb/Symbol/Variable.h
  source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
  source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
  source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Symbol/Variable.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: include/lldb/Symbol/Variable.h
===================================================================
--- include/lldb/Symbol/Variable.h
+++ include/lldb/Symbol/Variable.h
@@ -29,7 +29,7 @@
     //------------------------------------------------------------------
     Variable (lldb::user_id_t uid,
               const char *name, 
-              const char *mangled,   // The mangled variable name for variables in namespaces
+              const char *mangled,  // The mangled or fully qualified name of the variable.
               const lldb::SymbolFileTypeSP &symfile_type_sp,
               lldb::ValueType scope,
               SymbolContextScope *owner_scope,
Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -51,6 +51,7 @@
     m_producer_version_major (0),
     m_producer_version_minor (0),
     m_producer_version_update (0),
+    m_language_type (eLanguageTypeUnknown),
     m_is_dwarf64    (false)
 {
 }
@@ -68,6 +69,7 @@
     m_func_aranges_ap.reset();
     m_user_data     = NULL;
     m_producer      = eProducerInvalid;
+    m_language_type = eLanguageTypeUnknown;
     m_is_dwarf64    = false;
 }
 
@@ -1042,6 +1044,19 @@
     return m_producer_version_update;
 }
 
+LanguageType
+DWARFCompileUnit::GetLanguageType()
+{
+    if (m_language_type != eLanguageTypeUnknown)
+        return m_language_type;
+
+    const DWARFDebugInfoEntry *die = GetCompileUnitDIEOnly();
+    if (die)
+        m_language_type = static_cast<LanguageType>(
+            die->GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_language, eLanguageTypeUnknown));
+    return m_language_type;
+}
+
 bool
 DWARFCompileUnit::IsDWARF64() const
 {
Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
@@ -10,6 +10,7 @@
 #ifndef SymbolFileDWARF_DWARFCompileUnit_h_
 #define SymbolFileDWARF_DWARFCompileUnit_h_
 
+#include "lldb/lldb-enumerations.h"
 #include "DWARFDebugInfoEntry.h"
 #include "SymbolFileDWARF.h"
 
@@ -186,6 +187,9 @@
     uint32_t
     GetProducerVersionUpdate();
 
+    lldb::LanguageType
+    GetLanguageType();
+
     bool
     IsDWARF64() const;
 
@@ -204,6 +208,7 @@
     uint32_t            m_producer_version_major;
     uint32_t            m_producer_version_minor;
     uint32_t            m_producer_version_update;
+    lldb::LanguageType  m_language_type;
     bool                m_is_dwarf64;
     
     void
Index: source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
+++ source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
@@ -100,6 +100,14 @@
     const char *
     GetQualifiedName () const;
 
+    // Same as GetQaulifiedName, but the life time of the returned string will
+    // be that of the LLDB session.
+    lldb_private::ConstString
+    GetQualifiedNameAsConstString () const
+    {
+        return lldb_private::ConstString (GetQualifiedName ());
+    }
+
 protected:
     typedef std::vector<Entry> collection;
     collection m_entries;
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -7402,6 +7402,26 @@
             dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
             SymbolContextScope * symbol_context_scope = NULL;
 
+            if (!mangled)
+            {
+                std::string lang_name(LanguageRuntime::GetNameForLanguageType(dwarf_cu->GetLanguageType()));
+
+                // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
+                // generate fully qualified names of global variables with commands like "frame var j".
+                // For example, if j were an int variable holding a value 4 and declared in a namespace
+                // B which in turn is contained in a namespace A, the command "frame var j" returns
+                // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
+                // to generate a fully qualified name from the declaration context.
+                dw_tag_t imm_parent_tag = die->GetParent()->Tag();
+                if (imm_parent_tag == DW_TAG_compile_unit && lang_name.find("c++") == 0)
+                {
+                    DWARFDeclContext decl_ctx;
+
+                    die->GetDWARFDeclContext(this, dwarf_cu, decl_ctx);
+                    mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
+                }
+            }
+
             // DWARF doesn't specify if a DW_TAG_variable is a local, global
             // or static variable, so we have to do a little digging by
             // looking at the location of a variable to see if it contains
Index: source/Symbol/Variable.cpp
===================================================================
--- source/Symbol/Variable.cpp
+++ source/Symbol/Variable.cpp
@@ -36,7 +36,7 @@
 (
     lldb::user_id_t uid,
     const char *name, 
-    const char *mangled,   // The mangled variable name for variables in namespaces
+    const char *mangled,  // The mangled or fully qualified name of the variable.
     const lldb::SymbolFileTypeSP &symfile_type_sp,
     ValueType scope,
     SymbolContextScope *context,
@@ -47,7 +47,7 @@
 ) :
     UserID(uid),
     m_name(name),
-    m_mangled (ConstString(mangled), true),
+    m_mangled (ConstString(mangled)),
     m_symfile_type_sp(symfile_type_sp),
     m_scope(scope),
     m_owner_scope(context),
@@ -69,8 +69,9 @@
 const ConstString&
 Variable::GetName() const
 {
-    if (m_mangled)
-        return m_mangled.GetName();
+    const ConstString &name = m_mangled.GetName();
+    if (name)
+        return name;
     return m_name;
 }
 
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to