From 561079c8601d7ded6fe958b4cec3d0f7aec1ee63 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Thu, 8 Oct 2009 09:57:43 -0400 Subject: PR10702: preprocessor conditional for kernel CONFIG_foo * session.h (kernel_config[]): New session field. * main.cxx (parse_kernel_config): Populate it. * parse.cxx (eval_comparison): Use it. * testsuite/buildok/utrace.stp, testsuite/parseok/kconfig.stp: New tests. * NEWS, stap.1.in, doc/langref.tex: Mention it. --- main.cxx | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'main.cxx') diff --git a/main.cxx b/main.cxx index 86990675..c0ff3ba5 100644 --- a/main.cxx +++ b/main.cxx @@ -335,8 +335,8 @@ setup_signals (sighandler_t handler) sigaction (SIGTERM, &sa, NULL); } -void -setup_kernel_release (systemtap_session &s, const char* kstr) { +void setup_kernel_release (systemtap_session &s, const char* kstr) +{ if (kstr[0] == '/') // fully specified path { s.kernel_build_tree = kstr; @@ -364,6 +364,29 @@ setup_kernel_release (systemtap_session &s, const char* kstr) { } } + +void parse_kernel_config (systemtap_session &s) +{ + // PR10702: pull config options + string kernel_config_file = s.kernel_build_tree + "/.config"; + ifstream kcf (kernel_config_file.c_str()); + string line; + while (getline (kcf, line)) + { + if (line.substr(0, 7) != "CONFIG_") continue; + size_t off = line.find('='); + if (off == string::npos) continue; + string key = line.substr(0, off); + string value = line.substr(off+1, string::npos); + s.kernel_config[key] = value; + } + if (s.verbose > 2) + clog << "Parsed kernel \"" << kernel_config_file << "\", number of tuples: " << s.kernel_config.size() << endl; + + kcf.close(); +} + + static void checkOptions (systemtap_session &s) { @@ -945,6 +968,9 @@ main (int argc, char * const argv []) clog << "Created temporary directory \"" << s.tmpdir << "\"" << endl; } + // Now that no further changes to s.kernel_build_tree can occur, let's use it. + parse_kernel_config (s); + // Create the name of the C source file within the temporary // directory. s.translated_source = string(s.tmpdir) + "/" + s.module_name + ".c"; @@ -1028,7 +1054,7 @@ main (int argc, char * const argv []) // GLOB_NOMATCH is acceptable if (s.verbose>1 && globbuf.gl_pathc > 0) - clog << "Searched '" << dir << "', " + clog << "Searched \"" << dir << "\", " << "found " << globbuf.gl_pathc << endl; for (unsigned j=0; j