[Lldb-commits] [lldb] r145744 - in /lldb/trunk: include/lldb/Core/Mangled.h include/lldb/lldb-enumerations.h source/Core/Mangled.cpp source/Expression/ClangExpressionDeclMap.cpp source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp source/Symbol/ObjectFile.cpp source/Symbol/Symbol.cpp
Greg Clayton
gclayton at apple.com
Fri Dec 2 18:30:59 PST 2011
Author: gclayton
Date: Fri Dec 2 20:30:59 2011
New Revision: 145744
URL: http://llvm.org/viewvc/llvm-project?rev=145744&view=rev
Log:
Added new symbol types for Objective C classes, metaclasses, and ivars. Each
object file can correctly make these symbols which will abstract us from the
file format and ABI and we can then ask for the objective C class symbol for
a class and find out which object file it was defined in.
Modified:
lldb/trunk/include/lldb/Core/Mangled.h
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/source/Core/Mangled.cpp
lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/trunk/source/Symbol/ObjectFile.cpp
lldb/trunk/source/Symbol/Symbol.cpp
Modified: lldb/trunk/include/lldb/Core/Mangled.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Mangled.h?rev=145744&r1=145743&r2=145744&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Mangled.h (original)
+++ lldb/trunk/include/lldb/Core/Mangled.h Fri Dec 2 20:30:59 2011
@@ -400,6 +400,18 @@
const ConstString&
GetDemangledName () const;
+ void
+ SetDemangledName (const char *name)
+ {
+ m_demangled.SetCString (name);
+ }
+
+ void
+ SetMangledName (const char *name)
+ {
+ m_mangled.SetCString (name);
+ }
+
//----------------------------------------------------------------------
/// Mangled name get accessor.
///
@@ -407,7 +419,10 @@
/// A reference to the mangled name string object.
//----------------------------------------------------------------------
ConstString&
- GetMangledName ();
+ GetMangledName ()
+ {
+ return m_mangled;
+ }
//----------------------------------------------------------------------
/// Mangled name get accessor.
@@ -416,7 +431,10 @@
/// A const reference to the mangled name string object.
//----------------------------------------------------------------------
const ConstString&
- GetMangledName () const;
+ GetMangledName () const
+ {
+ return m_mangled;
+ }
//----------------------------------------------------------------------
/// Best name get accessor.
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=145744&r1=145743&r2=145744&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Fri Dec 2 20:30:59 2011
@@ -449,7 +449,10 @@
eSymbolTypeAdditional, // When symbols take more than one entry, the extra entries get this type
eSymbolTypeCompiler,
eSymbolTypeInstrumentation,
- eSymbolTypeUndefined
+ eSymbolTypeUndefined,
+ eSymbolTypeObjCClass,
+ eSymbolTypeObjCMetaClass,
+ eSymbolTypeObjCIVar
} SymbolType;
typedef enum SectionType
Modified: lldb/trunk/source/Core/Mangled.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Mangled.cpp?rev=145744&r1=145743&r2=145744&view=diff
==============================================================================
--- lldb/trunk/source/Core/Mangled.cpp (original)
+++ lldb/trunk/source/Core/Mangled.cpp Fri Dec 2 20:30:59 2011
@@ -190,25 +190,6 @@
return false;
}
-
-//----------------------------------------------------------------------
-// Mangled name get accessor
-//----------------------------------------------------------------------
-ConstString&
-Mangled::GetMangledName ()
-{
- return m_mangled;
-}
-
-//----------------------------------------------------------------------
-// Mangled name const get accessor
-//----------------------------------------------------------------------
-const ConstString&
-Mangled::GetMangledName () const
-{
- return m_mangled;
-}
-
//----------------------------------------------------------------------
// Get the demangled name if there is one, else return the mangled name.
//----------------------------------------------------------------------
Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=145744&r1=145743&r2=145744&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Fri Dec 2 20:30:59 2011
@@ -788,6 +788,9 @@
case eSymbolTypeCompiler:
case eSymbolTypeInstrumentation:
case eSymbolTypeUndefined:
+ case eSymbolTypeObjCClass:
+ case eSymbolTypeObjCMetaClass:
+ case eSymbolTypeObjCIVar:
symbol_load_addr = sym_address->GetLoadAddress (&target);
break;
}
Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=145744&r1=145743&r2=145744&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Fri Dec 2 20:30:59 2011
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/MachO.h"
#include "ObjectFileMachO.h"
@@ -305,6 +306,9 @@
case eSymbolTypeCompiler: return eAddressClassDebug;
case eSymbolTypeInstrumentation:return eAddressClassDebug;
case eSymbolTypeUndefined: return eAddressClassUnknown;
+ case eSymbolTypeObjCClass: return eAddressClassRuntime;
+ case eSymbolTypeObjCMetaClass: return eAddressClassRuntime;
+ case eSymbolTypeObjCIVar: return eAddressClassRuntime;
}
}
}
@@ -852,7 +856,8 @@
m_module->GetFileSpec().GetFilename().GetCString());
continue;
}
- const char* symbol_name = &strtab_data[nlist.n_strx];
+ const char *symbol_name = &strtab_data[nlist.n_strx];
+ const char *symbol_name_non_abi_mangled = NULL;
if (symbol_name[0] == '\0')
symbol_name = NULL;
@@ -1184,121 +1189,167 @@
uint8_t n_type = NlistMaskType & nlist.n_type;
sym[sym_idx].SetExternal((NlistMaskExternal & nlist.n_type) != 0);
- if (symbol_name && ::strstr (symbol_name, ".objc") == symbol_name)
+ switch (n_type)
{
- type = eSymbolTypeRuntime;
- }
- else
- {
- switch (n_type)
- {
- case NListTypeIndirect: // N_INDR - Fall through
- case NListTypePreboundUndefined:// N_PBUD - Fall through
- case NListTypeUndefined: // N_UNDF
- type = eSymbolTypeUndefined;
- break;
+ case NListTypeIndirect: // N_INDR - Fall through
+ case NListTypePreboundUndefined:// N_PBUD - Fall through
+ case NListTypeUndefined: // N_UNDF
+ type = eSymbolTypeUndefined;
+ break;
+
+ case NListTypeAbsolute: // N_ABS
+ type = eSymbolTypeAbsolute;
+ break;
- case NListTypeAbsolute: // N_ABS
- type = eSymbolTypeAbsolute;
+ 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;
+ }
- case NListTypeSection: // N_SECT
- 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;
- if (symbol_section == NULL)
+ switch (section_type)
{
- // TODO: warn about this?
- add_nlist = false;
- break;
+ 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;
}
- if (TEXT_eh_frame_sectID == nlist.n_sect)
+ if (type == eSymbolTypeInvalid)
{
- type = eSymbolTypeException;
- }
- else
- {
- uint32_t section_type = symbol_section->Get() & SectionFlagMaskSectionType;
-
- switch (section_type)
+ const char *symbol_sect_name = symbol_section->GetName().AsCString();
+ if (symbol_section->IsDescendant (text_section_sp.get()))
{
- 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;
+ if (symbol_section->IsClear(SectionAttrUserPureInstructions |
+ SectionAttrUserSelfModifyingCode |
+ SectionAttrSytemSomeInstructions))
+ type = eSymbolTypeData;
+ else
+ type = eSymbolTypeCode;
}
-
- if (type == eSymbolTypeInvalid)
+ else
+ if (symbol_section->IsDescendant(data_section_sp.get()))
{
- 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)
{
- if (symbol_sect_name && ::strstr (symbol_sect_name, "__objc") == symbol_sect_name)
- {
- type = eSymbolTypeRuntime;
- }
- else
- if (symbol_sect_name && ::strstr (symbol_sect_name, "__gcc_except_tab") == symbol_sect_name)
- {
- type = eSymbolTypeException;
- }
- else
+ type = eSymbolTypeRuntime;
+
+ if (symbol_name &&
+ symbol_name[0] == '_' &&
+ symbol_name[1] == 'O' &&
+ symbol_name[2] == 'B')
{
- type = eSymbolTypeData;
+ llvm::StringRef symbol_name_ref(symbol_name);
+ static const llvm::StringRef g_objc_v2_prefix_class ("_OBJC_CLASS_$_");
+ static const llvm::StringRef g_objc_v2_prefix_metaclass ("_OBJC_METACLASS_$_");
+ 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 = 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 = 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 = symbol_name + g_objc_v2_prefix_ivar.size();
+ type = eSymbolTypeObjCIVar;
+ }
}
}
else
- if (symbol_sect_name && ::strstr (symbol_sect_name, "__IMPORT") == symbol_sect_name)
+ 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 = eSymbolTypeRuntime;
+ 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))
+ {
+ symbol_name_non_abi_mangled = symbol_name;
+ symbol_name = symbol_name + g_objc_v1_prefix_class.size();
+ type = eSymbolTypeObjCClass;
+ }
}
}
}
- break;
- }
- }
+ }
+ break;
+ }
}
+
if (add_nlist)
{
+ uint64_t symbol_value = nlist.n_value;
bool symbol_name_is_mangled = false;
- if (symbol_name && symbol_name[0] == '_')
+
+ if (symbol_name_non_abi_mangled)
{
- symbol_name_is_mangled = symbol_name[1] == '_';
- symbol_name++; // Skip the leading underscore
+ sym[sym_idx].GetMangled().SetMangledName (symbol_name_non_abi_mangled);
+ sym[sym_idx].GetMangled().SetDemangledName (symbol_name);
+ }
+ else
+ {
+ if (symbol_name && symbol_name[0] == '_')
+ {
+ symbol_name_is_mangled = symbol_name[1] == '_';
+ symbol_name++; // Skip the leading underscore
+ }
+
+ else if (symbol_name)
+ {
+ sym[sym_idx].GetMangled().SetValue(symbol_name, symbol_name_is_mangled);
+ }
}
- uint64_t symbol_value = nlist.n_value;
- if (symbol_name)
- sym[sym_idx].GetMangled().SetValue(symbol_name, symbol_name_is_mangled);
if (is_debug == false)
{
if (type == eSymbolTypeCode)
Modified: lldb/trunk/source/Symbol/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=145744&r1=145743&r2=145744&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ObjectFile.cpp (original)
+++ lldb/trunk/source/Symbol/ObjectFile.cpp Fri Dec 2 20:30:59 2011
@@ -260,6 +260,9 @@
case eSymbolTypeCompiler: return eAddressClassDebug;
case eSymbolTypeInstrumentation:return eAddressClassDebug;
case eSymbolTypeUndefined: return eAddressClassUnknown;
+ case eSymbolTypeObjCClass: return eAddressClassRuntime;
+ case eSymbolTypeObjCMetaClass: return eAddressClassRuntime;
+ case eSymbolTypeObjCIVar: return eAddressClassRuntime;
}
}
}
Modified: lldb/trunk/source/Symbol/Symbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symbol.cpp?rev=145744&r1=145743&r2=145744&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symbol.cpp (original)
+++ lldb/trunk/source/Symbol/Symbol.cpp Fri Dec 2 20:30:59 2011
@@ -339,6 +339,9 @@
ENUM_TO_CSTRING(Compiler);
ENUM_TO_CSTRING(Instrumentation);
ENUM_TO_CSTRING(Undefined);
+ ENUM_TO_CSTRING(ObjCClass);
+ ENUM_TO_CSTRING(ObjCMetaClass);
+ ENUM_TO_CSTRING(ObjCIVar);
default:
break;
}
More information about the lldb-commits
mailing list