Skip to content

[lldb] Fixup code addresses in the Objective-C language runtime #3476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "AppleObjCClassDescriptorV2.h"

#include "lldb/Expression/FunctionCaller.h"
#include "lldb/Target/ABI.h"
#include "lldb/Utility/Log.h"

using namespace lldb;
Expand Down Expand Up @@ -73,6 +74,10 @@ bool ClassDescriptorV2::objc_class_t::Read(Process *process,
m_flags = (uint8_t)(data_NEVER_USE & (lldb::addr_t)3);
m_data_ptr = data_NEVER_USE & GetClassDataMask(process);

if (ABISP abi_sp = process->GetABI()) {
m_isa = abi_sp->FixCodeAddress(m_isa);
m_superclass = abi_sp->FixCodeAddress(m_superclass);
}
return true;
}

Expand Down Expand Up @@ -105,6 +110,8 @@ bool ClassDescriptorV2::class_rw_t::Read(Process *process, lldb::addr_t addr) {
m_flags = extractor.GetU32_unchecked(&cursor);
m_version = extractor.GetU32_unchecked(&cursor);
m_ro_ptr = extractor.GetAddress_unchecked(&cursor);
if (ABISP abi_sp = process->GetABI())
m_ro_ptr = abi_sp->FixCodeAddress(m_ro_ptr);
m_method_list_ptr = extractor.GetAddress_unchecked(&cursor);
m_properties_ptr = extractor.GetAddress_unchecked(&cursor);
m_firstSubclass = extractor.GetAddress_unchecked(&cursor);
Expand All @@ -120,6 +127,8 @@ bool ClassDescriptorV2::class_rw_t::Read(Process *process, lldb::addr_t addr) {
process->GetByteOrder(),
process->GetAddressByteSize());
m_ro_ptr = extractor.GetAddress_unchecked(&cursor);
if (ABISP abi_sp = process->GetABI())
m_ro_ptr = abi_sp->FixCodeAddress(m_ro_ptr);
}

return true;
Expand Down Expand Up @@ -231,6 +240,8 @@ bool ClassDescriptorV2::method_list_t::Read(Process *process,
DataBufferHeap buffer(size, '\0');
Status error;

if (ABISP abi_sp = process->GetABI())
addr = abi_sp->FixCodeAddress(addr);
process->ReadMemory(addr, buffer.GetBytes(), size, error);
if (error.Fail()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "lldb/Expression/DiagnosticManager.h"
#include "lldb/Expression/FunctionCaller.h"
#include "lldb/Expression/UtilityFunction.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
Expand Down Expand Up @@ -134,6 +135,10 @@ bool AppleThreadPlanStepThroughObjCTrampoline::ShouldStop(Event *event_ptr) {
target_addr_value);
m_impl_function->DeallocateFunctionResults(exc_ctx, m_args_addr);
lldb::addr_t target_addr = target_addr_value.GetScalar().ULongLong();

if (ABISP abi_sp = GetThread().GetProcess()->GetABI()) {
target_addr = abi_sp->FixCodeAddress(target_addr);
}
Address target_so_addr;
target_so_addr.SetOpcodeLoadAddress(target_addr, exc_ctx.GetTargetPtr());
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "lldb/Symbol/TypeList.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/ABI.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Timer.h"

Expand Down Expand Up @@ -273,10 +274,17 @@ ObjCLanguageRuntime::ClassDescriptorSP
ObjCLanguageRuntime::GetClassDescriptorFromISA(ObjCISA isa) {
if (isa) {
UpdateISAToDescriptorMap();

ObjCLanguageRuntime::ISAToDescriptorIterator pos =
m_isa_to_descriptor.find(isa);
if (pos != m_isa_to_descriptor.end())
return pos->second;

if (ABISP abi_sp = m_process->GetABI()) {
pos = m_isa_to_descriptor.find(abi_sp->FixCodeAddress(isa));
if (pos != m_isa_to_descriptor.end())
return pos->second;
}
}
return ClassDescriptorSP();
}
Expand Down