[Lldb-commits] [lldb] r371796 - [Target] Move InferiorCall to Process

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 12 17:02:06 PDT 2019


Author: xiaobai
Date: Thu Sep 12 17:02:05 2019
New Revision: 371796

URL: http://llvm.org/viewvc/llvm-project?rev=371796&view=rev
Log:
[Target] Move InferiorCall to Process

Summary:
InferiorCall is only ever used in Process, and it is not specific to
POSIX. By moving it to Process, we can remove all dependencies on plugins from
Process. Moving InferiorCall to Process seems to achieve this quite well.
Additionally, the name InferiorCall is a little vague now, so we rename
it something a bit more specific.

Reviewers: JDevlieghere, clayborg, compnerd, labath

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D67472

Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
    lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=371796&r1=371795&r2=371796&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Thu Sep 12 17:02:05 2019
@@ -2466,6 +2466,11 @@ public:
     return Status("Not implemented");
   }
 
+  // This calls a function of the form "void * (*)(void)".
+  bool CallVoidArgVoidPtrReturn(const Address *address,
+                                lldb::addr_t &returned_func,
+                                bool trap_exceptions = false);
+
 protected:
   void SetState(lldb::EventSP &event_sp);
 

Modified: lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp?rev=371796&r1=371795&r2=371796&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp Thu Sep 12 17:02:05 2019
@@ -184,64 +184,3 @@ bool lldb_private::InferiorCallMunmap(Pr
 
   return false;
 }
-
-// FIXME: This has nothing to do with Posix, it is just a convenience function
-// that calls a
-// function of the form "void * (*)(void)".  We should find a better place to
-// put this.
-
-bool lldb_private::InferiorCall(Process *process, const Address *address,
-                                addr_t &returned_func, bool trap_exceptions) {
-  Thread *thread =
-      process->GetThreadList().GetExpressionExecutionThread().get();
-  if (thread == nullptr || address == nullptr)
-    return false;
-
-  EvaluateExpressionOptions options;
-  options.SetStopOthers(true);
-  options.SetUnwindOnError(true);
-  options.SetIgnoreBreakpoints(true);
-  options.SetTryAllThreads(true);
-  options.SetDebug(false);
-  options.SetTimeout(process->GetUtilityExpressionTimeout());
-  options.SetTrapExceptions(trap_exceptions);
-
-  auto type_system_or_err =
-      process->GetTarget().GetScratchTypeSystemForLanguage(eLanguageTypeC);
-  if (!type_system_or_err) {
-    llvm::consumeError(type_system_or_err.takeError());
-    return false;
-  }
-  CompilerType void_ptr_type =
-      type_system_or_err->GetBasicTypeFromAST(eBasicTypeVoid).GetPointerType();
-  lldb::ThreadPlanSP call_plan_sp(
-      new ThreadPlanCallFunction(*thread, *address, void_ptr_type,
-                                 llvm::ArrayRef<addr_t>(), options));
-  if (call_plan_sp) {
-    DiagnosticManager diagnostics;
-
-    StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
-    if (frame) {
-      ExecutionContext exe_ctx;
-      frame->CalculateExecutionContext(exe_ctx);
-      ExpressionResults result =
-          process->RunThreadPlan(exe_ctx, call_plan_sp, options, diagnostics);
-      if (result == eExpressionCompleted) {
-        returned_func =
-            call_plan_sp->GetReturnValueObject()->GetValueAsUnsigned(
-                LLDB_INVALID_ADDRESS);
-
-        if (process->GetAddressByteSize() == 4) {
-          if (returned_func == UINT32_MAX)
-            return false;
-        } else if (process->GetAddressByteSize() == 8) {
-          if (returned_func == UINT64_MAX)
-            return false;
-        }
-        return true;
-      }
-    }
-  }
-
-  return false;
-}

