From 45402f2ac87f44e36595dd83f7242f925fde4d54 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 11 Feb 2013 14:30:48 -0800 Subject: [PATCH] stap: Add shorthand option --dyninst for --runtime=dyninst * cmdline.cxx: Define --dyninst as LONG_OPT_RUNTIME_DYNINST. * session.cxx (systemtap_session::parse_cmdline_runtime): Pull out the code to set the runtime option. (systemtap_session::parse_cmdline): Use parse_cmdline_runtime for both LONG_OPT_RUNTIME and LONG_OPT_RUNTIME_DYNINST. (systemtap_session::usage): Document --dyninst. * man/stap.1: Document --dyninst. --- cmdline.cxx | 1 + cmdline.h | 1 + man/stap.1 | 4 ++++ session.cxx | 63 ++++++++++++++++++++++++++++++++++------------------- session.h | 1 + 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/cmdline.cxx b/cmdline.cxx index 935f27078..d7a2c607a 100644 --- a/cmdline.cxx +++ b/cmdline.cxx @@ -53,5 +53,6 @@ struct option stap_long_options[] = { { "sysenv", 1, NULL, LONG_OPT_SYSENV }, { "suppress-time-limits", 0, NULL, LONG_OPT_SUPPRESS_TIME_LIMITS }, { "runtime", 1, NULL, LONG_OPT_RUNTIME }, + { "dyninst", 0, NULL, LONG_OPT_RUNTIME_DYNINST }, { NULL, 0, NULL, 0 } }; diff --git a/cmdline.h b/cmdline.h index e002ddab6..6d38586d6 100644 --- a/cmdline.h +++ b/cmdline.h @@ -52,6 +52,7 @@ enum { LONG_OPT_SYSENV, LONG_OPT_SUPPRESS_TIME_LIMITS, LONG_OPT_RUNTIME, + LONG_OPT_RUNTIME_DYNINST, }; // NB: when adding new options, consider very carefully whether they diff --git a/man/stap.1 b/man/stap.1 index 3a9b0543a..5beb4811f 100644 --- a/man/stap.1 +++ b/man/stap.1 @@ -593,6 +593,10 @@ and \fIdyninst\fR. See .BR ALTERNATE\ RUNTIMES below for more information. +.TP +.BI \-\-dyninst +Shorthand for \fI\-\-runtime=dyninst\fR. + .SH ARGUMENTS Any additional arguments on the command line are passed to the script diff --git a/session.cxx b/session.cxx index cccade071..ad769de51 100644 --- a/session.cxx +++ b/session.cxx @@ -529,6 +529,10 @@ systemtap_session::usage (int exitcode) #endif /* HAVE_LIBSQLITE3 */ " --runtime=MODE\n" " set the pass-5 runtime mode, instead of kernel\n" +#ifdef HAVE_DYNINST + " --dyninst\n" + " shorthand for --runtime=dyninst\n" +#endif /* HAVE_DYNINST */ " --privilege=PRIVILEGE_LEVEL\n" " check the script for constructs not allowed at the given privilege level\n" " --unprivileged\n" @@ -1240,30 +1244,13 @@ systemtap_session::parse_cmdline (int argc, char * const argv []) } case LONG_OPT_RUNTIME: - if (optarg == string("kernel")) - runtime_mode = kernel_runtime; - else if (optarg == string("dyninst")) - { -#ifndef HAVE_DYNINST - cerr << _("ERROR: --runtime=dyninst unavailable; this build lacks DYNINST feature") << endl; - version(); - return 1; -#endif - if (privilege_set && pr_unprivileged != privilege) - { - cerr << _("ERROR: --runtime=dyninst implies unprivileged mode only") << endl; - return 1; - } - privilege = pr_unprivileged; - privilege_set = true; - runtime_mode = dyninst_runtime; - } - else - { - cerr << _F("ERROR: %s is an invalid argument for --runtime", optarg) << endl; - return 1; - } + if (!parse_cmdline_runtime (optarg)) + return 1; + break; + case LONG_OPT_RUNTIME_DYNINST: + if (!parse_cmdline_runtime ("dyninst")) + return 1; break; case '?': @@ -1284,6 +1271,36 @@ systemtap_session::parse_cmdline (int argc, char * const argv []) return 0; } +bool +systemtap_session::parse_cmdline_runtime (const string& opt_runtime) +{ + if (opt_runtime == string("kernel")) + runtime_mode = kernel_runtime; + else if (opt_runtime == string("dyninst")) + { +#ifndef HAVE_DYNINST + cerr << _("ERROR: --runtime=dyninst unavailable; this build lacks DYNINST feature") << endl; + version(); + return false; +#endif + if (privilege_set && pr_unprivileged != privilege) + { + cerr << _("ERROR: --runtime=dyninst implies unprivileged mode only") << endl; + return false; + } + privilege = pr_unprivileged; + privilege_set = true; + runtime_mode = dyninst_runtime; + } + else + { + cerr << _F("ERROR: %s is an invalid argument for --runtime", opt_runtime.c_str()) << endl; + return false; + } + + return true; +} + void systemtap_session::check_options (int argc, char * const argv []) { diff --git a/session.h b/session.h index 05fb41f77..b604009b0 100644 --- a/session.h +++ b/session.h @@ -115,6 +115,7 @@ public: // command line parsing int parse_cmdline (int argc, char * const argv []); + bool parse_cmdline_runtime (const std::string& opt_runtime); void version (); void usage (int exitcode); void check_options (int argc, char * const argv []); -- 2.43.5