Author: aidandodds
Date: Wed Jan  6 09:43:52 2016
New Revision: 256941

URL: http://llvm.org/viewvc/llvm-project?rev=256941&view=rev
Log:
[Renderscript] Fix stack argument inspection.

Function arguments that were spilled and passed on the stack were incorrectly 
read.
The value was written back into the output pointer rather then the memory being 
pointed to.

Modified:
    
lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp

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=256941&r1=256940&r2=256941&view=diff
==============================================================================
--- 
lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
 (original)
+++ 
lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
 Wed Jan  6 09:43:52 2016
@@ -452,7 +452,7 @@ RenderScriptRuntime::GetPluginNameStatic
     return g_name;
 }
 
-RenderScriptRuntime::ModuleKind 
+RenderScriptRuntime::ModuleKind
 RenderScriptRuntime::GetModuleKind(const lldb::ModuleSP &module_sp)
 {
     if (module_sp)
@@ -493,7 +493,7 @@ RenderScriptRuntime::IsRenderScriptModul
     return GetModuleKind(module_sp) != eModuleKindIgnored;
 }
 
-void 
+void
 RenderScriptRuntime::ModulesDidLoad(const ModuleList &module_list )
 {
     Mutex::Locker locker (module_list.GetMutex ());
@@ -640,11 +640,11 @@ RenderScriptRuntime::HookCallback(void *
     RenderScriptRuntime *lang_rt = (RenderScriptRuntime 
*)context.GetProcessPtr()->GetLanguageRuntime(eLanguageTypeExtRenderScript);
 
     lang_rt->HookCallback(hook_info, context);
-    
+
     return false;
 }
 
-void 
+void
 RenderScriptRuntime::HookCallback(RuntimeHook* hook_info, ExecutionContext& 
context)
 {
     Log* log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE));
@@ -652,7 +652,7 @@ RenderScriptRuntime::HookCallback(Runtim
     if (log)
         log->Printf ("RenderScriptRuntime::HookCallback - '%s' .", 
hook_info->defn->name);
 
-    if (hook_info->defn->grabber) 
+    if (hook_info->defn->grabber)
     {
         (this->*(hook_info->defn->grabber))(hook_info, context);
     }
@@ -706,7 +706,6 @@ RenderScriptRuntime::GetArgSimple(Execut
                 *data = result;
                 success = true;
             }
-
             break;
         }
         case llvm::Triple::ArchType::x86_64:
@@ -741,6 +740,7 @@ RenderScriptRuntime::GetArgSimple(Execut
         case llvm::Triple::ArchType::arm:
         {
             // arm 32 bit
+            // first 4 arguments are passed via registers
             if (arg < 4)
             {
                 const RegisterInfo* rArg = 
reg_ctx->GetRegisterInfoAtIndex(arg);
@@ -760,18 +760,19 @@ RenderScriptRuntime::GetArgSimple(Execut
             {
                 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())
+                uint32_t value = 0;
+                size_t bytes_read = process->ReadMemory(sp + offset, &value, 
sizeof(value), error);
+                if (error.Fail() || bytes_read != sizeof(value))
                 {
                     if (log)
                         log->Printf("RenderScriptRuntime::GetArgSimple - error 
reading ARM stack: %s.", error.AsCString());
                 }
                 else
                 {
+                    *data = value;
                     success = true;
                 }
             }
-
             break;
         }
         case llvm::Triple::ArchType::aarch64:
@@ -803,8 +804,8 @@ RenderScriptRuntime::GetArgSimple(Execut
         }
         case llvm::Triple::ArchType::mipsel:
         {
-
             // read from the registers
+            // first 4 arguments are passed in registers
             if (arg < 4){
                 const RegisterInfo* rArg = reg_ctx->GetRegisterInfoAtIndex(arg 
+ 4);
                 RegisterValue rVal;
@@ -818,26 +819,25 @@ RenderScriptRuntime::GetArgSimple(Execut
                     if (log)
                         log->Printf("RenderScriptRuntime::GetArgSimple() - 
Mips - Error while reading the argument #%d", arg);
                 }
-
             }
-
-            // read from the stack
+            // arguments > 4 are read from the stack
             else
             {
                 uint64_t sp = reg_ctx->GetSP();
                 uint32_t offset = arg * sizeof(uint32_t);
-                process->ReadMemory(sp + offset, &data, sizeof(uint32_t), 
error);
-                if (error.Fail())
+                uint32_t value = 0;
+                size_t bytes_read = process->ReadMemory(sp + offset, &value, 
sizeof(value), error);
+                if (error.Fail() || bytes_read != sizeof(value))
                 {
                     if (log)
                         log->Printf("RenderScriptRuntime::GetArgSimple - error 
reading Mips stack: %s.", error.AsCString());
                 }
                 else
                 {
+                    *data = value;
                     success = true;
                 }
             }
-
             break;
         }
         case llvm::Triple::ArchType::mips64el:
@@ -858,24 +858,24 @@ RenderScriptRuntime::GetArgSimple(Execut
                         log->Printf("RenderScriptRuntime::GetArgSimple - 
Mips64 - Error reading the argument #%d", arg);
                 }
             }
-
-            // read from the stack
+            // arguments > 8 are read from the stack
             else
             {
                 uint64_t sp = reg_ctx->GetSP();
                 uint32_t offset = (arg - 8) * sizeof(uint64_t);
-                process->ReadMemory(sp + offset, &data, sizeof(uint64_t), 
error);
-                if (error.Fail())
+                uint64_t value = 0;
+                size_t bytes_read = process->ReadMemory(sp + offset, &value, 
sizeof(value), error);
+                if (error.Fail() || bytes_read != sizeof(value))
                 {
                     if (log)
                         log->Printf("RenderScriptRuntime::GetArgSimple - 
Mips64 - Error reading Mips64 stack: %s.", error.AsCString());
                 }
                 else
                 {
+                    *data = value;
                     success = true;
                 }
             }
-
             break;
         }
         default:
@@ -883,7 +883,6 @@ RenderScriptRuntime::GetArgSimple(Execut
             // invalid architecture
             if (log)
                 log->Printf("RenderScriptRuntime::GetArgSimple - Architecture 
not supported");
-
         }
     }
 
@@ -895,11 +894,11 @@ RenderScriptRuntime::GetArgSimple(Execut
     return success;
 }
 
-void 
+void
 RenderScriptRuntime::CaptureSetGlobalVar1(RuntimeHook* hook_info, 
ExecutionContext& context)
 {
     Log* log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE));
-    
+
     //Context, Script, int, data, length
 
     uint64_t rs_context_u64 = 0U;
@@ -921,7 +920,7 @@ RenderScriptRuntime::CaptureSetGlobalVar
             log->Printf("RenderScriptRuntime::CaptureSetGlobalVar1 - Error 
while reading the function parameters");
         return;
     }
-    
+
     if (log)
     {
         log->Printf ("RenderScriptRuntime::CaptureSetGlobalVar1 - 0x%" PRIx64 
",0x%" PRIx64 " slot %" PRIu64 " = 0x%" PRIx64 ":%" PRIu64 "bytes.",
@@ -934,18 +933,18 @@ RenderScriptRuntime::CaptureSetGlobalVar
             if (rs_id_u64 < rsm->m_globals.size())
             {
                 auto rsg = rsm->m_globals[rs_id_u64];
-                log->Printf ("RenderScriptRuntime::CaptureSetGlobalVar1 - 
Setting of '%s' within '%s' inferred", rsg.m_name.AsCString(), 
+                log->Printf ("RenderScriptRuntime::CaptureSetGlobalVar1 - 
Setting of '%s' within '%s' inferred", rsg.m_name.AsCString(),
                                 
rsm->m_module->GetFileSpec().GetFilename().AsCString());
             }
         }
     }
 }
 
-void 
+void
 RenderScriptRuntime::CaptureAllocationInit1(RuntimeHook* hook_info, 
ExecutionContext& context)
 {
     Log* log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE));
-    
+
     //Context, Alloc, bool
 
     uint64_t rs_context_u64 = 0U;
@@ -1009,7 +1008,7 @@ RenderScriptRuntime::CaptureAllocationDe
         log->Printf("RenderScriptRuntime::CaptureAllocationDestroy - Couldn't 
find destroyed allocation");
 }
 
-void 
+void
 RenderScriptRuntime::CaptureScriptInit1(RuntimeHook* hook_info, 
ExecutionContext& context)
 {
     Log* log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_LANGUAGE));
@@ -1045,16 +1044,16 @@ RenderScriptRuntime::CaptureScriptInit1(
     {
         if (log)
             log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - error 
reading resname: %s.", error.AsCString());
-                   
+
     }
 
     process->ReadCStringFromMemory((lldb::addr_t)rs_cachedirptr_u64, cachedir, 
error);
     if (error.Fail())
     {
         if (log)
-            log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - error 
reading cachedir: %s.", error.AsCString());     
+            log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - error 
reading cachedir: %s.", error.AsCString());
     }
-    
+
     if (log)
         log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - 0x%" PRIx64 
",0x%" PRIx64 " => '%s' at '%s' .",
                      rs_context_u64, rs_script_u64, resname.c_str(), 
cachedir.c_str());
@@ -1077,7 +1076,7 @@ RenderScriptRuntime::CaptureScriptInit1(
         if (log)
             log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - '%s' 
tagged with context 0x%" PRIx64 " and script 0x%" PRIx64 ".",
                          strm.GetData(), rs_context_u64, rs_script_u64);
-    } 
+    }
     else if (log)
     {
         log->Printf ("RenderScriptRuntime::CaptureScriptInit1 - resource name 
invalid, Script not tagged");
@@ -1134,7 +1133,7 @@ RenderScriptRuntime::LoadRuntimeHooks(ll
         if (addr == LLDB_INVALID_ADDRESS)
         {
             if (log)
-                log->Printf ("RenderScriptRuntime::LoadRuntimeHooks - Unable 
to resolve the address of hook function '%s' with symbol '%s'.", 
+                log->Printf ("RenderScriptRuntime::LoadRuntimeHooks - Unable 
to resolve the address of hook function '%s' with symbol '%s'.",
                              hook_defn->name, symbol_name);
             continue;
         }
@@ -1152,7 +1151,7 @@ RenderScriptRuntime::LoadRuntimeHooks(ll
         m_runtimeHooks[addr] = hook;
         if (log)
         {
-            log->Printf ("RenderScriptRuntime::LoadRuntimeHooks - Successfully 
hooked '%s' in '%s' version %" PRIu64 " at 0x%" PRIx64 ".", 
+            log->Printf ("RenderScriptRuntime::LoadRuntimeHooks - Successfully 
hooked '%s' in '%s' version %" PRIu64 " at 0x%" PRIx64 ".",
                 hook_defn->name, 
module->GetFileSpec().GetFilename().AsCString(), (uint64_t)hook_defn->version, 
(uint64_t)addr);
         }
     }
@@ -2299,7 +2298,7 @@ RenderScriptRuntime::LoadModule(const ll
             }
             case eModuleKindLibRS:
             {
-                if (!m_libRS) 
+                if (!m_libRS)
                 {
                     m_libRS = module_sp;
                     static ConstString gDbgPresentStr("gDebuggerPresent");
@@ -2334,7 +2333,7 @@ RenderScriptRuntime::LoadModule(const ll
                 break;
         }
         if (module_loaded)
-            Update();  
+            Update();
         return module_loaded;
     }
     return false;
@@ -2408,7 +2407,7 @@ RSModuleDescriptor::ParseRSInfo()
                         m_kernels.push_back(RSKernelDescriptor(this, name, 
slot));
                     }
                 }
-            } 
+            }
             else if (sscanf(line.c_str(), "pragmaCount: %u", &numDefns) == 1)
             {
                 char name[MAXLINE];
@@ -2417,7 +2416,7 @@ RSModuleDescriptor::ParseRSInfo()
                 {
                     name[0] = '\0';
                     value[0] = '\0';
-                    if (sscanf(info_lines[++offset].c_str(), "%s - %s", 
&name[0], &value[0]) != 0 
+                    if (sscanf(info_lines[++offset].c_str(), "%s - %s", 
&name[0], &value[0]) != 0
                         && (name[0] != '\0'))
                     {
                         m_pragmas[std::string(name)] = value;
@@ -2466,7 +2465,7 @@ RenderScriptRuntime::Status(Stream &strm
         strm.Printf("CPU Reference Implementation discovered.");
         strm.EOL();
     }
-    
+
     if (m_runtimeHooks.size())
     {
         strm.Printf("Runtime functions hooked:");
@@ -2476,7 +2475,7 @@ RenderScriptRuntime::Status(Stream &strm
             strm.Indent(b.second->defn->name);
             strm.EOL();
         }
-    } 
+    }
     else
     {
         strm.Printf("Runtime is not hooked.");
@@ -2484,7 +2483,7 @@ RenderScriptRuntime::Status(Stream &strm
     }
 }
 
-void 
+void
 RenderScriptRuntime::DumpContexts(Stream &strm) const
 {
     strm.Printf("Inferred RenderScript Contexts:");
@@ -2519,7 +2518,7 @@ RenderScriptRuntime::DumpContexts(Stream
     strm.IndentLess();
 }
 
-void 
+void
 RenderScriptRuntime::DumpKernels(Stream &strm) const
 {
     strm.Printf("RenderScript Kernels:");


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to