diff options
-rw-r--r-- | main.cxx | 17 | ||||
-rw-r--r-- | session.h | 5 | ||||
-rw-r--r-- | tapsets.cxx | 8 | ||||
-rw-r--r-- | translate.cxx | 119 |
4 files changed, 72 insertions, 77 deletions
@@ -105,6 +105,17 @@ usage (systemtap_session& s, int exitcode) << " -c CMD start the probes, run CMD, and exit when it finishes" << endl << " -x PID sets target() to PID" << endl + << " -d OBJECT add unwind/symbol data for OBJECT file"; + if (s.unwindsym_modules.size() == 0) + clog << endl; + else + clog << ", in addition to" << endl; + { + vector<string> syms (s.unwindsym_modules.begin(), s.unwindsym_modules.end()); + for (unsigned i=0; i<syms.size(); i++) + clog << " " << syms[i] << endl; + } + clog << " -t collect probe timing information" << endl #ifdef HAVE_LIBSQLITE3 << " -q generate information on tapset coverage" << endl @@ -392,7 +403,7 @@ main (int argc, char * const argv []) { "ignore-dwarf", 0, &long_opt, LONG_OPT_IGNORE_DWARF }, { NULL, 0, NULL, 0 } }; - int grc = getopt_long (argc, argv, "hVMvtp:I:e:o:R:r:m:kgPc:x:D:bs:uqwl:", + int grc = getopt_long (argc, argv, "hVMvtp:I:e:o:R:r:m:kgPc:x:D:bs:uqwl:d:", long_options, NULL); if (grc < 0) break; @@ -436,6 +447,10 @@ main (int argc, char * const argv []) s.include_path.push_back (string (optarg)); break; + case 'd': + s.unwindsym_modules.insert (string (optarg)); + break; + case 'e': if (have_script) { @@ -1,5 +1,5 @@ // -*- C++ -*- -// Copyright (C) 2005-2007 Red Hat Inc. +// Copyright (C) 2005-2008 Red Hat Inc. // // This file is part of systemtap, and is free software. You can // redistribute it and/or modify it under the terms of the GNU General @@ -162,6 +162,9 @@ struct systemtap_session Dwarf_Addr sym_kprobes_text_end; Dwarf_Addr sym_stext; + // List of libdwfl module names to extract symbol/unwind data for. + std::set<std::string> unwindsym_modules; + std::set<std::string> seen_errors; unsigned num_errors () { return seen_errors.size(); } // void print_error (const parse_error& e); diff --git a/tapsets.cxx b/tapsets.cxx index 96999d26..54b951cd 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -3104,6 +3104,7 @@ dwarf_query::add_probe_point(const string& funcname, if (! bad) { + sess.unwindsym_modules.insert (module); probe = new dwarf_derived_probe(funcname, filename, line, module, reloc_section, addr, reloc_addr, *this, scope_die); results.push_back(probe); @@ -3150,7 +3151,6 @@ dwarf_query::assess_dbinfo_reqt() } - // The critical determining factor when interpreting a pattern // string is, perhaps surprisingly: "presence of a lineno". The // presence of a lineno changes the search strategy completely. @@ -4676,6 +4676,7 @@ dwarf_builder::build(systemtap_session & sess, q.statement_num_val, q.statement_num_val, q, 0); finished_results.push_back (p); + sess.unwindsym_modules.insert ("kernel"); return; } @@ -5262,6 +5263,9 @@ struct utrace_builder: public derived_probe_builder string::size_type start_pos, end_pos; string component; + // XXX: these checks should be done in terms of filesystem + // operations. + // Make sure it starts with '/'. if (path[0] != '/') throw semantic_error ("process path must start with a '/'", @@ -5288,6 +5292,8 @@ struct utrace_builder: public derived_probe_builder // Make sure it isn't relative. else if (component == "." || component == "..") throw semantic_error ("process path cannot be relative (and contain '.' or '..')", location->tok); + + sess.unwindsym_modules.insert (path); } finished_results.push_back(new utrace_derived_probe(sess, base, location, diff --git a/translate.cxx b/translate.cxx index 1782abd1..b1037fef 100644 --- a/translate.cxx +++ b/translate.cxx @@ -4395,9 +4395,24 @@ get_symbols (Dwfl_Module *m, return DWARF_CB_OK; } -int -emit_symbol_data_from_debuginfo(systemtap_session& s, ofstream& kallsyms_out) + +void +emit_symbol_data (systemtap_session& s) { + ofstream kallsyms_out ((s.tmpdir + "/stap-symbols.h").c_str()); + s.op->newline() << "\n\n#include \"stap-symbols.h\""; + + if (s.verbose > 1) + { + std::set<std::string>::iterator it = s.unwindsym_modules.begin(); + clog << "unwindsym modules: "; + while (it != s.unwindsym_modules.end()) + { + clog << *(it++) << " "; + } + clog << endl; + } + static char debuginfo_path_arr[] = "-:.debug:/usr/lib/debug:build"; static char *debuginfo_env_arr = getenv("SYSTEMTAP_DEBUGINFO_PATH"); @@ -4412,75 +4427,31 @@ emit_symbol_data_from_debuginfo(systemtap_session& s, ofstream& kallsyms_out) & debuginfo_path }; - Dwfl *dwfl = dwfl_begin (&kernel_callbacks); - if (!dwfl) - throw semantic_error ("cannot open dwfl"); - dwfl_report_begin (dwfl); - - int rc = dwfl_linux_kernel_report_offline (dwfl, - s.kernel_release.c_str(), - kernel_filter); - dwfl_report_end (dwfl, NULL, NULL); - if (rc < 0) - return rc; - - dwfl_getmodules (dwfl, &get_symbols, NULL, 0); - dwfl_end(dwfl); - - int i = 0; - map< Dwarf_Addr, string>::iterator pos; - kallsyms_out << "struct _stp_symbol _stp_kernel_symbols [] = {"; - for (pos = addrmap.begin(); pos != addrmap.end(); pos++) { - kallsyms_out << " { 0x" << hex << pos->first << ", " << "\"" << pos->second << "\" },\n"; - i++; - } - - kallsyms_out << "};\n"; - kallsyms_out << "unsigned _stp_num_kernel_symbols = " << dec << i << ";\n"; - return i == 0; -} - -int -emit_symbol_data (systemtap_session& s) -{ - unsigned i=0; - char kallsyms_outbuf [4096]; - ofstream kallsyms_out ((s.tmpdir + "/stap-symbols.h").c_str()); - kallsyms_out.rdbuf()->pubsetbuf (kallsyms_outbuf, - sizeof(kallsyms_outbuf)); - s.op->newline() << "\n\n#include \"stap-symbols.h\""; - - // FIXME for non-debuginfo use. - if (true) { - return emit_symbol_data_from_debuginfo(s, kallsyms_out); - } else { - // For symbol-table only operation, we don't have debuginfo, - // so parse /proc/kallsyms. - - ifstream kallsyms("/proc/kallsyms"); - string lastaddr, modules_op_addr; - - kallsyms_out << "struct _stp_symbol _stp_kernel_symbols [] = {"; - while (! kallsyms.eof()) - { - string addr, type, sym; - kallsyms >> addr >> type >> sym >> ws; - - if (kallsyms.peek() == '[') - break; - - // NB: kallsyms includes some duplicate addresses - if ((type == "t" || type == "T" || type == "A" || sym == "modules_op") && lastaddr != addr) - { - kallsyms_out << " { 0x" << addr << ", " << "\"" << sym << "\" },\n"; - lastaddr = addr; - i ++; - } - } - kallsyms_out << "};\n"; - kallsyms_out << "unsigned _stp_num_kernel_symbols = " << i << ";\n"; + Dwfl *dwfl = dwfl_begin (&kernel_callbacks); + if (!dwfl) + throw semantic_error ("cannot open dwfl"); + dwfl_report_begin (dwfl); + + int rc = dwfl_linux_kernel_report_offline (dwfl, + s.kernel_release.c_str(), + kernel_filter); + dwfl_report_end (dwfl, NULL, NULL); + if (rc < 0) + throw semantic_error ("dwfl rc"); + + dwfl_getmodules (dwfl, &get_symbols, NULL, 0); + dwfl_end(dwfl); + + int i = 0; + map< Dwarf_Addr, string>::iterator pos; + kallsyms_out << "struct _stp_symbol _stp_kernel_symbols [] = {"; + for (pos = addrmap.begin(); pos != addrmap.end(); pos++) { + kallsyms_out << " { 0x" << hex << pos->first << ", " << "\"" << pos->second << "\" },\n"; + i++; } - return (i == 0); + + kallsyms_out << "};\n"; + kallsyms_out << "unsigned _stp_num_kernel_symbols = " << dec << i << ";\n"; } @@ -4643,16 +4614,16 @@ translate_pass (systemtap_session& s) s.up->emit_global_param (s.globals[i]); } - s.op->newline() << "MODULE_DESCRIPTION(\"systemtap probe\");"; - s.op->newline() << "MODULE_LICENSE(\"GPL\");"; // XXX + emit_symbol_data (s); + + s.op->newline() << "MODULE_DESCRIPTION(\"systemtap-generated probe\");"; + s.op->newline() << "MODULE_LICENSE(\"GPL\");"; } catch (const semantic_error& e) { s.print_error (e); } - rc |= emit_symbol_data (s); - s.op->line() << "\n"; delete s.op; |