summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2005-09-06 17:40:12 +0000
committerhunt <hunt>2005-09-06 17:40:12 +0000
commit4c5ff1bb5bb35cb35e30c45e385043c5f8383cd0 (patch)
treea6696d16ece8e98844a6bac3ac550f0bd99f77c9
parentc0b3ea3235ced04f5f372c98c5ea321e2da22c59 (diff)
downloadsystemtap-steved-4c5ff1bb5bb35cb35e30c45e385043c5f8383cd0.tar.gz
systemtap-steved-4c5ff1bb5bb35cb35e30c45e385043c5f8383cd0.tar.xz
systemtap-steved-4c5ff1bb5bb35cb35e30c45e385043c5f8383cd0.zip
2005-09-06 Martin Hunt <hunt@redhat.com>
* tapset/context.stp: Add function target(). * stapfuncs.5.in (target): Document it. * elaborate.h (struct systemtap_session): Add cmd and target_pid to the struct. * main.cxx (usage): Add secriptions of "-c" and "-x" options. (main): Set s.cmd and s.target_pid. * buildrun.cxx (stringify): Copy this utility func here too. (run_pass): Add new options to set cmd and pid to the stpd command line.
-rw-r--r--ChangeLog12
-rw-r--r--buildrun.cxx20
-rw-r--r--elaborate.h2
-rw-r--r--main.cxx14
-rw-r--r--stapfuncs.5.in4
-rw-r--r--tapset/context.stp5
6 files changed, 54 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a9f14d3..40f398b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-09-06 Martin Hunt <hunt@redhat.com>
+
+ * tapset/context.stp: Add function target().
+ * stapfuncs.5.in (target): Document it.
+ * elaborate.h (struct systemtap_session): Add cmd and target_pid to
+ the struct.
+ * main.cxx (usage): Add secriptions of "-c" and "-x" options.
+ (main): Set s.cmd and s.target_pid.
+ * buildrun.cxx (stringify): Copy this utility func here too.
+ (run_pass): Add new options to set cmd and pid to the stpd
+ command line.
+
2005-09-06 Frank Ch. Eigler <fche@redhat.com>
* tapsets.cxx (emit_probe_entries): Disable fault_handler for now.
diff --git a/buildrun.cxx b/buildrun.cxx
index 867d0d0e..130f4a1b 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -92,6 +92,15 @@ compile_pass (systemtap_session& s)
}
+template <typename T>
+static string
+stringify(T t)
+{
+ ostringstream s;
+ s << t;
+ return s.str ();
+}
+
int
run_pass (systemtap_session& s)
@@ -114,8 +123,15 @@ run_pass (systemtap_session& s)
string stpd_cmd = string("/usr/bin/sudo ")
+ string(PKGLIBDIR) + "/stpd "
+ "-r " // disable relayfs
- + (s.verbose ? "" : "-q ")
- + s.tmpdir + "/" + s.module_name + ".ko";
+ + (s.verbose ? "" : "-q ");
+
+ if (s.cmd != "")
+ stpd_cmd += "-c \"" + s.cmd + "\" ";
+
+ if (s.target_pid)
+ stpd_cmd += "-t " + stringify(s.target_pid) + " ";
+
+ stpd_cmd += s.tmpdir + "/" + s.module_name + ".ko";
if (s.verbose) clog << "Running " << stpd_cmd << endl;
rc = system (stpd_cmd.c_str ());
diff --git a/elaborate.h b/elaborate.h
index 43816e61..6482952c 100644
--- a/elaborate.h
+++ b/elaborate.h
@@ -206,6 +206,8 @@ struct systemtap_session
std::string kernel_release;
std::string runtime_path;
std::string module_name;
+ std::string cmd;
+ int target_pid;
int last_pass;
bool test_mode;
bool verbose;
diff --git a/main.cxx b/main.cxx
index adf1136f..c6663655 100644
--- a/main.cxx
+++ b/main.cxx
@@ -78,6 +78,8 @@ usage (systemtap_session& s)
<< " -m MODULE set probe module name, instead of" << endl
<< " " << s.module_name << endl
<< " -o FILE send output to file instead of stdout" << endl
+ << " -c CMD start the probes, run CMD, and exit when it finishes" << endl
+ << " -x PID sets target() to PID" << endl
;
// -d: dump safety-related external references
@@ -116,6 +118,8 @@ main (int argc, char * const argv [])
s.last_pass = 5;
s.module_name = "stap_" + stringify(getuid()) + "_" + stringify(time(0));
s.keep_tmpdir = false;
+ s.cmd = "";
+ s.target_pid = 0;
const char* s_p = getenv ("SYSTEMTAP_TAPSET");
if (s_p != NULL)
@@ -131,7 +135,7 @@ main (int argc, char * const argv [])
while (true)
{
- int grc = getopt (argc, argv, "hVvp:I:e:o:tR:r:m:kg");
+ int grc = getopt (argc, argv, "hVvp:I:e:o:tR:r:m:kgc:x:");
if (grc < 0)
break;
switch (grc)
@@ -192,6 +196,14 @@ main (int argc, char * const argv [])
s.guru_mode = true;
break;
+ case 'c':
+ s.cmd = string (optarg);
+ break;
+
+ case 'x':
+ s.target_pid = atoi(optarg);
+ break;
+
case 'h':
default:
usage (s);
diff --git a/stapfuncs.5.in b/stapfuncs.5.in
index dbecf0d3..77514e28 100644
--- a/stapfuncs.5.in
+++ b/stapfuncs.5.in
@@ -150,6 +150,10 @@ pp:string ()
Return the probe point associated with the currently running probe handler,
including alias and wildcard expansion effects.
+.TP
+target:long ()
+Returns the pid of the target process.
+
.SH FILES
.nh
.IR /usr/share/systemtap/tapset
diff --git a/tapset/context.stp b/tapset/context.stp
index 3e776547..bb4004bb 100644
--- a/tapset/context.stp
+++ b/tapset/context.stp
@@ -92,3 +92,8 @@ function print_stack(stk:string) %{
function pp:string () %{
strlcpy (THIS->__retvalue, CONTEXT->probe_point, MAXSTRINGLEN);
%}
+
+function target:long () %{
+ THIS->__retvalue = _stp_target;
+%}
+