]> sourceware.org Git - systemtap.git/commitdiff
stapdyn: Manage mutatee lifetimes better
authorJosh Stone <jistone@redhat.com>
Tue, 30 Oct 2012 01:58:58 +0000 (18:58 -0700)
committerJosh Stone <jistone@redhat.com>
Tue, 30 Oct 2012 01:58:58 +0000 (18:58 -0700)
It will be more convenient to manage mutatee resources if there's one
clear owner of the process, so stop allowing implicit copies.

* stapdyn/mutatee.h (mutatee::mutatee): Don't implement copy ctors.
* stapdyn/mutator.h (mutator::mutatees): Use shared_ptr for this list.
* stapdyn/mutator.cxx (mutator::create_process): Save a shared_ptr.
  (mutator::run): Use pointer indirection for mutatees.
  (mutator::dynamic_library_callback): Ditto.

stapdyn/mutatee.h
stapdyn/mutator.cxx
stapdyn/mutator.h

index 79d9e4636de0c49055189fc8a9d3f792ce260f2a..3c6ef5736a3e3065099dfa1a106678d82dae2765 100644 (file)
@@ -28,6 +28,10 @@ class mutatee {
 
     std::vector<BPatch_snippet*> registers; // PC + DWARF registers
 
+    // disable implicit constructors by not implementing these
+    mutatee (const mutatee& other);
+    mutatee& operator= (const mutatee& other);
+
   public:
     mutatee(BPatch_process* process);
     ~mutatee() {}
index 6d11174697155b88d24d96c6a931b9c068b48ce8..0404113e8fedf6409c338ea9e02dcc1986c06bdb 100644 (file)
@@ -49,6 +49,8 @@ mutator:: mutator (const string& module_name)
 
 mutator::~mutator ()
 {
+  mutatees.clear();
+
   if (module)
     {
       dlclose(module);
@@ -110,12 +112,14 @@ mutator::create_process(const string& command)
       return false;
     }
 
-  mutatees.push_back(mutatee(app));
-  if (!mutatees.back().load_stap_dso(module_name))
+  boost::shared_ptr<mutatee> m(new mutatee(app));
+  mutatees.push_back(m);
+
+  if (!m->load_stap_dso(module_name))
     return false;
 
   if (!targets.empty())
-    mutatees.back().instrument_dynprobes(targets);
+    m->instrument_dynprobes(targets);
 
   return true;
 }
@@ -172,17 +176,17 @@ mutator::run ()
   // children for continuation and exit status.
 
   // Get the stap module ready...
-  mutatees[0].call_function("stp_dyninst_session_init");
+  mutatees[0]->call_function("stp_dyninst_session_init");
 
   // And away we go!
-  mutatees[0].continue_execution();
-  while (!mutatees[0].is_terminated())
+  mutatees[0]->continue_execution();
+  while (!mutatees[0]->is_terminated())
     patch.waitForStatusChange();
 
   // When we get process detaching (rather than just exiting), need:
-  // mutatees[0].call_function("stp_dyninst_session_exit");
+  // mutatees[0]->call_function("stp_dyninst_session_exit");
 
-  return mutatees[0].check_exit();
+  return mutatees[0]->check_exit();
 }
 
 
@@ -199,8 +203,8 @@ mutator::dynamic_library_callback(BPatch_thread *thread,
   BPatch_process* process = thread->getProcess();
 
   for (size_t i = 0; i < mutatees.size(); ++i)
-    if (mutatees[i] == process)
-      mutatees[i].instrument_object_dynprobes(module->getObject(), targets);
+    if (*mutatees[i] == process)
+      mutatees[i]->instrument_object_dynprobes(module->getObject(), targets);
 }
 
 
index 16cbd7960c5e2845b631dab290b996b838faa411..e9b44b4685a6292138213b4bbe6e3fab4fb72cc8 100644 (file)
@@ -12,6 +12,8 @@
 #include <string>
 #include <vector>
 
+#include <boost/shared_ptr.hpp>
+
 #include <BPatch.h>
 #include <BPatch_module.h>
 #include <BPatch_process.h>
@@ -31,7 +33,7 @@ class mutator {
     std::string module_name; // the filename of the probe module
     std::vector<dynprobe_target> targets; // the probe targets in the module
 
-    std::vector<mutatee> mutatees; // all attached target processes
+    std::vector<boost::shared_ptr<mutatee> > mutatees; // all attached target processes
 
     // disable implicit constructors by not implementing these
     mutator (const mutator& other);
This page took 0.031596 seconds and 5 git commands to generate.