diff options
author | fche <fche> | 2005-09-28 21:23:12 +0000 |
---|---|---|
committer | fche <fche> | 2005-09-28 21:23:12 +0000 |
commit | ed10c6397cc27ad161c7fcd5242c38efd89dc5ee (patch) | |
tree | 26eb4a7e8d7176e93e6bcde03599c8e96abc7828 | |
parent | e0d31311729955985b3142c1c7d08cf461192469 (diff) | |
download | systemtap-steved-ed10c6397cc27ad161c7fcd5242c38efd89dc5ee.tar.gz systemtap-steved-ed10c6397cc27ad161c7fcd5242c38efd89dc5ee.tar.xz systemtap-steved-ed10c6397cc27ad161c7fcd5242c38efd89dc5ee.zip |
2005-09-28 Frank Ch. Eigler <fche@elastic.org>
PR 1182.
* main.cxx (main): Support -D macro-setting option.
* stap.1.in: Document it and related macros.
* buildrun.cxx (compile_pass): Emit macro definitions.
* translate.cxx (translate_pass): Guard limit macros with #ifdef.
Eliminate MAXCONCURRENCY macro.
* elaborate.h (systemtap_session): Add "macros" field.
* parse.cxx (parse_if_statement): Clear "elseblock" if needed.
2005-09-28 Frank Ch. Eigler <fche@elastic.org>
PR 1182.
* systemtap.samples/control_limits.*: New test.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | buildrun.cxx | 29 | ||||
-rw-r--r-- | elaborate.h | 1 | ||||
-rw-r--r-- | main.cxx | 7 | ||||
-rw-r--r-- | parse.cxx | 2 | ||||
-rw-r--r-- | stap.1.in | 27 | ||||
-rw-r--r-- | translate.cxx | 13 |
7 files changed, 84 insertions, 6 deletions
@@ -1,3 +1,14 @@ +2005-09-28 Frank Ch. Eigler <fche@elastic.org> + + PR 1182. + * main.cxx (main): Support -D macro-setting option. + * stap.1.in: Document it and related macros. + * buildrun.cxx (compile_pass): Emit macro definitions. + * translate.cxx (translate_pass): Guard limit macros with #ifdef. + Eliminate MAXCONCURRENCY macro. + * elaborate.h (systemtap_session): Add "macros" field. + * parse.cxx (parse_if_statement): Clear "elseblock" if needed. + 2005-09-27 Frank Ch. Eigler <fche@elastic.org> * tapsets.cxx (query_cu_containing_global_address): Tolerate diff --git a/buildrun.cxx b/buildrun.cxx index 130f4a1b..598d7110 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -20,6 +20,26 @@ extern "C" { using namespace std; +// return as quoted string, with at least '"' backslash-escaped +template <typename IN> inline string +lex_cast_qstring(IN const & in) +{ + stringstream ss; + string out, out2; + if (!(ss << in)) + throw runtime_error("bad lexical cast"); + out = ss.str(); + out2 += '"'; + for (unsigned i=0; i<out.length(); i++) + { + if (out[i] == '"') // XXX others? + out2 += '\\'; + out2 += out[i]; + } + out2 += '"'; + return out2; +} + int compile_pass (systemtap_session& s) @@ -30,10 +50,15 @@ compile_pass (systemtap_session& s) int rc = 0; // Create makefile + + for (unsigned i=0; i<s.macros.size(); i++) + o << "CFLAGS += -D " << lex_cast_qstring(s.macros[i]) << endl; + if (s.test_mode) { string module_dir = string("/lib/modules/") + s.kernel_release + "/build"; + o << "CFLAGS += -I \"" << module_dir << "/include\"" << endl; o << "CFLAGS += -I \"" << s.runtime_path << "/user\"" << endl; o << "CFLAGS += -I \"" << s.runtime_path << "\"" << endl; @@ -41,7 +66,6 @@ compile_pass (systemtap_session& s) o << s.module_name << ": " << s.translated_source << endl; o << "\t$(CC) $(CFLAGS) -o " << s.module_name << " " << s.translated_source << endl; - o.close (); } else { @@ -50,9 +74,10 @@ compile_pass (systemtap_session& s) o << "CFLAGS += -I \"" << s.runtime_path << "\"" << endl; o << "CFLAGS += -I \"" << s.runtime_path << "/relayfs\"" << endl; o << "obj-m := " << s.module_name << ".o" << endl; - o.close (); } + o.close (); + // Run make if (s.test_mode) { diff --git a/elaborate.h b/elaborate.h index 6482952c..22fea82f 100644 --- a/elaborate.h +++ b/elaborate.h @@ -202,6 +202,7 @@ struct systemtap_session // command line args std::vector<std::string> include_path; + std::vector<std::string> macros; std::vector<std::string> args; std::string kernel_release; std::string runtime_path; @@ -71,6 +71,7 @@ usage (systemtap_session& s) for (unsigned i=0; i<s.include_path.size(); i++) clog << " " << s.include_path[i] << endl; clog + << " -D NM=VAL emit macro definition into generated C code" << endl << " -R DIR look in DIR for runtime, instead of" << endl << " " << s.runtime_path << endl // << " -r RELEASE use kernel RELEASE, instead of" << endl @@ -135,7 +136,7 @@ main (int argc, char * const argv []) while (true) { - int grc = getopt (argc, argv, "hVvp:I:e:o:tR:r:m:kgc:x:"); + int grc = getopt (argc, argv, "hVvp:I:e:o:tR:r:m:kgc:x:D:"); if (grc < 0) break; switch (grc) @@ -204,6 +205,10 @@ main (int argc, char * const argv []) s.target_pid = atoi(optarg); break; + case 'D': + s.macros.push_back (string (optarg)); + break; + case 'h': default: usage (s); @@ -946,6 +946,8 @@ parser::parse_if_statement () next (); s->elseblock = parse_statement (); } + else + s->elseblock = 0; // in case not otherwise initialized return s; } @@ -100,6 +100,10 @@ section for details. Add the given directory to the tapset search directory. See the description of pass 2 for details. .TP +.BI \-D " NAME=VALUE" +Add the given preprocessor directive to the module Makefile. These can +be used to override limit parameters described below. +.TP .BI \-R " DIR" Look for the systemtap runtime sources in the given directory. .TP @@ -471,7 +475,6 @@ See the .IR stapex (5) manual page for a collection of samples. - .SH SAFETY AND SECURITY Systemtap is an administrative tool. It exposes kernel internal data structures and potentially private user information. It acquires root @@ -497,6 +500,28 @@ against manipulation by concurrent probe handlers. Use of guru mode constructs such as embedded C can violate these constraints, leading to kernel crash or data corruption. .PP +The resource use limits are set by macros in the generated C code. +These may be overridden with the +.R -D +flag. A selection of these is as follows: +.TP +MAXNESTING +Maximum number of recursive function call levels. +.TP +MAXSTRINGLEN +Maximum length of strings. +.TP +MAXTRYLOCK +Maximum number of iterations to wait for locks on global variables +before declaring possible deadlock. +.TP +MAXACTION +Maximum number of statements to execute during any single probe hit. +.TP +MAXMAPENTRIES +Maximum number of rows in any single global array. + +.PP In case something goes wrong with .IR stap " or " stpd after a probe has already started running, one may safely kill both diff --git a/translate.cxx b/translate.cxx index cc4b58c5..a7caf0bd 100644 --- a/translate.cxx +++ b/translate.cxx @@ -670,7 +670,7 @@ c_unparser::emit_common_header () o->newline(-1) << "} function_" << c_varname (fd->name) << ";"; } o->newline(-1) << "} locals [MAXNESTING];"; - o->newline(-1) << "} contexts [MAXCONCURRENCY];" << endl; + o->newline(-1) << "} contexts [NR_CPUS];" << endl; emit_map_type_instantiations (); } @@ -2376,12 +2376,21 @@ translate_pass (systemtap_session& s) // This is at the very top of the file. s.op->line() << "#define TEST_MODE " << (s.test_mode ? 1 : 0) << endl; + s.op->newline() << "#ifndef MAXNESTING"; s.op->newline() << "#define MAXNESTING 30"; - s.op->newline() << "#define MAXCONCURRENCY NR_CPUS"; + s.op->newline() << "#endif"; + s.op->newline() << "#ifndef MAXSTRINGLEN"; s.op->newline() << "#define MAXSTRINGLEN 128"; + s.op->newline() << "#endif"; + s.op->newline() << "#ifndef MAXTRYLOCK"; s.op->newline() << "#define MAXTRYLOCK 20"; + s.op->newline() << "#endif"; + s.op->newline() << "#ifndef MAXACTION"; s.op->newline() << "#define MAXACTION 1000"; + s.op->newline() << "#endif"; + s.op->newline() << "#ifndef MAXMAPENTRIES"; s.op->newline() << "#define MAXMAPENTRIES 2048"; + s.op->newline() << "#endif"; // impedance mismatch s.op->newline() << "#define STP_STRING_SIZE MAXSTRINGLEN"; |