[DynInst_API:] [PATCH 1/3] dyninstAPI: Continue after loadLibrary


Date: Thu, 6 Feb 2014 18:33:27 -0800
From: Josh Stone <jistone@xxxxxxxxxx>
Subject: [DynInst_API:] [PATCH 1/3] dyninstAPI: Continue after loadLibrary
If BPatch_process::loadLibrary() had to stop the process at its start,
then it should also continue execution before returning.  This was changed
in commit 3faa4175c8100, a large commit with no explanation for this
particular change, possibly an accident.
---
 dyninstAPI/src/BPatch_process.C | 123 ++++++++++++++++++++++------------------
 1 file changed, 69 insertions(+), 54 deletions(-)

diff --git a/dyninstAPI/src/BPatch_process.C b/dyninstAPI/src/BPatch_process.C
index 21b1e4653e58..231ce4277ce0 100644
--- a/dyninstAPI/src/BPatch_process.C
+++ b/dyninstAPI/src/BPatch_process.C
@@ -1010,63 +1010,78 @@ BPatch_object *BPatch_process::loadLibrary(const char *libname, bool)
        }
    }
 
-   /**
-    * Find the DYNINSTloadLibrary function
-    **/
-   BPatch_Vector<BPatch_function *> bpfv;
-   BPatch_module* dyn_rt_lib = image->findModule("dyninstAPI_RT", true);
-   if(dyn_rt_lib == NULL)
-   {
-      cerr << __FILE__ << ":" << __LINE__ << ": FATAL:  Cannot find module for "
-           << "DyninstAPI Runtime Library" << endl;
-      return NULL;
-   }
-   dyn_rt_lib->findFunction("DYNINSTloadLibrary", bpfv);
-   if (!bpfv.size()) {
-      cerr << __FILE__ << ":" << __LINE__ << ": FATAL:  Cannot find Internal"
-           << "Function DYNINSTloadLibrary" << endl;
-      return NULL;
-   }
-   if (bpfv.size() > 1) {
-      std::string msg = std::string("Found ") + utos(bpfv.size()) +
-         std::string("functions called DYNINSTloadLibrary -- not fatal but weird");
-      BPatch_reportError(BPatchSerious, 100, msg.c_str());
-   }
-   BPatch_function *dlopen_func = bpfv[0];
-   if (dlopen_func == NULL) return NULL;
-
-   /**
-    * Generate a call to DYNINSTloadLibrary, and then run the generated code.
-    **/
-   BPatch_Vector<BPatch_snippet *> args;
-   BPatch_constExpr nameArg(libname);
-   args.push_back(&nameArg);
-   BPatch_funcCallExpr call_dlopen(*dlopen_func, args);
-
-   if (!oneTimeCodeInternal(call_dlopen, NULL, NULL, NULL, true)) {
-      BPatch_variableExpr *dlerror_str_var =
-         dyn_rt_lib->findVariable("gLoadLibraryErrorString");
-      assert(NULL != dlerror_str_var);
-      char dlerror_str[256];
-      dlerror_str_var->readValue((void *)dlerror_str, 256);
-      BPatch_reportError(BPatchSerious, 124, dlerror_str);
-      return NULL;
-   }
-   /* Find the new mapped_object, map it to a BPatch_module, and return it */
+   BPatch_object *object = NULL;
+   do {
+
+      /**
+       * Find the DYNINSTloadLibrary function
+       **/
+      BPatch_Vector<BPatch_function *> bpfv;
+      BPatch_module* dyn_rt_lib = image->findModule("dyninstAPI_RT", true);
+      if(dyn_rt_lib == NULL)
+      {
+         cerr << __FILE__ << ":" << __LINE__ << ": FATAL:  Cannot find module for "
+              << "DyninstAPI Runtime Library" << endl;
+         break;
+      }
+      dyn_rt_lib->findFunction("DYNINSTloadLibrary", bpfv);
+      if (!bpfv.size()) {
+         cerr << __FILE__ << ":" << __LINE__ << ": FATAL:  Cannot find Internal"
+              << "Function DYNINSTloadLibrary" << endl;
+         break;
+      }
+      if (bpfv.size() > 1) {
+         std::string msg = std::string("Found ") + utos(bpfv.size()) +
+            std::string("functions called DYNINSTloadLibrary -- not fatal but weird");
+         BPatch_reportError(BPatchSerious, 100, msg.c_str());
+      }
+      BPatch_function *dlopen_func = bpfv[0];
+      if (dlopen_func == NULL)
+        break;
+
+      /**
+       * Generate a call to DYNINSTloadLibrary, and then run the generated code.
+       **/
+      BPatch_Vector<BPatch_snippet *> args;
+      BPatch_constExpr nameArg(libname);
+      args.push_back(&nameArg);
+      BPatch_funcCallExpr call_dlopen(*dlopen_func, args);
+
+      if (!oneTimeCodeInternal(call_dlopen, NULL, NULL, NULL, true)) {
+         BPatch_variableExpr *dlerror_str_var =
+            dyn_rt_lib->findVariable("gLoadLibraryErrorString");
+         assert(NULL != dlerror_str_var);
+         char dlerror_str[256];
+         dlerror_str_var->readValue((void *)dlerror_str, 256);
+         BPatch_reportError(BPatchSerious, 124, dlerror_str);
+         break;
+      }
+      /* Find the new mapped_object, map it to a BPatch_module, and return it */
 
-   mapped_object* plib = llproc->findObject(libname);
-   if (!plib) {
-     std::string wildcard(libname);
-     wildcard += "*";
-     plib = llproc->findObject(wildcard, true);
-   }
-   if (!plib) {
-      // Best effort; take the latest added mapped_object
-      plib = llproc->mappedObjects().back();
+      mapped_object* plib = llproc->findObject(libname);
+      if (!plib) {
+        std::string wildcard(libname);
+        wildcard += "*";
+        plib = llproc->findObject(wildcard, true);
+      }
+      if (!plib) {
+         // Best effort; take the latest added mapped_object
+         plib = llproc->mappedObjects().back();
+      }
+
+      dynamic_cast<DynAddrSpace*>(llproc->mgr()->as())->loadLibrary(plib);
+      object = getImage()->findOrCreateObject(plib);
+
+   } while (0);
+
+   if( !wasStopped ) {
+       if( !continueExecution() ) {
+           BPatch_reportError(BPatchWarning, 0,
+                   "Failed to continue process for loadLibrary");
+       }
    }
 
-   dynamic_cast<DynAddrSpace*>(llproc->mgr()->as())->loadLibrary(plib);
-   return getImage()->findOrCreateObject(plib);
+   return object;
 }
 
 
-- 
1.8.5.3

[← Prev in Thread] Current Thread [Next in Thread→]