summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2012-11-27 01:52:16 +0000
committerGreg Clayton <gclayton@apple.com>2012-11-27 01:52:16 +0000
commit3d51b9f9571d2a95ed077ac6723f713ffa8af29e (patch)
treee3322273a29bf1aa46a3abeb41fbc9bb7f30ee8c /lldb/source
parent7dc71d03b984e2cd288cb0b6c02de3fe54782a73 (diff)
downloadbcm5719-llvm-3d51b9f9571d2a95ed077ac6723f713ffa8af29e.tar.gz
bcm5719-llvm-3d51b9f9571d2a95ed077ac6723f713ffa8af29e.zip
<rdar://problem/12106825>
Allow the expression parser to see more than just data symbols. We now accept any symbol that has an address. We take precautions to only accept symbols by their mangled or demangled names only if the demangled name was not synthesized. If the demangled name is synthesized, then we now mark symbols accordingly and only compare against the mangled original name. llvm-svn: 168668
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Expression/ClangExpressionDeclMap.cpp80
-rw-r--r--lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp165
-rw-r--r--lldb/source/Symbol/Symbol.cpp6
3 files changed, 156 insertions, 95 deletions
diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp
index 4cd74a86b34..dd39fa1e35b 100644
--- a/lldb/source/Expression/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp
@@ -1838,7 +1838,7 @@ ClangExpressionDeclMap::DoMaterializeOneVariable
TypeFromUser type(expr_var->GetTypeFromUser());
VariableSP &var(expr_var->m_parser_vars->m_lldb_var);
- lldb_private::Symbol *sym(expr_var->m_parser_vars->m_lldb_sym);
+ const lldb_private::Symbol *symbol = expr_var->m_parser_vars->m_lldb_sym;
bool is_reference(expr_var->m_flags & ClangExpressionVariable::EVTypeIsReference);
@@ -1849,7 +1849,7 @@ ClangExpressionDeclMap::DoMaterializeOneVariable
location_value.reset(GetVariableValue(var,
NULL));
}
- else if (sym)
+ else if (symbol)
{
addr_t location_load_addr = GetSymbolAddress(*target, process, name, lldb::eSymbolTypeAny);
@@ -2281,25 +2281,69 @@ ClangExpressionDeclMap::FindVariableInScope
return lldb::VariableSP();
}
-Symbol *
-ClangExpressionDeclMap::FindGlobalDataSymbol
-(
- Target &target,
- const ConstString &name
-)
+const Symbol *
+ClangExpressionDeclMap::FindGlobalDataSymbol (Target &target,
+ const ConstString &name)
{
SymbolContextList sc_list;
- target.GetImages().FindSymbolsWithNameAndType(name,
- eSymbolTypeData,
- sc_list);
+ target.GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
- if (sc_list.GetSize())
+ const uint32_t matches = sc_list.GetSize();
+ for (uint32_t i=0; i<matches; ++i)
{
SymbolContext sym_ctx;
- sc_list.GetContextAtIndex(0, sym_ctx);
-
- return sym_ctx.symbol;
+ sc_list.GetContextAtIndex(i, sym_ctx);
+ if (sym_ctx.symbol)
+ {
+ const Symbol *symbol = sym_ctx.symbol;
+ const Address *sym_address = &symbol->GetAddress();
+
+ if (sym_address && sym_address->IsValid())
+ {
+ switch (symbol->GetType())
+ {
+ case eSymbolTypeData:
+ case eSymbolTypeRuntime:
+ case eSymbolTypeAbsolute:
+ case eSymbolTypeObjCClass:
+ case eSymbolTypeObjCMetaClass:
+ case eSymbolTypeObjCIVar:
+ if (symbol->GetDemangledNameIsSynthesized())
+ {
+ // If the demangled name was synthesized, then don't use it
+ // for expressions. Only let the symbol match if the mangled
+ // named matches for these symbols.
+ if (symbol->GetMangled().GetMangledName() != name)
+ break;
+ }
+ return symbol;
+
+ case eSymbolTypeCode: // We already lookup functions elsewhere
+ case eSymbolTypeVariable:
+ case eSymbolTypeLocal:
+ case eSymbolTypeParam:
+ case eSymbolTypeTrampoline:
+ case eSymbolTypeInvalid:
+ case eSymbolTypeException:
+ case eSymbolTypeSourceFile:
+ case eSymbolTypeHeaderFile:
+ case eSymbolTypeObjectFile:
+ case eSymbolTypeCommonBlock:
+ case eSymbolTypeBlock:
+ case eSymbolTypeVariableType:
+ case eSymbolTypeLineEntry:
+ case eSymbolTypeLineHeader:
+ case eSymbolTypeScopeBegin:
+ case eSymbolTypeScopeEnd:
+ case eSymbolTypeAdditional:
+ case eSymbolTypeCompiler:
+ case eSymbolTypeInstrumentation:
+ case eSymbolTypeUndefined:
+ break;
+ }
+ }
+ }
}
return NULL;
@@ -2878,7 +2922,7 @@ ClangExpressionDeclMap::FindExternalVisibleDecls (NameSearchContext &context,
// We couldn't find a non-symbol variable for this. Now we'll hunt for a generic
// data symbol, and -- if it is found -- treat it as a variable.
- Symbol *data_symbol = FindGlobalDataSymbol(*target, name);
+ const Symbol *data_symbol = FindGlobalDataSymbol(*target, name);
if (data_symbol)
{
@@ -3144,7 +3188,7 @@ ClangExpressionDeclMap::AddOneVariable(NameSearchContext &context,
void
ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
- Symbol &symbol,
+ const Symbol &symbol,
unsigned int current_id)
{
assert(m_parser_vars.get());
@@ -3177,7 +3221,7 @@ ClangExpressionDeclMap::AddOneGenericVariable(NameSearchContext &context,
std::auto_ptr<Value> symbol_location(new Value);
- Address &symbol_address = symbol.GetAddress();
+ const Address &symbol_address = symbol.GetAddress();
lldb::addr_t symbol_load_addr = symbol_address.GetLoadAddress(target);
symbol_location->SetContext(Value::eContextTypeClangType, user_type.GetOpaqueQualType());
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 3e6cd1efbb8..4d6d00755a5 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1641,6 +1641,7 @@ ObjectFileMachO::ParseSymtab (bool minimize)
uint32_t symbol_byte_size = 0;
bool add_nlist = true;
bool is_debug = ((nlist.n_type & NlistMaskStab) != 0);
+ bool demangled_is_synthesized = false;
assert (sym_idx < num_syms);
@@ -2035,68 +2036,67 @@ ObjectFileMachO::ParseSymtab (bool minimize)
break;
case NListTypeSection: // N_SECT
- {
- symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
-
- if (symbol_section == NULL)
{
- // TODO: warn about this?
- add_nlist = false;
- break;
- }
+ symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
- if (TEXT_eh_frame_sectID == nlist.n_sect)
- {
- type = eSymbolTypeException;
- }
- else
- {
- uint32_t section_type = symbol_section->Get() & SectionFlagMaskSectionType;
-
- switch (section_type)
+ if (symbol_section == NULL)
{
- case SectionTypeRegular: break; // regular section
- //case SectionTypeZeroFill: type = eSymbolTypeData; break; // zero fill on demand section
- case SectionTypeCStringLiterals: type = eSymbolTypeData; break; // section with only literal C strings
- case SectionType4ByteLiterals: type = eSymbolTypeData; break; // section with only 4 byte literals
- case SectionType8ByteLiterals: type = eSymbolTypeData; break; // section with only 8 byte literals
- case SectionTypeLiteralPointers: type = eSymbolTypeTrampoline; break; // section with only pointers to literals
- case SectionTypeNonLazySymbolPointers: type = eSymbolTypeTrampoline; break; // section with only non-lazy symbol pointers
- case SectionTypeLazySymbolPointers: type = eSymbolTypeTrampoline; break; // section with only lazy symbol pointers
- case SectionTypeSymbolStubs: type = eSymbolTypeTrampoline; break; // section with only symbol stubs, byte size of stub in the reserved2 field
- case SectionTypeModuleInitFunctionPointers: type = eSymbolTypeCode; break; // section with only function pointers for initialization
- case SectionTypeModuleTermFunctionPointers: type = eSymbolTypeCode; break; // section with only function pointers for termination
- //case SectionTypeCoalesced: type = eSymbolType; break; // section contains symbols that are to be coalesced
- //case SectionTypeZeroFillLarge: type = eSymbolTypeData; break; // zero fill on demand section (that can be larger than 4 gigabytes)
- case SectionTypeInterposing: type = eSymbolTypeTrampoline; break; // section with only pairs of function pointers for interposing
- case SectionType16ByteLiterals: type = eSymbolTypeData; break; // section with only 16 byte literals
- case SectionTypeDTraceObjectFormat: type = eSymbolTypeInstrumentation; break;
- case SectionTypeLazyDylibSymbolPointers: type = eSymbolTypeTrampoline; break;
- default: break;
+ // TODO: warn about this?
+ add_nlist = false;
+ break;
}
-
- if (type == eSymbolTypeInvalid)
+
+ if (TEXT_eh_frame_sectID == nlist.n_sect)
+ {
+ type = eSymbolTypeException;
+ }
+ else
{
- const char *symbol_sect_name = symbol_section->GetName().AsCString();
- if (symbol_section->IsDescendant (text_section_sp.get()))
+ uint32_t section_type = symbol_section->Get() & SectionFlagMaskSectionType;
+
+ switch (section_type)
{
- if (symbol_section->IsClear(SectionAttrUserPureInstructions |
- SectionAttrUserSelfModifyingCode |
- SectionAttrSytemSomeInstructions))
- type = eSymbolTypeData;
- else
- type = eSymbolTypeCode;
+ case SectionTypeRegular: break; // regular section
+ //case SectionTypeZeroFill: type = eSymbolTypeData; break; // zero fill on demand section
+ case SectionTypeCStringLiterals: type = eSymbolTypeData; break; // section with only literal C strings
+ case SectionType4ByteLiterals: type = eSymbolTypeData; break; // section with only 4 byte literals
+ case SectionType8ByteLiterals: type = eSymbolTypeData; break; // section with only 8 byte literals
+ case SectionTypeLiteralPointers: type = eSymbolTypeTrampoline; break; // section with only pointers to literals
+ case SectionTypeNonLazySymbolPointers: type = eSymbolTypeTrampoline; break; // section with only non-lazy symbol pointers
+ case SectionTypeLazySymbolPointers: type = eSymbolTypeTrampoline; break; // section with only lazy symbol pointers
+ case SectionTypeSymbolStubs: type = eSymbolTypeTrampoline; break; // section with only symbol stubs, byte size of stub in the reserved2 field
+ case SectionTypeModuleInitFunctionPointers: type = eSymbolTypeCode; break; // section with only function pointers for initialization
+ case SectionTypeModuleTermFunctionPointers: type = eSymbolTypeCode; break; // section with only function pointers for termination
+ //case SectionTypeCoalesced: type = eSymbolType; break; // section contains symbols that are to be coalesced
+ //case SectionTypeZeroFillLarge: type = eSymbolTypeData; break; // zero fill on demand section (that can be larger than 4 gigabytes)
+ case SectionTypeInterposing: type = eSymbolTypeTrampoline; break; // section with only pairs of function pointers for interposing
+ case SectionType16ByteLiterals: type = eSymbolTypeData; break; // section with only 16 byte literals
+ case SectionTypeDTraceObjectFormat: type = eSymbolTypeInstrumentation; break;
+ case SectionTypeLazyDylibSymbolPointers: type = eSymbolTypeTrampoline; break;
+ default: break;
}
- else
- if (symbol_section->IsDescendant(data_section_sp.get()))
+
+ if (type == eSymbolTypeInvalid)
+ {
+ const char *symbol_sect_name = symbol_section->GetName().AsCString();
+ if (symbol_section->IsDescendant (text_section_sp.get()))
+ {
+ if (symbol_section->IsClear(SectionAttrUserPureInstructions |
+ SectionAttrUserSelfModifyingCode |
+ SectionAttrSytemSomeInstructions))
+ type = eSymbolTypeData;
+ else
+ type = eSymbolTypeCode;
+ }
+ else if (symbol_section->IsDescendant(data_section_sp.get()))
{
if (symbol_sect_name && ::strstr (symbol_sect_name, "__objc") == symbol_sect_name)
{
type = eSymbolTypeRuntime;
- if (symbol_name &&
- symbol_name[0] == '_' &&
- symbol_name[1] == 'O' &&
+ if (symbol_name &&
+ symbol_name[0] == '_' &&
+ symbol_name[1] == 'O' &&
symbol_name[2] == 'B')
{
llvm::StringRef symbol_name_ref(symbol_name);
@@ -2108,55 +2108,56 @@ ObjectFileMachO::ParseSymtab (bool minimize)
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_class.size();
type = eSymbolTypeObjCClass;
+ demangled_is_synthesized = true;
}
else if (symbol_name_ref.startswith(g_objc_v2_prefix_metaclass))
{
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
type = eSymbolTypeObjCMetaClass;
+ demangled_is_synthesized = true;
}
else if (symbol_name_ref.startswith(g_objc_v2_prefix_ivar))
{
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
type = eSymbolTypeObjCIVar;
+ demangled_is_synthesized = true;
}
}
}
- else
- if (symbol_sect_name && ::strstr (symbol_sect_name, "__gcc_except_tab") == symbol_sect_name)
- {
- type = eSymbolTypeException;
- }
- else
- {
- type = eSymbolTypeData;
- }
- }
- else
- if (symbol_sect_name && ::strstr (symbol_sect_name, "__IMPORT") == symbol_sect_name)
+ else if (symbol_sect_name && ::strstr (symbol_sect_name, "__gcc_except_tab") == symbol_sect_name)
{
- type = eSymbolTypeTrampoline;
+ type = eSymbolTypeException;
}
else
- if (symbol_section->IsDescendant(objc_section_sp.get()))
+ {
+ type = eSymbolTypeData;
+ }
+ }
+ else if (symbol_sect_name && ::strstr (symbol_sect_name, "__IMPORT") == symbol_sect_name)
+ {
+ type = eSymbolTypeTrampoline;
+ }
+ else if (symbol_section->IsDescendant(objc_section_sp.get()))
+ {
+ type = eSymbolTypeRuntime;
+ if (symbol_name && symbol_name[0] == '.')
+ {
+ llvm::StringRef symbol_name_ref(symbol_name);
+ static const llvm::StringRef g_objc_v1_prefix_class (".objc_class_name_");
+ if (symbol_name_ref.startswith(g_objc_v1_prefix_class))
{
- type = eSymbolTypeRuntime;
- if (symbol_name && symbol_name[0] == '.')
- {
- llvm::StringRef symbol_name_ref(symbol_name);
- static const llvm::StringRef g_objc_v1_prefix_class (".objc_class_name_");
- if (symbol_name_ref.startswith(g_objc_v1_prefix_class))
- {
- symbol_name_non_abi_mangled = symbol_name;
- symbol_name = symbol_name + g_objc_v1_prefix_class.size();
- type = eSymbolTypeObjCClass;
- }
- }
+ symbol_name_non_abi_mangled = symbol_name;
+ symbol_name = symbol_name + g_objc_v1_prefix_class.size();
+ type = eSymbolTypeObjCClass;
+ demangled_is_synthesized = true;
}
+ }
+ }
+ }
}
}
- }
break;
}
}
@@ -2292,6 +2293,8 @@ ObjectFileMachO::ParseSymtab (bool minimize)
if (symbol_byte_size > 0)
sym[sym_idx].SetByteSize(symbol_byte_size);
+ if (demangled_is_synthesized)
+ sym[sym_idx].SetDemangledNameIsSynthesized(true);
++sym_idx;
}
else
@@ -2382,6 +2385,7 @@ ObjectFileMachO::ParseSymtab (bool minimize)
uint32_t symbol_byte_size = 0;
bool add_nlist = true;
bool is_debug = ((nlist.n_type & NlistMaskStab) != 0);
+ bool demangled_is_synthesized = false;
assert (sym_idx < num_syms);
@@ -2850,18 +2854,21 @@ ObjectFileMachO::ParseSymtab (bool minimize)
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_class.size();
type = eSymbolTypeObjCClass;
+ demangled_is_synthesized = true;
}
else if (symbol_name_ref.startswith(g_objc_v2_prefix_metaclass))
{
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
type = eSymbolTypeObjCMetaClass;
+ demangled_is_synthesized = true;
}
else if (symbol_name_ref.startswith(g_objc_v2_prefix_ivar))
{
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
type = eSymbolTypeObjCIVar;
+ demangled_is_synthesized = true;
}
}
}
@@ -2893,6 +2900,7 @@ ObjectFileMachO::ParseSymtab (bool minimize)
symbol_name_non_abi_mangled = symbol_name;
symbol_name = symbol_name + g_objc_v1_prefix_class.size();
type = eSymbolTypeObjCClass;
+ demangled_is_synthesized = true;
}
}
}
@@ -3029,6 +3037,9 @@ ObjectFileMachO::ParseSymtab (bool minimize)
if (symbol_byte_size > 0)
sym[sym_idx].SetByteSize(symbol_byte_size);
+ if (demangled_is_synthesized)
+ sym[sym_idx].SetDemangledNameIsSynthesized(true);
+
++sym_idx;
}
else
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index 3a8a333cb75..8b2bd20aaf6 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -33,6 +33,7 @@ Symbol::Symbol() :
m_size_is_sibling (false),
m_size_is_synthesized (false),
m_calculated_size (false),
+ m_demangled_is_synthesized (false),
m_type (eSymbolTypeInvalid),
m_flags (),
m_addr_range ()
@@ -65,6 +66,7 @@ Symbol::Symbol
m_size_is_sibling (false),
m_size_is_synthesized (false),
m_calculated_size (size > 0),
+ m_demangled_is_synthesized (false),
m_type (type),
m_flags (flags),
m_addr_range (section_sp, offset, size)
@@ -95,6 +97,7 @@ Symbol::Symbol
m_size_is_sibling (false),
m_size_is_synthesized (false),
m_calculated_size (range.GetByteSize() > 0),
+ m_demangled_is_synthesized (false),
m_type (type),
m_flags (flags),
m_addr_range (range)
@@ -113,6 +116,7 @@ Symbol::Symbol(const Symbol& rhs):
m_size_is_sibling (rhs.m_size_is_sibling),
m_size_is_synthesized (false),
m_calculated_size (rhs.m_calculated_size),
+ m_demangled_is_synthesized (rhs.m_demangled_is_synthesized),
m_type (rhs.m_type),
m_flags (rhs.m_flags),
m_addr_range (rhs.m_addr_range)
@@ -135,6 +139,7 @@ Symbol::operator= (const Symbol& rhs)
m_size_is_sibling = rhs.m_size_is_sibling;
m_size_is_synthesized = rhs.m_size_is_sibling;
m_calculated_size = rhs.m_calculated_size;
+ m_demangled_is_synthesized = rhs.m_demangled_is_synthesized;
m_type = rhs.m_type;
m_flags = rhs.m_flags;
m_addr_range = rhs.m_addr_range;
@@ -155,6 +160,7 @@ Symbol::Clear()
m_size_is_sibling = false;
m_size_is_synthesized = false;
m_calculated_size = false;
+ m_demangled_is_synthesized = false;
m_type = eSymbolTypeInvalid;
m_flags = 0;
m_addr_range.Clear();
OpenPOWER on IntegriCloud