<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
This commit is contained in:
Greg Clayton 2012-11-27 01:52:16 +00:00
parent 7dc71d03b9
commit 3d51b9f957
6 changed files with 172 additions and 99 deletions

View File

@ -840,7 +840,7 @@ private:
/// @return
/// The LLDB Symbol found, or NULL if none was found.
//---------------------------------------------------------
Symbol *
const Symbol *
FindGlobalDataSymbol (Target &target,
const ConstString &name);
@ -958,7 +958,7 @@ private:
//------------------------------------------------------------------
void
AddOneGenericVariable (NameSearchContext &context,
Symbol &symbol,
const Symbol &symbol,
unsigned int current_id);
//------------------------------------------------------------------

View File

@ -108,7 +108,7 @@ public:
llvm::Value *m_llvm_value; ///< The IR value corresponding to this variable; usually a GlobalValue
lldb_private::Value *m_lldb_value; ///< The value found in LLDB for this variable
lldb::VariableSP m_lldb_var; ///< The original variable for this variable
lldb_private::Symbol *m_lldb_sym; ///< The original symbol for this variable, if it was a symbol
const lldb_private::Symbol *m_lldb_sym; ///< The original symbol for this variable, if it was a symbol
private:
DISALLOW_COPY_AND_ASSIGN (ParserVars);

View File

@ -250,6 +250,17 @@ public:
uint32_t
GetPrologueByteSize ();
bool
GetDemangledNameIsSynthesized() const
{
return m_demangled_is_synthesized;
}
void
SetDemangledNameIsSynthesized(bool b)
{
m_demangled_is_synthesized = b;
}
//------------------------------------------------------------------
/// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
///
@ -284,6 +295,7 @@ protected:
m_size_is_sibling:1, // m_size contains the index of this symbol's sibling
m_size_is_synthesized:1,// non-zero if this symbol's size was calculated using a delta between this symbol and the next
m_calculated_size:1,
m_demangled_is_synthesized:1, // The demangled name was created should not be used for expressions or other lookups
m_type:8;
uint32_t m_flags; // A copy of the flags from the original symbol table, the ObjectFile plug-in can interpret these
AddressRange m_addr_range; // Contains the value, or the section offset address when the value is an address in a section, and the size (if any)

View File

@ -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());

View File

@ -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);
{
symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
if (symbol_section == NULL)
{
// TODO: warn about this?
add_nlist = false;
break;
}
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)
{
const char *symbol_sect_name = symbol_section->GetName().AsCString();
if (symbol_section->IsDescendant (text_section_sp.get()))
type = eSymbolTypeException;
}
else
{
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

View File

@ -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();