[Lldb-commits] [lldb] r233098 - [DWARF] If linkages names are missing, use decl context to get qualified names.
Siva Chandra
sivachandra at google.com
Tue Mar 24 11:32:28 PDT 2015
Author: sivachandra
Date: Tue Mar 24 13:32:27 2015
New Revision: 233098
URL: http://llvm.org/viewvc/llvm-project?rev=233098&view=rev
Log:
[DWARF] If linkages names are missing, use decl context to get qualified names.
Summary:
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.
Test Plan: dotest.py -C gcc -p TestNamespace
Reviewers: clayborg
Reviewed By: clayborg
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D8569
Modified:
lldb/trunk/include/lldb/Symbol/Variable.h
lldb/trunk/include/lldb/Target/LanguageRuntime.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/trunk/source/Symbol/Variable.cpp
lldb/trunk/source/Target/LanguageRuntime.cpp
Modified: lldb/trunk/include/lldb/Symbol/Variable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Variable.h?rev=233098&r1=233097&r2=233098&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Variable.h (original)
+++ lldb/trunk/include/lldb/Symbol/Variable.h Tue Mar 24 13:32:27 2015
@@ -29,7 +29,7 @@ public:
//------------------------------------------------------------------
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,
Modified: lldb/trunk/include/lldb/Target/LanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/LanguageRuntime.h?rev=233098&r1=233097&r2=233098&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/LanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/LanguageRuntime.h Tue Mar 24 13:32:27 2015
@@ -90,6 +90,9 @@ public:
static const char *
GetNameForLanguageType (lldb::LanguageType language);
+
+ static bool
+ LanguageIsCPlusPlus (lldb::LanguageType language);
Process *
GetProcess()
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=233098&r1=233097&r2=233098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Tue Mar 24 13:32:27 2015
@@ -51,6 +51,7 @@ DWARFCompileUnit::DWARFCompileUnit(Symbo
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 @@ DWARFCompileUnit::Clear()
m_func_aranges_ap.reset();
m_user_data = NULL;
m_producer = eProducerInvalid;
+ m_language_type = eLanguageTypeUnknown;
m_is_dwarf64 = false;
}
@@ -1042,6 +1044,19 @@ DWARFCompileUnit::GetProducerVersionUpda
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
{
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h?rev=233098&r1=233097&r2=233098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h Tue Mar 24 13:32:27 2015
@@ -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 @@ public:
uint32_t
GetProducerVersionUpdate();
+ lldb::LanguageType
+ GetLanguageType();
+
bool
IsDWARF64() const;
@@ -204,6 +208,7 @@ protected:
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
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h?rev=233098&r1=233097&r2=233098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h Tue Mar 24 13:32:27 2015
@@ -100,6 +100,14 @@ public:
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;
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=233098&r1=233097&r2=233098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Mar 24 13:32:27 2015
@@ -7396,6 +7396,24 @@ SymbolFileDWARF::ParseVariableDIE
dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
SymbolContextScope * symbol_context_scope = NULL;
+ if (!mangled)
+ {
+ // 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.
+ if (die->GetParent()->Tag() == DW_TAG_compile_unit &&
+ LanguageRuntime::LanguageIsCPlusPlus(dwarf_cu->GetLanguageType()))
+ {
+ 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
Modified: lldb/trunk/source/Symbol/Variable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Variable.cpp?rev=233098&r1=233097&r2=233098&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Variable.cpp (original)
+++ lldb/trunk/source/Symbol/Variable.cpp Tue Mar 24 13:32:27 2015
@@ -36,7 +36,7 @@ Variable::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,
ValueType scope,
SymbolContextScope *context,
@@ -47,7 +47,7 @@ Variable::Variable
) :
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 @@ Variable::~Variable()
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;
}
Modified: lldb/trunk/source/Target/LanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/LanguageRuntime.cpp?rev=233098&r1=233097&r2=233098&view=diff
==============================================================================
--- lldb/trunk/source/Target/LanguageRuntime.cpp (original)
+++ lldb/trunk/source/Target/LanguageRuntime.cpp Tue Mar 24 13:32:27 2015
@@ -367,6 +367,21 @@ LanguageRuntime::GetNameForLanguageType
return language_names[eLanguageTypeUnknown].name;
}
+bool
+LanguageRuntime::LanguageIsCPlusPlus (LanguageType language)
+{
+ switch (language)
+ {
+ case eLanguageTypeC_plus_plus:
+ case eLanguageTypeC_plus_plus_03:
+ case eLanguageTypeC_plus_plus_11:
+ case eLanguageTypeC_plus_plus_14:
+ return true;
+ default:
+ return false;
+ }
+}
+
lldb::SearchFilterSP
LanguageRuntime::CreateExceptionSearchFilter ()
{
More information about the lldb-commits
mailing list