[Lldb-commits] [lldb] r248003 - Differential Revision: http://reviews.llvm.org/D12966
Aidan Dodds via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 18 09:49:39 PDT 2015
Author: aidandodds
Date: Fri Sep 18 11:49:39 2015
New Revision: 248003
URL: http://llvm.org/viewvc/llvm-project?rev=248003&view=rev
Log:
Differential Revision: http://reviews.llvm.org/D12966
On behalf of Dean De Leo
Modified:
lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp?rev=248003&r1=248002&r2=248003&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp Fri Sep 18 11:49:39 2015
@@ -210,15 +210,64 @@ RenderScriptRuntime::CreateExceptionReso
const RenderScriptRuntime::HookDefn RenderScriptRuntime::s_runtimeHookDefns[] =
{
//rsdScript
- {"rsdScriptInit", "_Z13rsdScriptInitPKN7android12renderscript7ContextEPNS0_7ScriptCEPKcS7_PKhjj", 0, RenderScriptRuntime::eModuleKindDriver, &lldb_private::RenderScriptRuntime::CaptureScriptInit1},
- {"rsdScriptInvokeForEach", "_Z22rsdScriptInvokeForEachPKN7android12renderscript7ContextEPNS0_6ScriptEjPKNS0_10AllocationEPS6_PKvjPK12RsScriptCall", 0, RenderScriptRuntime::eModuleKindDriver, nullptr},
- {"rsdScriptInvokeForEachMulti", "_Z27rsdScriptInvokeForEachMultiPKN7android12renderscript7ContextEPNS0_6ScriptEjPPKNS0_10AllocationEjPS6_PKvjPK12RsScriptCall", 0, RenderScriptRuntime::eModuleKindDriver, nullptr},
- {"rsdScriptInvokeFunction", "_Z23rsdScriptInvokeFunctionPKN7android12renderscript7ContextEPNS0_6ScriptEjPKvj", 0, RenderScriptRuntime::eModuleKindDriver, nullptr},
- {"rsdScriptSetGlobalVar", "_Z21rsdScriptSetGlobalVarPKN7android12renderscript7ContextEPKNS0_6ScriptEjPvj", 0, RenderScriptRuntime::eModuleKindDriver, &lldb_private::RenderScriptRuntime::CaptureSetGlobalVar1},
+ {
+ "rsdScriptInit", //name
+ "_Z13rsdScriptInitPKN7android12renderscript7ContextEPNS0_7ScriptCEPKcS7_PKhjj", // symbol name 32 bit
+ "_Z13rsdScriptInitPKN7android12renderscript7ContextEPNS0_7ScriptCEPKcS7_PKhmj", // symbol name 64 bit
+ 0, // version
+ RenderScriptRuntime::eModuleKindDriver, // type
+ &lldb_private::RenderScriptRuntime::CaptureScriptInit1 // handler
+ },
+ {
+ "rsdScriptInvokeForEach", // name
+ "_Z22rsdScriptInvokeForEachPKN7android12renderscript7ContextEPNS0_6ScriptEjPKNS0_10AllocationEPS6_PKvjPK12RsScriptCall", // symbol name 32bit
+ "_Z22rsdScriptInvokeForEachPKN7android12renderscript7ContextEPNS0_6ScriptEjPKNS0_10AllocationEPS6_PKvmPK12RsScriptCall", // symbol name 64bit
+ 0, // version
+ RenderScriptRuntime::eModuleKindDriver, // type
+ nullptr // handler
+ },
+ {
+ "rsdScriptInvokeForEachMulti", // name
+ "_Z27rsdScriptInvokeForEachMultiPKN7android12renderscript7ContextEPNS0_6ScriptEjPPKNS0_10AllocationEjPS6_PKvjPK12RsScriptCall", // symbol name 32bit
+ "_Z27rsdScriptInvokeForEachMultiPKN7android12renderscript7ContextEPNS0_6ScriptEjPPKNS0_10AllocationEmPS6_PKvmPK12RsScriptCall", // symbol name 64bit
+ 0, // version
+ RenderScriptRuntime::eModuleKindDriver, // type
+ nullptr // handler
+ },
+ {
+ "rsdScriptInvokeFunction", // name
+ "_Z23rsdScriptInvokeFunctionPKN7android12renderscript7ContextEPNS0_6ScriptEjPKvj", // symbol name 32bit
+ "_Z23rsdScriptInvokeFunctionPKN7android12renderscript7ContextEPNS0_6ScriptEjPKvm", // symbol name 64bit
+ 0, // version
+ RenderScriptRuntime::eModuleKindDriver, // type
+ nullptr // handler
+ },
+ {
+ "rsdScriptSetGlobalVar", // name
+ "_Z21rsdScriptSetGlobalVarPKN7android12renderscript7ContextEPKNS0_6ScriptEjPvj", // symbol name 32bit
+ "_Z21rsdScriptSetGlobalVarPKN7android12renderscript7ContextEPKNS0_6ScriptEjPvm", // symbol name 64bit
+ 0, // version
+ RenderScriptRuntime::eModuleKindDriver, // type
+ &lldb_private::RenderScriptRuntime::CaptureSetGlobalVar1 // handler
+ },
//rsdAllocation
- {"rsdAllocationInit", "_Z17rsdAllocationInitPKN7android12renderscript7ContextEPNS0_10AllocationEb", 0, RenderScriptRuntime::eModuleKindDriver, &lldb_private::RenderScriptRuntime::CaptureAllocationInit1},
- {"rsdAllocationRead2D", "_Z19rsdAllocationRead2DPKN7android12renderscript7ContextEPKNS0_10AllocationEjjj23RsAllocationCubemapFacejjPvjj", 0, RenderScriptRuntime::eModuleKindDriver, nullptr},
+ {
+ "rsdAllocationInit", // name
+ "_Z17rsdAllocationInitPKN7android12renderscript7ContextEPNS0_10AllocationEb", // symbol name 32bit
+ "_Z17rsdAllocationInitPKN7android12renderscript7ContextEPNS0_10AllocationEb", // symbol name 64bit
+ 0, // version
+ RenderScriptRuntime::eModuleKindDriver, // type
+ &lldb_private::RenderScriptRuntime::CaptureAllocationInit1 // handler
+ },
+ {
+ "rsdAllocationRead2D", //name
+ "_Z19rsdAllocationRead2DPKN7android12renderscript7ContextEPKNS0_10AllocationEjjj23RsAllocationCubemapFacejjPvjj", // symbol name 32bit
+ "_Z19rsdAllocationRead2DPKN7android12renderscript7ContextEPKNS0_10AllocationEjjj23RsAllocationCubemapFacejjPvmm", // symbol name 64bit
+ 0, // version
+ RenderScriptRuntime::eModuleKindDriver, // type
+ nullptr // handler
+ },
};
const size_t RenderScriptRuntime::s_runtimeHookCount = sizeof(s_runtimeHookDefns)/sizeof(s_runtimeHookDefns[0]);
@@ -242,7 +291,7 @@ RenderScriptRuntime::HookCallback(Runtim
{
Log* log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE));
- if(log)
+ if (log)
log->Printf ("RenderScriptRuntime::HookCallback - '%s' .", hook_info->defn->name);
if (hook_info->defn->grabber)
@@ -253,54 +302,115 @@ RenderScriptRuntime::HookCallback(Runtim
bool
-RenderScriptRuntime::GetArg32Simple(ExecutionContext& context, uint32_t arg, uint32_t *data)
+RenderScriptRuntime::GetArgSimple(ExecutionContext &context, uint32_t arg, uint64_t *data)
{
- Log* log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE));
-
if (!data)
return false;
+ Log* log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE));
Error error;
RegisterContext* reg_ctx = context.GetRegisterContext();
Process* process = context.GetProcessPtr();
+ bool success = false; // return value
+
+ if (!context.GetTargetPtr())
+ {
+ if (log)
+ log->Printf("RenderScriptRuntime::GetArgSimple - Invalid target");
- if (context.GetTargetPtr()->GetArchitecture().GetMachine() == llvm::Triple::ArchType::x86)
+ return false;
+ }
+
+ switch (context.GetTargetPtr()->GetArchitecture().GetMachine())
{
- uint64_t sp = reg_ctx->GetSP();
+ case llvm::Triple::ArchType::x86:
{
+ uint64_t sp = reg_ctx->GetSP();
uint32_t offset = (1 + arg) * sizeof(uint32_t);
- process->ReadMemory(sp + offset, data, sizeof(uint32_t), error);
- if(error.Fail())
+ uint32_t result = 0;
+ process->ReadMemory(sp + offset, &result, sizeof(uint32_t), error);
+ if (error.Fail())
{
- if(log)
- log->Printf ("RenderScriptRuntime:: GetArg32Simple - error reading X86 stack: %s.", error.AsCString());
+ if (log)
+ log->Printf ("RenderScriptRuntime:: GetArgSimple - error reading X86 stack: %s.", error.AsCString());
}
+ else
+ {
+ *data = result;
+ success = true;
+ }
+
+ break;
}
- }
- else if (context.GetTargetPtr()->GetArchitecture().GetMachine() == llvm::Triple::ArchType::arm)
- {
- if (arg < 4)
+ case llvm::Triple::ArchType::arm:
{
- const RegisterInfo* rArg = reg_ctx->GetRegisterInfoAtIndex(arg);
- RegisterValue rVal;
- reg_ctx->ReadRegister(rArg, rVal);
- (*data) = rVal.GetAsUInt32();
+ // arm 32 bit
+ if (arg < 4)
+ {
+ const RegisterInfo* rArg = reg_ctx->GetRegisterInfoAtIndex(arg);
+ RegisterValue rVal;
+ reg_ctx->ReadRegister(rArg, rVal);
+ (*data) = rVal.GetAsUInt32();
+ success = true;
+ }
+ else
+ {
+ uint64_t sp = reg_ctx->GetSP();
+ {
+ uint32_t offset = (arg-4) * sizeof(uint32_t);
+ process->ReadMemory(sp + offset, &data, sizeof(uint32_t), error);
+ if (error.Fail())
+ {
+ if (log)
+ log->Printf ("RenderScriptRuntime:: GetArgSimple - error reading ARM stack: %s.", error.AsCString());
+ }
+ else
+ {
+ success = true;
+ }
+ }
+ }
+
+ break;
}
- else
+ case llvm::Triple::ArchType::aarch64:
{
- uint64_t sp = reg_ctx->GetSP();
+ // arm 64 bit
+ // first 8 arguments are in the registers
+ if (arg < 8)
{
- uint32_t offset = (arg-4) * sizeof(uint32_t);
- process->ReadMemory(sp + offset, &data, sizeof(uint32_t), error);
- if(error.Fail())
+ const RegisterInfo* rArg = reg_ctx->GetRegisterInfoAtIndex(arg);
+ RegisterValue rVal;
+ success = reg_ctx->ReadRegister(rArg, rVal);
+ if (success)
{
- if(log)
- log->Printf ("RenderScriptRuntime:: GetArg32Simple - error reading ARM stack: %s.", error.AsCString());
+ *data = rVal.GetAsUInt64();
+ }
+ else
+ {
+ if (log)
+ log->Printf("RenderScriptRuntime::GetArgSimple() - AARCH64 - Error while reading the argument #%d", arg);
}
}
- }
+ else
+ {
+ // @TODO: need to find the argument in the stack
+ if (log)
+ log->Printf("RenderScriptRuntime::GetArgSimple - AARCH64 - FOR #ARG >= 8 NOT IMPLEMENTED YET. Argument number: %d", arg);
+ }
+ break;
+ }
+ default:
+ {
+ // invalid architecture
+ if (log)
+ log->Printf("RenderScriptRuntime::GetArgSimple - Architecture not supported");
+
+ }
}
- return true;
+
+
+ return success;
}
void
@@ -310,35 +420,38 @@ RenderScriptRuntime::CaptureSetGlobalVar
//Context, Script, int, data, length
- Error error;
-
- uint32_t rs_context_u32 = 0U;
- uint32_t rs_script_u32 = 0U;
- uint32_t rs_id_u32 = 0U;
- uint32_t rs_data_u32 = 0U;
- uint32_t rs_length_u32 = 0U;
+ uint64_t rs_context_u64 = 0U;
+ uint64_t rs_script_u64 = 0U;
+ uint64_t rs_id_u64 = 0U;
+ uint64_t rs_data_u64 = 0U;
+ uint64_t rs_length_u64 = 0U;
+
+ bool success =
+ GetArgSimple(context, 0, &rs_context_u64) &&
+ GetArgSimple(context, 1, &rs_script_u64) &&
+ GetArgSimple(context, 2, &rs_id_u64) &&
+ GetArgSimple(context, 3, &rs_data_u64) &&
+ GetArgSimple(context, 4, &rs_length_u64);
- std::string resname;
- std::string cachedir;
-
- GetArg32Simple(context, 0, &rs_context_u32);
- GetArg32Simple(context, 1, &rs_script_u32);
- GetArg32Simple(context, 2, &rs_id_u32);
- GetArg32Simple(context, 3, &rs_data_u32);
- GetArg32Simple(context, 4, &rs_length_u32);
+ if (!success)
+ {
+ if (log)
+ log->Printf("RenderScriptRuntime::CaptureSetGlobalVar1 - Error while reading the function parameters");
+ return;
+ }
- if(log)
+ if (log)
{
log->Printf ("RenderScriptRuntime::CaptureSetGlobalVar1 - 0x%" PRIx64 ",0x%" PRIx64 " slot %" PRIu64 " = 0x%" PRIx64 ":%" PRIu64 "bytes.",
- (uint64_t)rs_context_u32, (uint64_t)rs_script_u32, (uint64_t)rs_id_u32, (uint64_t)rs_data_u32, (uint64_t)rs_length_u32);
+ rs_context_u64, rs_script_u64, rs_id_u64, rs_data_u64, rs_length_u64);
- addr_t script_addr = (addr_t)rs_script_u32;
+ addr_t script_addr = (addr_t)rs_script_u64;
if (m_scriptMappings.find( script_addr ) != m_scriptMappings.end())
{
auto rsm = m_scriptMappings[script_addr];
- if (rs_id_u32 < rsm->m_globals.size())
+ if (rs_id_u64 < rsm->m_globals.size())
{
- auto rsg = rsm->m_globals[rs_id_u32];
+ auto rsg = rsm->m_globals[rs_id_u64];
log->Printf ("RenderScriptRuntime::CaptureSetGlobalVar1 - Setting of '%s' within '%s' inferred", rsg.m_name.AsCString(),
rsm->m_module->GetFileSpec().GetFilename().AsCString());
}
@@ -353,19 +466,24 @@ RenderScriptRuntime::CaptureAllocationIn
//Context, Alloc, bool
- Error error;
-
- uint32_t rs_context_u32 = 0U;
- uint32_t rs_alloc_u32 = 0U;
- uint32_t rs_forceZero_u32 = 0U;
-
- GetArg32Simple(context, 0, &rs_context_u32);
- GetArg32Simple(context, 1, &rs_alloc_u32);
- GetArg32Simple(context, 2, &rs_forceZero_u32);
-
- if(log)
+ uint64_t rs_context_u64 = 0U;
+ uint64_t rs_alloc_u64 = 0U;
+ uint64_t rs_forceZero_u64 = 0U;
+
+ bool success =
+ GetArgSimple(context, 0, &rs_context_u64) &&
+ GetArgSimple(context, 1, &rs_alloc_u64) &&
+ GetArgSimple(context, 2, &rs_forceZero_u64);
+ if (!success) // error case
+ {
+ if (log)
+ log->Printf("RenderScriptRuntime::CaptureAllocationInit1 - Error while reading the function parameters");
+ return; // abort
+ }
+
+ if (log)
log->Printf ("RenderScriptRuntime::CaptureAllocationInit1 - 0x%" PRIx64 ",0x%" PRIx64 ",0x%" PRIx64 " .",
- (uint64_t)rs_context_u32, (uint64_t)rs_alloc_u32, (uint64_t)rs_forceZero_u32);
+ rs_context_u64, rs_alloc_u64, rs_forceZero_u64);
}
void
@@ -377,37 +495,46 @@ RenderScriptRuntime::CaptureScriptInit1(
Error error;
Process* process = context.GetProcessPtr();
- uint32_t rs_context_u32 = 0U;
- uint32_t rs_script_u32 = 0U;
- uint32_t rs_resnameptr_u32 = 0U;
- uint32_t rs_cachedirptr_u32 = 0U;
+ uint64_t rs_context_u64 = 0U;
+ uint64_t rs_script_u64 = 0U;
+ uint64_t rs_resnameptr_u64 = 0U;
+ uint64_t rs_cachedirptr_u64 = 0U;
std::string resname;
std::string cachedir;
- GetArg32Simple(context, 0, &rs_context_u32);
- GetArg32Simple(context, 1, &rs_script_u32);
- GetArg32Simple(context, 2, &rs_resnameptr_u32);
- GetArg32Simple(context, 3, &rs_cachedirptr_u32);
+ // read the function parameters
+ bool success =
+ GetArgSimple(context, 0, &rs_context_u64) &&
+ GetArgSimple(context, 1, &rs_script_u64) &&
+ GetArgSimple(context, 2, &rs_resnameptr_u64) &&
+ GetArgSimple(context, 3, &rs_cachedirptr_u64);
- process->ReadCStringFromMemory((lldb::addr_t)rs_resnameptr_u32, resname, error);
+ if (!success)
+ {
+ if (log)
+ log->Printf("RenderScriptRuntime::CaptureScriptInit1 - Error while reading the function parameters");
+ return;
+ }
+
+ process->ReadCStringFromMemory((lldb::addr_t)rs_resnameptr_u64, resname, error);
if (error.Fail())
{
- if(log)
+ if (log)
log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - error reading resname: %s.", error.AsCString());
}
- process->ReadCStringFromMemory((lldb::addr_t)rs_cachedirptr_u32, cachedir, error);
+ process->ReadCStringFromMemory((lldb::addr_t)rs_cachedirptr_u64, cachedir, error);
if (error.Fail())
{
- if(log)
+ if (log)
log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - error reading cachedir: %s.", error.AsCString());
}
if (log)
log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - 0x%" PRIx64 ",0x%" PRIx64 " => '%s' at '%s' .",
- (uint64_t)rs_context_u32, (uint64_t)rs_script_u32, resname.c_str(), cachedir.c_str());
+ rs_context_u64, rs_script_u64, resname.c_str(), cachedir.c_str());
if (resname.size() > 0)
{
@@ -418,14 +545,14 @@ RenderScriptRuntime::CaptureScriptInit1(
script.cachedir = cachedir;
script.resname = resname;
script.scriptDyLib.assign(strm.GetData());
- script.script = rs_script_u32;
- script.context = rs_context_u32;
+ script.script = (addr_t) rs_script_u64;
+ script.context = (addr_t) rs_context_u64;
m_scripts.push_back(script);
if (log)
log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - '%s' tagged with context 0x%" PRIx64 " and script 0x%" PRIx64 ".",
- strm.GetData(), (uint64_t)rs_context_u32, (uint64_t)rs_script_u32);
+ strm.GetData(), rs_context_u64, rs_script_u64);
}
else if (log)
{
@@ -445,8 +572,12 @@ RenderScriptRuntime::LoadRuntimeHooks(ll
return;
}
- if ((GetProcess()->GetTarget().GetArchitecture().GetMachine() != llvm::Triple::ArchType::x86)
- && (GetProcess()->GetTarget().GetArchitecture().GetMachine() != llvm::Triple::ArchType::arm))
+ Target &target = GetProcess()->GetTarget();
+ llvm::Triple::ArchType targetArchType = target.GetArchitecture().GetMachine();
+
+ if (targetArchType != llvm::Triple::ArchType::x86
+ && targetArchType != llvm::Triple::ArchType::arm
+ && targetArchType != llvm::Triple::ArchType::aarch64)
{
if (log)
log->Printf ("RenderScriptRuntime::LoadRuntimeHooks - Unable to hook runtime. Only X86, ARM supported currently.");
@@ -454,7 +585,7 @@ RenderScriptRuntime::LoadRuntimeHooks(ll
return;
}
- Target &target = GetProcess()->GetTarget();
+ uint32_t archByteSize = target.GetArchitecture().GetAddressByteSize();
for (size_t idx = 0; idx < s_runtimeHookCount; idx++)
{
@@ -463,16 +594,29 @@ RenderScriptRuntime::LoadRuntimeHooks(ll
continue;
}
- const Symbol *sym = module->FindFirstSymbolWithNameAndType(ConstString(hook_defn->symbol_name), eSymbolTypeCode);
+ const char* symbol_name = (archByteSize == 4) ? hook_defn->symbol_name_m32 : hook_defn->symbol_name_m64;
+
+ const Symbol *sym = module->FindFirstSymbolWithNameAndType(ConstString(symbol_name), eSymbolTypeCode);
+ if (!sym){
+ if (log){
+ log->Printf("RenderScriptRuntime::LoadRuntimeHooks - ERROR: Symbol '%s' related to the function %s not found", symbol_name, hook_defn->name);
+ }
+ continue;
+ }
addr_t addr = sym->GetLoadAddress(&target);
if (addr == LLDB_INVALID_ADDRESS)
{
- if(log)
+ if (log)
log->Printf ("RenderScriptRuntime::LoadRuntimeHooks - Unable to resolve the address of hook function '%s' with symbol '%s'.",
- hook_defn->name, hook_defn->symbol_name);
+ hook_defn->name, symbol_name);
continue;
}
+ else
+ {
+ if (log)
+ log->Printf("RenderScriptRuntime::LoadRuntimeHooks - Function %s, address resolved at 0x%" PRIx64, hook_defn->name, addr);
+ }
RuntimeHookSP hook(new RuntimeHook());
hook->address = addr;
Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h?rev=248003&r1=248002&r2=248003&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h Fri Sep 18 11:49:39 2015
@@ -237,7 +237,8 @@ class RenderScriptRuntime : public lldb_
struct HookDefn
{
const char * name;
- const char * symbol_name;
+ const char * symbol_name_m32; // mangled name for the 32 bit architectures
+ const char * symbol_name_m64; // mangled name for the 64 bit archs
uint32_t version;
ModuleKind kind;
CaptureStateFn grabber;
@@ -286,7 +287,7 @@ class RenderScriptRuntime : public lldb_
void HookCallback(RuntimeHook* hook_info, ExecutionContext& context);
- bool GetArg32Simple(ExecutionContext& context, uint32_t arg, uint32_t *data);
+ bool GetArgSimple(ExecutionContext& context, uint32_t arg, uint64_t* data);
void CaptureScriptInit1(RuntimeHook* hook_info, ExecutionContext& context);
void CaptureAllocationInit1(RuntimeHook* hook_info, ExecutionContext& context);
More information about the lldb-commits
mailing list