diff options
-rw-r--r-- | lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 137 | ||||
-rw-r--r-- | lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h | 2 |
2 files changed, 58 insertions, 81 deletions
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp index d79eb753015..5442acd4b85 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -88,9 +88,6 @@ extern \"C\" void *__lldb_apple_objc_v2_find_class_name ( } \n\ "; -const char *AppleObjCRuntimeV2::g_objc_class_symbol_prefix = "OBJC_CLASS_$_"; -const char *AppleObjCRuntimeV2::g_objc_class_data_section_name = "__objc_data"; - AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, const ModuleSP &objc_module_sp) : AppleObjCRuntime (process), @@ -99,11 +96,12 @@ AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process, m_isa_to_name_cache(), m_isa_to_parent_cache() { - m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType(ConstString("gdb_object_getClass"), eSymbolTypeCode) != NULL); + static const ConstString g_gdb_object_getClass("gdb_object_getClass"); + m_has_object_getClass = (objc_module_sp->FindFirstSymbolWithNameAndType(g_gdb_object_getClass, eSymbolTypeCode) != NULL); } bool -AppleObjCRuntimeV2::RunFunctionToFindClassName(lldb::addr_t object_addr, Thread *thread, char *name_dst, size_t max_name_len) +AppleObjCRuntimeV2::RunFunctionToFindClassName(addr_t object_addr, Thread *thread, char *name_dst, size_t max_name_len) { // Since we are going to run code we have to make sure only one thread at a time gets to try this. Mutex::Locker (m_get_class_name_args_mutex); @@ -123,7 +121,7 @@ AppleObjCRuntimeV2::RunFunctionToFindClassName(lldb::addr_t object_addr, Thread Value void_ptr_value; ClangASTContext *clang_ast_context = m_process->GetTarget().GetScratchClangASTContext(); - lldb::clang_type_t clang_void_ptr_type = clang_ast_context->GetVoidPtrType(false); + clang_type_t clang_void_ptr_type = clang_ast_context->GetVoidPtrType(false); void_ptr_value.SetValueType (Value::eValueTypeScalar); void_ptr_value.SetContext (Value::eContextTypeClangType, clang_void_ptr_type); void_ptr_value.GetScalar() = object_addr; @@ -131,7 +129,7 @@ AppleObjCRuntimeV2::RunFunctionToFindClassName(lldb::addr_t object_addr, Thread dispatch_values.PushValue (void_ptr_value); Value int_value; - lldb::clang_type_t clang_int_type = clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingSint, 32); + clang_type_t clang_int_type = clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, 32); int_value.SetValueType (Value::eValueTypeScalar); int_value.SetContext (Value::eContextTypeClangType, clang_int_type); int_value.GetScalar() = debug; @@ -221,7 +219,7 @@ AppleObjCRuntimeV2::RunFunctionToFindClassName(lldb::addr_t object_addr, Thread return false; } - lldb::addr_t result_ptr = void_ptr_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + addr_t result_ptr = void_ptr_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); size_t chars_read = m_process->ReadCStringFromMemory (result_ptr, name_dst, max_name_len); // If we exhausted our buffer before finding a NULL we're probably off in the weeds somewhere... @@ -234,7 +232,7 @@ AppleObjCRuntimeV2::RunFunctionToFindClassName(lldb::addr_t object_addr, Thread bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, - lldb::DynamicValueType use_dynamic, + DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name, Address &address) { @@ -245,53 +243,18 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, if (CouldHaveDynamicValue (in_value)) { // First job, pull out the address at 0 offset from the object That will be the ISA pointer. - AddressType address_type; - lldb::addr_t original_ptr = in_value.GetPointerValue(&address_type); - - // ObjC only has single inheritance, so the objects all start at the same pointer value. - address.SetSection (NULL); - address.SetOffset (original_ptr); + Error error; + const addr_t object_ptr = in_value.GetPointerValue(); + const addr_t isa_addr = m_process->ReadPointerFromMemory (object_ptr, error); - if (original_ptr == LLDB_INVALID_ADDRESS) + if (error.Fail()) return false; - - Target *target = m_process->CalculateTarget(); - char memory_buffer[16]; - DataExtractor data (memory_buffer, - sizeof(memory_buffer), - m_process->GetByteOrder(), - m_process->GetAddressByteSize()); + address.SetSection (NULL); + address.SetOffset(object_ptr); - size_t address_byte_size = m_process->GetAddressByteSize(); - Error error; - size_t bytes_read = m_process->ReadMemory (original_ptr, - memory_buffer, - address_byte_size, - error); - if (!error.Success() || (bytes_read != address_byte_size)) - { - return false; - } - - uint32_t offset = 0; - lldb::addr_t isa_addr = data.GetAddress (&offset); - - if (offset == 0) - return false; - - // Make sure the class address is readable, otherwise this is not a good object: - bytes_read = m_process->ReadMemory (isa_addr, - memory_buffer, - address_byte_size, - error); - if (bytes_read != address_byte_size) - return false; - // First check the cache... - SymbolContext sc; - class_type_or_name = LookupInClassNameCache (isa_addr); if (!class_type_or_name.IsEmpty()) @@ -302,9 +265,17 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, return false; } + // We don't have the object cached, so make sure the class + // address is readable, otherwise this is not a good object: + m_process->ReadPointerFromMemory (isa_addr, error); + + if (error.Fail()) + return false; + const char *class_name = NULL; Address isa_address; - target->GetSectionLoadList().ResolveLoadAddress (isa_addr, isa_address); + Target &target = m_process->GetTarget(); + target.GetSectionLoadList().ResolveLoadAddress (isa_addr, isa_address); if (isa_address.IsValid()) { @@ -319,14 +290,14 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, // some static class or nothing. See if it is in the right section // and if its name is the right form. ConstString section_name = section->GetName(); - if (section_name == ConstString(g_objc_class_data_section_name)) + static ConstString g_objc_class_section_name ("__objc_data"); + if (section_name == g_objc_class_section_name) { isa_address.CalculateSymbolContext(&sc); if (sc.symbol) { - class_name = sc.symbol->GetName().AsCString(); - if (strstr (class_name, g_objc_class_symbol_prefix) == class_name) - class_name += strlen (g_objc_class_symbol_prefix); + if (sc.symbol->GetType() == eSymbolTypeObjCClass) + class_name = sc.symbol->GetName().GetCString(); else return false; } @@ -335,7 +306,7 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, } char class_buffer[1024]; - if (class_name == NULL && use_dynamic != lldb::eDynamicDontRunTarget) + if (class_name == NULL && use_dynamic != eDynamicDontRunTarget) { // If the class address didn't point into the binary, or // it points into the right section but there wasn't a symbol @@ -351,23 +322,23 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, if (thread_to_use == NULL) return false; - if (!RunFunctionToFindClassName (original_ptr, thread_to_use, class_buffer, 1024)) + if (!RunFunctionToFindClassName (object_ptr, thread_to_use, class_buffer, 1024)) return false; class_name = class_buffer; } - if (class_name != NULL && *class_name != '\0') + if (class_name && class_name[0]) { class_type_or_name.SetName (class_name); TypeList class_types; - uint32_t num_matches = target->GetImages().FindTypes (sc, - class_type_or_name.GetName(), - true, - UINT32_MAX, - class_types); + uint32_t num_matches = target.GetImages().FindTypes (sc, + class_type_or_name.GetName(), + true, + UINT32_MAX, + class_types); if (num_matches == 1) { class_type_or_name.SetTypeSP (class_types.GetTypeAtIndex(0)); @@ -377,7 +348,7 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, { for (size_t i = 0; i < num_matches; i++) { - lldb::TypeSP this_type(class_types.GetTypeAtIndex(i)); + TypeSP this_type(class_types.GetTypeAtIndex(i)); if (this_type) { if (ClangASTContext::IsObjCClassType(this_type->GetClangFullType())) @@ -419,7 +390,7 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value, // Static Functions //------------------------------------------------------------------ LanguageRuntime * -AppleObjCRuntimeV2::CreateInstance (Process *process, lldb::LanguageType language) +AppleObjCRuntimeV2::CreateInstance (Process *process, LanguageType language) { // FIXME: This should be a MacOS or iOS process, and we need to look for the OBJC section to make // sure we aren't using the V1 runtime. @@ -565,9 +536,9 @@ AppleObjCRuntimeV2::GetByteOffsetForIvar (ClangASTType &parent_ast_type, const c ConstString ivar_const_str (buffer.c_str()); SymbolContextList sc_list; - Target *target = &(m_process->GetTarget()); + Target &target = m_process->GetTarget(); - target->GetImages().FindSymbolsWithNameAndType(ivar_const_str, eSymbolTypeRuntime, sc_list); + target.GetImages().FindSymbolsWithNameAndType(ivar_const_str, eSymbolTypeRuntime, sc_list); SymbolContext ivar_offset_symbol; if (sc_list.GetSize() != 1 @@ -575,7 +546,7 @@ AppleObjCRuntimeV2::GetByteOffsetForIvar (ClangASTType &parent_ast_type, const c || ivar_offset_symbol.symbol == NULL) return LLDB_INVALID_IVAR_OFFSET; - lldb::addr_t ivar_offset_address = ivar_offset_symbol.symbol->GetValue().GetLoadAddress(target); + addr_t ivar_offset_address = ivar_offset_symbol.symbol->GetValue().GetLoadAddress (&target); Error error; @@ -592,7 +563,7 @@ AppleObjCRuntimeV2::GetByteOffsetForIvar (ClangASTType &parent_ast_type, const c // is not accurate (it might become better by incorporating further // knowledge about the internals of tagged pointers) bool -AppleObjCRuntimeV2::IsTaggedPointer(lldb::addr_t ptr) +AppleObjCRuntimeV2::IsTaggedPointer(addr_t ptr) { return (ptr & 0x01); } @@ -604,7 +575,7 @@ AppleObjCRuntimeV2::IsTaggedPointer(lldb::addr_t ptr) ObjCLanguageRuntime::ObjCISA AppleObjCRuntimeV2::GetISA(ValueObject& valobj) { - if (ClangASTType::GetMinimumLanguage(valobj.GetClangAST(),valobj.GetClangType()) != lldb::eLanguageTypeObjC) + if (ClangASTType::GetMinimumLanguage(valobj.GetClangAST(),valobj.GetClangType()) != eLanguageTypeObjC) return 0; // if we get an invalid VO (which might still happen when playing around @@ -613,7 +584,7 @@ AppleObjCRuntimeV2::GetISA(ValueObject& valobj) if (valobj.GetValue().GetContextType() == Value::eContextTypeInvalid) return 0; - lldb::addr_t isa_pointer = valobj.GetPointerValue(); + addr_t isa_pointer = valobj.GetPointerValue(); // tagged pointer if (IsTaggedPointer(isa_pointer)) @@ -635,11 +606,16 @@ AppleObjCRuntimeV2::GetISA(ValueObject& valobj) ConstString AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) { + static const ConstString g_unknown ("unknown"); + if (!IsValidISA(isa)) - return ConstString(NULL); + return ConstString(); if (isa == g_objc_Tagged_ISA) - return ConstString("_lldb_Tagged_ObjC_ISA"); + { + static const ConstString g_objc_tagged_isa_name ("_lldb_Tagged_ObjC_ISA"); + return g_objc_tagged_isa_name; + } ISAToNameIterator found = m_isa_to_name_cache.find(isa); ISAToNameIterator end = m_isa_to_name_cache.end(); @@ -658,14 +634,17 @@ AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) --> class_rw_t data; */ - lldb::addr_t rw_pointer = isa + (4 * pointer_size); + addr_t rw_pointer = isa + (4 * pointer_size); //printf("rw_pointer: %llx\n", rw_pointer); uint64_t data_pointer = m_process->ReadUnsignedIntegerFromMemory(rw_pointer, pointer_size, 0, error); if (error.Fail()) - return ConstString("unknown"); + { + return g_unknown; + + } /* uint32_t flags; @@ -680,7 +659,7 @@ AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) 0, error); if (error.Fail()) - return ConstString("unknown"); + return g_unknown; /* uint32_t flags; @@ -704,7 +683,7 @@ AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) 0, error); if (error.Fail()) - return ConstString("unknown"); + return g_unknown; //printf("name_pointer: %llx\n", name_pointer); char* cstr = new char[512]; @@ -730,7 +709,7 @@ AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa) } } else - return ConstString("unknown"); + return g_unknown; } ObjCLanguageRuntime::ObjCISA @@ -754,7 +733,7 @@ AppleObjCRuntimeV2::GetParentClass(ObjCLanguageRuntime::ObjCISA isa) struct class_t *isa; --> struct class_t *superclass; */ - lldb::addr_t parent_pointer = isa + pointer_size; + addr_t parent_pointer = isa + pointer_size; //printf("rw_pointer: %llx\n", rw_pointer); uint64_t parent_isa = m_process->ReadUnsignedIntegerFromMemory(parent_pointer, diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h index cf4bf3f641e..f53dc59b04a 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h @@ -130,8 +130,6 @@ private: static const char *g_find_class_name_function_name; static const char *g_find_class_name_function_body; - static const char *g_objc_class_symbol_prefix; - static const char *g_objc_class_data_section_name; }; } // namespace lldb_private |