Just like functions can have a basename and a mangled/demangled name, variable
can too. So now the lldb_private::Variable class has support for this.
Variables now have support for having a basename ("i"), and a mangled name
("_ZN12_GLOBAL__N_11iE"), and a demangled name ("(anonymous namespace)::i").
Nowwhen searching for a variable by name, users might enter the fully qualified
name, or just the basename. So new test functions were added to the Variable
and Mangled classes as:
bool NameMatches (const ConstString &name);
bool NameMatches (const RegularExpression ®ex);
I also modified "ClangExpressionDeclMap::FindVariableInScope" to also search
for global variables that are not in the current file scope by first starting
with the current module, then moving on to all modules.
Fixed an issue in the DWARF parser that could cause a varaible to get parsed
more than once. Now, once we have parsed a VariableSP for a DIE, we cache
the result even if a variable wasn't made so we don't do any re-parsing. Some
DW_TAG_variable DIEs don't have locations, or are missing vital info that
stops a debugger from being able to display anything for it, we parse a NULL
variable shared pointer for these DIEs so we don't keep trying to reparse it.
llvm-svn: 119085
diff --git a/lldb/include/lldb/Core/Mangled.h b/lldb/include/lldb/Core/Mangled.h
index f89e4b9..f764a20 100644
--- a/lldb/include/lldb/Core/Mangled.h
+++ b/lldb/include/lldb/Core/Mangled.h
@@ -433,6 +433,26 @@
GetName (NamePreference preference = ePreferDemangled) const;
//----------------------------------------------------------------------
+ /// Check if "name" matches either the mangled or demangled name.
+ ///
+ /// @param[in] name
+ /// A name to match against both strings.
+ ///
+ /// @return
+ /// \b True if \a name matches either name, \b false otherwise.
+ //----------------------------------------------------------------------
+ bool
+ NameMatches (const ConstString &name) const
+ {
+ if (m_mangled == name)
+ return true;
+ return GetDemangledName () == name;
+ }
+
+ bool
+ NameMatches (const RegularExpression& regex) const;
+
+ //----------------------------------------------------------------------
/// Generate the tokens from the demangled name.
///
/// @param[out] tokens
diff --git a/lldb/include/lldb/Symbol/Variable.h b/lldb/include/lldb/Symbol/Variable.h
index 514e1aa..89a1bbc 100644
--- a/lldb/include/lldb/Symbol/Variable.h
+++ b/lldb/include/lldb/Symbol/Variable.h
@@ -14,9 +14,10 @@
#include "lldb/lldb-private.h"
#include "lldb/lldb-enumerations.h"
+#include "lldb/Core/Mangled.h"
+#include "lldb/Core/UserID.h"
#include "lldb/Expression/DWARFExpression.h"
#include "lldb/Symbol/Declaration.h"
-#include "lldb/Core/UserID.h"
namespace lldb_private {
@@ -26,14 +27,16 @@
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
- Variable(lldb::user_id_t uid,
- const ConstString& name, Type *type,
- lldb::ValueType scope,
- SymbolContextScope *owner_scope,
- Declaration* decl,
- const DWARFExpression& location,
- bool external,
- bool artificial);
+ Variable (lldb::user_id_t uid,
+ const char *name,
+ const char *mangled, // The mangled variable name for variables in namespaces
+ Type *type,
+ lldb::ValueType scope,
+ SymbolContextScope *owner_scope,
+ Declaration* decl,
+ const DWARFExpression& location,
+ bool external,
+ bool artificial);
virtual
~Variable();
@@ -48,11 +51,24 @@
}
const ConstString&
- GetName() const
+ GetName() const;
+
+ // Since a variable can have a basename "i" and also a mangled
+ // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name
+ // "(anonymous namespace)::i", this function will allow a generic match
+ // function that can be called by commands and expression parsers to make
+ // sure we match anything we come across.
+ bool
+ NameMatches (const ConstString &name) const
{
- return m_name;
+ if (m_name == name)
+ return true;
+ return m_mangled.NameMatches (name);
}
+ bool
+ NameMatches (const RegularExpression& regex) const;
+
Type *
GetType()
{
@@ -105,7 +121,8 @@
IsInScope (StackFrame *frame);
protected:
- ConstString m_name; // Name of the variable
+ ConstString m_name; // The basename of the variable (no namespaces)
+ Mangled m_mangled; // The mangled name of hte variable
Type *m_type; // The type pointer of the variable (int, struct, class, etc)
lldb::ValueType m_scope; // global, parameter, local
SymbolContextScope *m_owner_scope; // The symbol file scope that this variable was defined in
diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj
index ef4258c..118eae7 100644
--- a/lldb/lldb.xcodeproj/project.pbxproj
+++ b/lldb/lldb.xcodeproj/project.pbxproj
@@ -2452,6 +2452,7 @@
isa = PBXProject;
buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */;
compatibilityVersion = "Xcode 3.1";
+ developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
en,
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index 4821e7e..37cfbfa 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -727,7 +727,7 @@
ValueObject::DumpValueObject (result.GetOutputStream(),
exe_ctx.frame,
valobj_sp.get(),
- name_cstr,
+ valobj_sp->GetParent() ? name_cstr : NULL,
ptr_depth,
0,
m_options.max_depth,
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index d69753d..6a55ebc 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -13,6 +13,7 @@
#include "lldb/Core/ConstString.h"
#include "lldb/Core/Mangled.h"
+#include "lldb/Core/RegularExpression.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/Timer.h"
#include <ctype.h>
@@ -192,6 +193,19 @@
return m_demangled;
}
+
+bool
+Mangled::NameMatches (const RegularExpression& regex) const
+{
+ if (m_mangled && regex.Execute (m_mangled.AsCString()))
+ return true;
+
+ if (GetDemangledName() && regex.Execute (m_demangled.AsCString()))
+ return true;
+ return false;
+}
+
+
//----------------------------------------------------------------------
// Mangled name get accessor
//----------------------------------------------------------------------
diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp
index 0ddd9ef..7e05940 100644
--- a/lldb/source/Expression/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp
@@ -39,6 +39,7 @@
#include "lldb/Target/Target.h"
#include "llvm/Support/raw_ostream.h"
+using namespace lldb;
using namespace lldb_private;
using namespace clang;
@@ -364,8 +365,8 @@
return false;
}
- static ConstString g_this_cs ("this");
- Variable *object_ptr_var = FindVariableInScope(*exe_ctx->frame, g_this_cs, &m_object_pointer_type);
+ static ConstString g_this_const_str ("this");
+ Variable *object_ptr_var = FindVariableInScope (*exe_ctx->frame, g_this_const_str, &m_object_pointer_type);
if (!object_ptr_var)
{
@@ -681,7 +682,7 @@
if (!exe_ctx.frame || !exe_ctx.process)
return false;
- Variable *var = FindVariableInScope(*exe_ctx.frame, name, &type);
+ Variable *var = FindVariableInScope (*exe_ctx.frame, name, &type);
if (!var)
{
@@ -931,27 +932,50 @@
if (!var_list)
return NULL;
- lldb::VariableSP var = var_list->FindVariable(name);
-
- if (!var)
- return NULL;
-
- if (!type)
- return var.get();
-
- if (type->GetASTContext() == var->GetType()->GetClangAST())
+ lldb::VariableSP var_sp (var_list->FindVariable(name));
+
+ const bool append = true;
+ const uint32_t max_matches = 1;
+ if (!var_sp)
{
- if (!ClangASTContext::AreTypesSame(type->GetASTContext(), type->GetOpaqueQualType(), var->GetType()->GetClangType()))
+ // Look for globals elsewhere in the module for the frame
+ ModuleSP module_sp (m_exe_ctx.frame->GetSymbolContext(eSymbolContextModule).module_sp);
+ if (module_sp)
+ {
+ VariableList module_globals;
+ if (module_sp->FindGlobalVariables (name, append, max_matches, module_globals))
+ var_sp = module_globals.GetVariableAtIndex (0);
+ }
+ }
+
+ if (!var_sp)
+ {
+ // Look for globals elsewhere in the program (all images)
+ TargetSP target_sp (m_exe_ctx.frame->GetSymbolContext(eSymbolContextTarget).target_sp);
+ if (target_sp)
+ {
+ VariableList program_globals;
+ if (target_sp->GetImages().FindGlobalVariables (name, append, max_matches, program_globals))
+ var_sp = program_globals.GetVariableAtIndex (0);
+ }
+ }
+
+ if (var_sp && type)
+ {
+ if (type->GetASTContext() == var_sp->GetType()->GetClangAST())
+ {
+ if (!ClangASTContext::AreTypesSame(type->GetASTContext(), type->GetOpaqueQualType(), var_sp->GetType()->GetClangType()))
+ return NULL;
+ }
+ else
+ {
+ if (log)
+ log->PutCString("Skipping a candidate variable because of different AST contexts");
return NULL;
+ }
}
- else
- {
- if (log)
- log->PutCString("Skipping a candidate variable because of different AST contexts");
- return NULL;
- }
-
- return var.get();
+
+ return var_sp.get();
}
// Interface for ClangASTSource
@@ -969,9 +993,14 @@
SymbolContextList sc_list;
+ const char *name_unique_cstr = name.GetCString();
+
+ if (name_unique_cstr == NULL)
+ return;
+
// Only look for functions by name out in our symbols if the function
// doesn't start with our phony prefix of '$'
- if (name.GetCString()[0] != '$')
+ if (name_unique_cstr[0] != '$')
{
Variable *var = FindVariableInScope(*m_exe_ctx.frame, name);
@@ -1084,13 +1113,11 @@
// See information on gating of this operation next to the definition for
// m_lookedup_types.
-
- const char *name_uniq = name.GetCString();
-
- if (m_lookedup_types.find(name_uniq) == m_lookedup_types.end())
+
+ if (m_lookedup_types.find(name_unique_cstr) == m_lookedup_types.end())
{
// 1 The name is added to m_lookedup_types.
- m_lookedup_types.insert(std::pair<const char*, bool>(name_uniq, true));
+ m_lookedup_types.insert(std::pair<const char*, bool>(name_unique_cstr, true));
// 2 The type is looked up and added, potentially causing more type loookups.
lldb::TypeSP type = m_sym_ctx.FindTypeByName (name);
@@ -1104,7 +1131,7 @@
}
// 3 The name is removed from m_lookedup_types.
- m_lookedup_types.erase(name_uniq);
+ m_lookedup_types.erase(name_unique_cstr);
}
}
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
index 2784ca5..bd4e87d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -883,6 +883,14 @@
if (name && has_location && is_global_or_static_variable)
{
globals.Insert (ConstString(name), die_info);
+ // Be sure to include variables by their mangled and demangled
+ // names if they have any since a variable can have a basename
+ // "i", a mangled named "_ZN12_GLOBAL__N_11iE" and a demangled
+ // mangled name "(anonymous namespace)::i"...
+ if (mangled.GetMangledName())
+ globals.Insert (mangled.GetMangledName(), die_info);
+ if (mangled.GetDemangledName())
+ globals.Insert (mangled.GetDemangledName(), die_info);
}
break;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 1337ba6..1344213 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1776,16 +1776,16 @@
bool clear_dies = curr_cu->ExtractDIEsIfNeeded (false) > 1;
curr_cu->Index (cu_idx,
- m_function_basename_index,
- m_function_fullname_index,
- m_function_method_index,
- m_function_selector_index,
- m_objc_class_selectors_index,
- m_global_index,
- m_type_index,
- m_namespace_index,
- DebugRanges(),
- m_aranges.get());
+ m_function_basename_index,
+ m_function_fullname_index,
+ m_function_method_index,
+ m_function_selector_index,
+ m_objc_class_selectors_index,
+ m_global_index,
+ m_type_index,
+ m_namespace_index,
+ DebugRanges(),
+ m_aranges.get());
// Keep memory down by clearing DIEs if this generate function
// caused them to be parsed
@@ -3719,7 +3719,7 @@
VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, dwarf_cu->GetDIEAtIndexUnchecked(global_die_info_array[idx].die_idx), LLDB_INVALID_ADDRESS));
if (var_sp)
{
- variables->AddVariable(var_sp);
+ variables->AddVariableIfUnique (var_sp);
++vars_added;
}
}
@@ -3741,7 +3741,9 @@
)
{
- VariableSP var_sp;
+ VariableSP var_sp (m_die_to_variable_sp[die]);
+ if (var_sp)
+ return var_sp; // Already been parsed!
const dw_tag_t tag = die->Tag();
DWARFDebugInfoEntry::Attributes attributes;
@@ -3821,18 +3823,6 @@
{
assert(var_type != DIE_IS_BEING_PARSED);
- ConstString var_name;
- if (mangled)
- {
- Mangled mangled_var_name (mangled, true);
- var_name = mangled_var_name.GetDemangledName();
- }
-
- if (!var_name && name)
- {
- var_name.SetCString(name);
- }
-
ValueType scope = eValueTypeInvalid;
const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
@@ -3859,7 +3849,8 @@
assert(symbol_context_scope != NULL);
var_sp.reset (new Variable(die->GetOffset(),
- var_name,
+ name,
+ mangled,
var_type,
scope,
symbol_context_scope,
@@ -3868,9 +3859,13 @@
is_external,
is_artificial));
- m_die_to_variable_sp[die] = var_sp;
}
}
+ // Cache var_sp even if NULL (the variable was just a specification or
+ // was missing vital information to be able to be displayed in the debugger
+ // (missing location due to optimization, etc)) so we don't re-parse
+ // this DIE over and over later...
+ m_die_to_variable_sp[die] = var_sp;
return var_sp;
}
@@ -3952,7 +3947,7 @@
if (m_die_to_variable_sp[die])
{
if (cc_variable_list)
- cc_variable_list->AddVariable (m_die_to_variable_sp[die]);
+ cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
}
else
{
@@ -3964,9 +3959,9 @@
VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
if (var_sp)
{
- variables->AddVariable(var_sp);
+ variables->AddVariableIfUnique (var_sp);
if (cc_variable_list)
- cc_variable_list->AddVariable (var_sp);
+ cc_variable_list->AddVariableIfUnique (var_sp);
++vars_added;
}
}
diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index 6511c01..f264e14 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -10,6 +10,7 @@
#include "lldb/Symbol/Variable.h"
#include "lldb/Core/Stream.h"
+#include "lldb/Core/RegularExpression.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/SymbolContext.h"
@@ -26,17 +27,22 @@
//----------------------------------------------------------------------
// Variable constructor
//----------------------------------------------------------------------
-Variable::Variable(lldb::user_id_t uid,
- const ConstString& name,
- Type *type,
- ValueType scope,
- SymbolContextScope *context,
- Declaration* decl_ptr,
- const DWARFExpression& location,
- bool external,
- bool artificial) :
+Variable::Variable
+(
+ lldb::user_id_t uid,
+ const char *name,
+ const char *mangled, // The mangled variable name for variables in namespaces
+ Type *type,
+ ValueType scope,
+ SymbolContextScope *context,
+ Declaration* decl_ptr,
+ const DWARFExpression& location,
+ bool external,
+ bool artificial
+) :
UserID(uid),
m_name(name),
+ m_mangled (mangled, true),
m_type(type),
m_scope(scope),
m_owner_scope(context),
@@ -55,6 +61,22 @@
}
+const ConstString&
+Variable::GetName() const
+{
+ if (m_mangled)
+ return m_mangled.GetName();
+ return m_name;
+}
+
+bool
+Variable::NameMatches (const RegularExpression& regex) const
+{
+ if (regex.Execute (m_name.AsCString()))
+ return true;
+ return m_mangled.NameMatches (regex);
+}
+
void
Variable::Dump(Stream *s, bool show_context) const
{
diff --git a/lldb/source/Symbol/VariableList.cpp b/lldb/source/Symbol/VariableList.cpp
index 75106ff..7dd80a4 100644
--- a/lldb/source/Symbol/VariableList.cpp
+++ b/lldb/source/Symbol/VariableList.cpp
@@ -91,7 +91,7 @@
iterator pos, end = m_variables.end();
for (pos = m_variables.begin(); pos != end; ++pos)
{
- if ((*pos)->GetName() == name)
+ if ((*pos)->NameMatches(name))
{
var_sp = (*pos);
break;
@@ -107,7 +107,7 @@
iterator pos, end = m_variables.end();
for (pos = m_variables.begin(); pos != end; ++pos)
{
- if (regex.Execute ((*pos)->GetName().AsCString()))
+ if ((*pos)->NameMatches (regex))
{
// Note the total matches found
total_matches++;