Testcase fixes with the new symbol lookup code for

Objective-C, making symbol lookups for various raw
Objective-C symbols work correctly.  The IR interpreter
makes these lookups because Clang has emitted raw
symbol references for ivars and classes.

Also improved performance in SymbolFiles, caching the
result of asking for SymbolFile abilities.

llvm-svn: 145758
This commit is contained in:
Sean Callanan 2011-12-03 04:38:43 +00:00
parent dfb6dc9187
commit bfaf54d665
8 changed files with 37 additions and 30 deletions

View File

@ -48,7 +48,9 @@ public:
// Constructors and Destructors
//------------------------------------------------------------------
SymbolFile(ObjectFile* obj_file) :
m_obj_file(obj_file)
m_obj_file(obj_file),
m_abilities(0),
m_calculated_abilities(false)
{
}
@ -86,7 +88,18 @@ public:
/// enumeration. Any bits that are set represent an ability that
/// this symbol plug-in can parse from the object file.
///------------------------------------------------------------------
virtual uint32_t GetAbilities () = 0;
uint32_t GetAbilities ()
{
if (!m_calculated_abilities)
{
m_abilities = CalculateAbilities();
m_calculated_abilities = true;
}
return m_abilities;
}
virtual uint32_t CalculateAbilities() = 0;
//------------------------------------------------------------------
/// Initialize the SymbolFile object.
@ -144,7 +157,8 @@ public:
void ReportError (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
protected:
ObjectFile* m_obj_file; // The object file that symbols can be extracted from.
uint32_t m_abilities;
bool m_calculated_abilities;
private:
DISALLOW_COPY_AND_ASSIGN (SymbolFile);
};

View File

@ -1271,19 +1271,19 @@ ObjectFileMachO::ParseSymtab (bool minimize)
static const llvm::StringRef g_objc_v2_prefix_ivar ("_OBJC_IVAR_$_");
if (symbol_name_ref.startswith(g_objc_v2_prefix_class))
{
symbol_name_non_abi_mangled = symbol_name;
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_class.size();
type = eSymbolTypeObjCClass;
}
else if (symbol_name_ref.startswith(g_objc_v2_prefix_metaclass))
{
symbol_name_non_abi_mangled = symbol_name;
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
type = eSymbolTypeObjCMetaClass;
}
else if (symbol_name_ref.startswith(g_objc_v2_prefix_ivar))
{
symbol_name_non_abi_mangled = symbol_name;
symbol_name_non_abi_mangled = symbol_name + 1;
symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
type = eSymbolTypeObjCIVar;
}

View File

@ -307,7 +307,7 @@ SymbolFileDWARF::SupportedVersion(uint16_t version)
}
uint32_t
SymbolFileDWARF::GetAbilities ()
SymbolFileDWARF::CalculateAbilities ()
{
uint32_t abilities = 0;
if (m_obj_file != NULL)

View File

@ -84,7 +84,7 @@ public:
SymbolFileDWARF(lldb_private::ObjectFile* ofile);
virtual ~SymbolFileDWARF();
virtual uint32_t GetAbilities ();
virtual uint32_t CalculateAbilities ();
virtual void InitializeObject();
//------------------------------------------------------------------

View File

@ -419,7 +419,7 @@ SymbolFileDWARFDebugMap::GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit
}
uint32_t
SymbolFileDWARFDebugMap::GetAbilities ()
SymbolFileDWARFDebugMap::CalculateAbilities ()
{
// In order to get the abilities of this plug-in, we look at the list of
// N_OSO entries (object files) from the symbol table and make sure that

View File

@ -48,7 +48,7 @@ public:
SymbolFileDWARFDebugMap (lldb_private::ObjectFile* ofile);
virtual ~ SymbolFileDWARFDebugMap ();
virtual uint32_t GetAbilities ();
virtual uint32_t CalculateAbilities ();
virtual void InitializeObject();

View File

@ -83,19 +83,11 @@ SymbolFileSymtab::GetClangASTContext ()
bool
SymbolFileSymtab::HasObjCSymbols ()
{
if (m_has_objc_symbols == eLazyBoolCalculate)
{
if (m_obj_file->GetSectionList()->FindSectionByName(ConstString("__objc_data")))
m_has_objc_symbols = eLazyBoolYes;
else
m_has_objc_symbols = eLazyBoolNo;
}
return m_has_objc_symbols == eLazyBoolYes;
return (m_abilities & RuntimeTypes) != 0;
}
uint32_t
SymbolFileSymtab::GetAbilities ()
SymbolFileSymtab::CalculateAbilities ()
{
uint32_t abilities = 0;
if (m_obj_file)
@ -136,8 +128,11 @@ SymbolFileSymtab::GetAbilities ()
abilities |= GlobalVariables;
}
if (HasObjCSymbols())
symtab->AppendSymbolIndexesWithType(eSymbolTypeObjCClass, m_objc_class_indexes);
if (!m_objc_class_indexes.empty())
{
symtab->SortSymbolIndexesByValue(m_objc_class_indexes, true);
abilities |= RuntimeTypes;
}
}
@ -403,14 +398,10 @@ SymbolFileSymtab::FindTypes (const lldb_private::SymbolContext& sc, const lldb_p
types.Insert(iter->second);
return 1;
}
std::string symbol_name("OBJC_CLASS_$_");
symbol_name.append(name.AsCString());
ConstString symbol_const_string(symbol_name.c_str());
std::vector<uint32_t> indices;
if (m_obj_file->GetSymtab()->FindAllSymbolsWithNameAndType(symbol_const_string, lldb::eSymbolTypeRuntime, indices) == 0)
/*const ConstString &name, SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector<uint32_t>& symbol_indexes*/
if (m_obj_file->GetSymtab()->FindAllSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, Symtab::eDebugNo, Symtab::eVisibilityAny, m_objc_class_indexes) == 0)
return 0;
const bool isForwardDecl = false;

View File

@ -42,7 +42,7 @@ public:
virtual
~SymbolFileSymtab();
virtual uint32_t GetAbilities ();
virtual uint32_t CalculateAbilities ();
//------------------------------------------------------------------
// Compile Unit function calls
@ -119,12 +119,14 @@ public:
GetPluginVersion();
protected:
lldb_private::LazyBool m_has_objc_symbols;
std::vector<uint32_t> m_source_indexes;
std::vector<uint32_t> m_func_indexes;
std::vector<uint32_t> m_code_indexes;
std::vector<uint32_t> m_data_indexes;
std::vector<uint32_t> m_addr_indexes; // Anything that needs to go into an search by address
std::vector<uint32_t> m_objc_class_indexes;
lldb_private::LazyBool m_has_objc_symbols;
typedef std::map<lldb_private::ConstString, lldb::TypeSP> TypeMap;