Modified: lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h?rev=371796&r1=371795&r2=371796&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h Thu Sep 12 17:02:05 2019
@@ -30,9 +30,6 @@ bool InferiorCallMmap(Process *proc, lld
 
 bool InferiorCallMunmap(Process *proc, lldb::addr_t addr, lldb::addr_t length);
 
-bool InferiorCall(Process *proc, const Address *address,
-                  lldb::addr_t &returned_func, bool trap_exceptions = false);
-
 } // namespace lldb_private
 
 #endif // lldb_InferiorCallPOSIX_h_

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=371796&r1=371795&r2=371796&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Thu Sep 12 17:02:05 2019
@@ -13,7 +13,6 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/Threading.h"
 
-#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
 #include "lldb/Breakpoint/BreakpointLocation.h"
 #include "lldb/Breakpoint/StoppointCallbackContext.h"
 #include "lldb/Core/Debugger.h"
@@ -59,6 +58,7 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadPlan.h"
 #include "lldb/Target/ThreadPlanBase.h"
+#include "lldb/Target/ThreadPlanCallFunction.h"
 #include "lldb/Target/UnixSignals.h"
 #include "lldb/Utility/Event.h"
 #include "lldb/Utility/Log.h"
@@ -5593,7 +5593,7 @@ addr_t Process::ResolveIndirectFunction(
   if (iter != m_resolved_indirect_addresses.end()) {
     function_addr = (*iter).second;
   } else {
-    if (!InferiorCall(this, address, function_addr)) {
+    if (!CallVoidArgVoidPtrReturn(address, function_addr)) {
       Symbol *symbol = address->CalculateSymbolContextSymbol();
       error.SetErrorStringWithFormat(
           "Unable to call resolver for indirect function %s",
@@ -5969,3 +5969,58 @@ UtilityFunction *Process::GetLoadImageUt
                   [&] { m_dlopen_utility_func_up = factory(); });
   return m_dlopen_utility_func_up.get();
 }
+
+bool Process::CallVoidArgVoidPtrReturn(const Address *address,
+                                       addr_t &returned_func,
+                                       bool trap_exceptions) {
+  Thread *thread = GetThreadList().GetExpressionExecutionThread().get();
+  if (thread == nullptr || address == nullptr)
+    return false;
+
+  EvaluateExpressionOptions options;
+  options.SetStopOthers(true);
+  options.SetUnwindOnError(true);
+  options.SetIgnoreBreakpoints(true);
+  options.SetTryAllThreads(true);
+  options.SetDebug(false);
+  options.SetTimeout(GetUtilityExpressionTimeout());
+  options.SetTrapExceptions(trap_exceptions);
+
+  auto type_system_or_err =
+      GetTarget().GetScratchTypeSystemForLanguage(eLanguageTypeC);
+  if (!type_system_or_err) {
+    llvm::consumeError(type_system_or_err.takeError());
+    return false;
+  }
+  CompilerType void_ptr_type =
+      type_system_or_err->GetBasicTypeFromAST(eBasicTypeVoid).GetPointerType();
+  lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallFunction(
+      *thread, *address, void_ptr_type, llvm::ArrayRef<addr_t>(), options));
+  if (call_plan_sp) {
+    DiagnosticManager diagnostics;
+
+    StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
+    if (frame) {
+      ExecutionContext exe_ctx;
+      frame->CalculateExecutionContext(exe_ctx);
+      ExpressionResults result =
+          RunThreadPlan(exe_ctx, call_plan_sp, options, diagnostics);
+      if (result == eExpressionCompleted) {
+        returned_func =
+            call_plan_sp->GetReturnValueObject()->GetValueAsUnsigned(
+                LLDB_INVALID_ADDRESS);
+
+        if (GetAddressByteSize() == 4) {
+          if (returned_func == UINT32_MAX)
+            return false;
+        } else if (GetAddressByteSize() == 8) {
+          if (returned_func == UINT64_MAX)
+            return false;
+        }
+        return true;
+      }
+    }
+  }
+
+  return false;
+}




More information about the lldb-commits mailing list