From 8af41ec2646fb9fa30ee95eb27dff626be11b1dc Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 11 Aug 2011 18:53:01 +0200 Subject: [PATCH] Be more explicit about when the session needs symbol data. pragma:symbols. Introduce /* pragma:symbols */ which is added to those tapset functions that use print_addr or print_stack with symbol resolving. Now we no longer have to output the symbol tables at translate time if unnecessary. Although we could do even less work (see the new comment in translate.cxx). --- elaborate.cxx | 17 +++++++++++++---- session.cxx | 2 ++ session.h | 1 + tapset/context-symbols.stp | 17 ++++++----------- tapset/context-unwind.stp | 11 ++++------- tapset/ucontext-symbols.stp | 14 ++++---------- tapset/ucontext-unwind.stp | 12 +++--------- translate.cxx | 31 +++++++++++++++++++------------ 8 files changed, 52 insertions(+), 53 deletions(-) diff --git a/elaborate.cxx b/elaborate.cxx index d137cc5c1..486c508ff 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -1201,8 +1201,8 @@ semantic_pass_conditions (systemtap_session & sess) // necessary initialization of code needed by the embedded code functions. // This is only for pragmas that don't have any other side-effect than -// needing some initialization at module init time. Currently only handles -// /* pragma:vma */ and /* pragma:unwind */. +// needing some initialization at module init time. Currently handles +// /* pragma:vma */ /* pragma:unwind */ /* pragma:symbol */ // /* pragma:uprobes */ is handled during the typeresolution_info pass. // /* pure */, /* unprivileged */. /* myproc-unprivileged */ and /* guru */ @@ -1233,8 +1233,17 @@ public: if (session.verbose > 2) clog << _F("Turning on unwind support, pragma:unwind found in %s", current_function->name.c_str()) << endl; - session.need_unwind = true; - } + session.need_unwind = true; + } + + if (! session.need_symbols + && c->code.find("/* pragma:symbols */") != string::npos) + { + if (session.verbose > 2) + clog << _F("Turning on symbol data collecting, pragma:symbols found in %s", + current_function->name.c_str()) << endl; + session.need_symbols = true; + } } }; diff --git a/session.cxx b/session.cxx index b54ea3866..b875f30df 100644 --- a/session.cxx +++ b/session.cxx @@ -124,6 +124,7 @@ systemtap_session::systemtap_session (): tapset_compile_coverage = false; need_uprobes = false; need_unwind = false; + need_symbols = false; uprobes_path = ""; consult_symtab = false; ignore_vmlinux = false; @@ -284,6 +285,7 @@ systemtap_session::systemtap_session (const systemtap_session& other, tapset_compile_coverage = other.tapset_compile_coverage; need_uprobes = false; need_unwind = false; + need_symbols = false; uprobes_path = ""; consult_symtab = other.consult_symtab; ignore_vmlinux = other.ignore_vmlinux; diff --git a/session.h b/session.h index 9845d4c50..30db53ee2 100644 --- a/session.h +++ b/session.h @@ -170,6 +170,7 @@ public: bool tapset_compile_coverage; bool need_uprobes; bool need_unwind; + bool need_symbols; std::string uprobes_path; std::string uprobes_hash; bool load_only; // flight recorder mode diff --git a/tapset/context-symbols.stp b/tapset/context-symbols.stp index e20cf3ed1..64401f69f 100644 --- a/tapset/context-symbols.stp +++ b/tapset/context-symbols.stp @@ -1,5 +1,5 @@ // context-symbols tapset -// Copyright (C) 2005-2008 Red Hat Inc. +// Copyright (C) 2005-2008, 2011 Red Hat Inc. // Copyright (C) 2006 Intel Corporation. // // This file is part of systemtap, and is free software. You can @@ -11,11 +11,6 @@ //provide information such as a backtrace to where the event occurred and the current register values for the //processor. // -%{ -#ifndef STP_NEED_SYMBOL_DATA -#define STP_NEED_SYMBOL_DATA 1 -#endif -%} /** * sfunction print_stack - Print out kernel stack from string @@ -30,7 +25,7 @@ * name of the function containing the address, and an estimate of * its position within that function. Return nothing. */ -function print_stack(stk:string) %{ +function print_stack(stk:string) %{ /* pragma:symbols */ char *ptr = THIS->stk; char *tok = strsep(&ptr, " "); while (tok && *tok) { @@ -57,7 +52,7 @@ function print_stack(stk:string) %{ * truncated to MAXSTRINGLEN, to print fuller and richer stacks use * print_stack. */ -function sprint_stack:string(stk:string) %{ /* pure */ +function sprint_stack:string(stk:string) %{ /* pure */ /* pragma:symbols */ char *ptr = THIS->stk; char *tok = strsep(&ptr, " "); char *str = THIS->__retvalue; @@ -87,7 +82,7 @@ function sprint_stack:string(stk:string) %{ /* pure */ * usymname(). This function might return a function name based on the * current address if the probe point context couldn't be parsed. */ -function probefunc:string () %{ /* pure */ +function probefunc:string () %{ /* pure */ /* pragma:symbols */ char *ptr, *start; start = strstr(CONTEXT->probe_point, "function(\""); @@ -173,7 +168,7 @@ function modname:string (addr: long) %{ /* pure */ * given address if known. If not known it will return the hex string * representation of addr. */ -function symname:string (addr: long) %{ /* pure */ +function symname:string (addr: long) %{ /* pure */ /* pragma:symbols */ _stp_snprint_addr(THIS->__retvalue, MAXSTRINGLEN, THIS->addr, _STP_SYM_SYMBOL, NULL); %} @@ -190,7 +185,7 @@ function symname:string (addr: long) %{ /* pure */ * omitted and if the symbol name is unknown it will return the hex * string for the given address. */ -function symdata:string (addr: long) %{ /* pure */ +function symdata:string (addr: long) %{ /* pure */ /* pragma:symbols */ _stp_snprint_addr(THIS->__retvalue, MAXSTRINGLEN, THIS->addr, _STP_SYM_DATA, NULL); %} diff --git a/tapset/context-unwind.stp b/tapset/context-unwind.stp index fb25555ad..441f0c0b0 100644 --- a/tapset/context-unwind.stp +++ b/tapset/context-unwind.stp @@ -11,11 +11,6 @@ //provide information such as a backtrace to where the event occurred and the current register values for the //processor. // -%{ -#ifndef STP_NEED_SYMBOL_DATA -#define STP_NEED_SYMBOL_DATA 1 -#endif -%} /** * sfunction print_backtrace - Print stack back trace @@ -24,7 +19,8 @@ * except that deeper stack nesting may be supported. * The function does not return a value. */ -function print_backtrace () %{ /* pragma:unwind */ +function print_backtrace () %{ + /* pragma:unwind */ /* pragma:symbols */ _stp_stack_print(CONTEXT, _STP_SYM_FULL, _STP_STACK_KERNEL); %} @@ -43,7 +39,8 @@ function print_backtrace () %{ /* pragma:unwind */ * but more efficient (no need to translate between hex strings and * final backtrace string). */ -function sprint_backtrace:string () %{ /* pure */ /* pragma:unwind */ +function sprint_backtrace:string () %{ + /* pure */ /* pragma:unwind */ /* pragma:symbols */ _stp_stack_sprint (THIS->__retvalue, MAXSTRINGLEN, CONTEXT, _STP_SYM_SIMPLE, _STP_STACK_KERNEL); %} diff --git a/tapset/ucontext-symbols.stp b/tapset/ucontext-symbols.stp index fe3d442b7..4d9acc6a6 100644 --- a/tapset/ucontext-symbols.stp +++ b/tapset/ucontext-symbols.stp @@ -13,12 +13,6 @@ // the function symbol of an address. // -%{ -#ifndef STP_NEED_SYMBOL_DATA -#define STP_NEED_SYMBOL_DATA 1 -#endif -%} - /** * sfunction usymname - Return the symbol of an address in the current task. EXPERIMENTAL! * @addr: The address to translate. @@ -28,7 +22,7 @@ * representation of addr. */ function usymname:string (addr: long) %{ -/* pure */ /* myproc-unprivileged */ /* pragma:vma */ +/* pure */ /* myproc-unprivileged */ /* pragma:vma */ /* pragma:symbols */ _stp_snprint_addr(THIS->__retvalue, MAXSTRINGLEN, THIS->addr, _STP_SYM_SYMBOL, current); %} @@ -46,7 +40,7 @@ function usymname:string (addr: long) %{ * unknown it will return the hex string for the given address. */ function usymdata:string (addr: long) %{ -/* pure */ /* myproc-unprivileged */ /* pragma:vma */ +/* pure */ /* myproc-unprivileged */ /* pragma:vma */ /* pragma:symbols */ _stp_snprint_addr(THIS->__retvalue, MAXSTRINGLEN, THIS->addr, _STP_SYM_DATA, current); %} @@ -64,7 +58,7 @@ function usymdata:string (addr: long) %{ * its position within that function. Return nothing. */ function print_ustack(stk:string) %{ -/* myproc-unprivileged */ /* pragma:vma */ +/* myproc-unprivileged */ /* pragma:vma */ /* pragma:symbols */ char *ptr = THIS->stk; char *tok = strsep(&ptr, " "); while (tok && *tok) { @@ -92,7 +86,7 @@ function print_ustack(stk:string) %{ * truncated to MAXSTRINGLEN, to print fuller and richer stacks use * print_ustack. */ -function sprint_ustack:string(stk:string) %{ /* pure */ +function sprint_ustack:string(stk:string) %{ /* pure */ /* pragma:symbols */ char *ptr = THIS->stk; char *tok = strsep(&ptr, " "); char *str = THIS->__retvalue; diff --git a/tapset/ucontext-unwind.stp b/tapset/ucontext-unwind.stp index 99178c547..f85ab940a 100644 --- a/tapset/ucontext-unwind.stp +++ b/tapset/ucontext-unwind.stp @@ -6,12 +6,6 @@ // Public License (GPL); either version 2, or (at your option) any // later version. -%{ -#ifndef STP_NEED_SYMBOL_DATA -#define STP_NEED_SYMBOL_DATA 1 -#endif -%} - /** * sfunction print_ubacktrace - Print stack back trace for current task. EXPERIMENTAL! * @@ -22,7 +16,7 @@ * shared libraries not mentioned in the current script run stap with * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data. */ -function print_ubacktrace () %{ /* pragma:unwind */ +function print_ubacktrace () %{ /* pragma:unwind */ /* pragma:symbols */ /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */ _stp_stack_print(CONTEXT, _STP_SYM_FULL, _STP_STACK_USER); %} @@ -46,7 +40,7 @@ function print_ubacktrace () %{ /* pragma:unwind */ * shared libraries not mentioned in the current script run stap with * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data. */ -function sprint_ubacktrace:string () %{ /* pragma:unwind */ +function sprint_ubacktrace:string () %{ /* pragma:unwind */ /* pragma:symbols */ /* pure */ /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */ _stp_stack_sprint (THIS->__retvalue, MAXSTRINGLEN, CONTEXT, _STP_SYM_SIMPLE, _STP_STACK_USER); @@ -63,7 +57,7 @@ function sprint_ubacktrace:string () %{ /* pragma:unwind */ * shared libraries not mentioned in the current script run stap with * -d /path/to/exe-or-so and/or add --ldd to load all needed unwind data. */ -function print_ubacktrace_brief () %{ /* pragma:unwind */ +function print_ubacktrace_brief () %{ /* pragma:unwind */ /* pragma:symbols */ /* myproc-unprivileged */ /* pragma:uprobes */ /* pragma:vma */ _stp_stack_print(CONTEXT, _STP_SYM_BRIEF, _STP_STACK_USER); %} diff --git a/translate.cxx b/translate.cxx index 85c697c53..f06b72b88 100644 --- a/translate.cxx +++ b/translate.cxx @@ -5075,7 +5075,11 @@ dump_unwindsyms (Dwfl_Module *m, seclist.push_back (make_pair(secname,size)); } - (addrmap[secidx])[sym_addr] = name; + // If we don't actually need the symbols then we did all + // of the above just to get the section names... we can + // probably do that in some more efficient way... + if (c->session.need_symbols) + (addrmap[secidx])[sym_addr] = name; } } } @@ -5193,19 +5197,22 @@ dump_unwindsyms (Dwfl_Module *m, << "_stp_module_" << stpmod_idx<< "_symbols_" << secidx << "[] = {\n"; // Only include symbols if they will be used - c->output << "#ifdef STP_NEED_SYMBOL_DATA\n"; - - // We write out a *sorted* symbol table, so the runtime doesn't have to sort them later. - for (addrmap_t::iterator it = addrmap[secidx].begin(); it != addrmap[secidx].end(); it++) - { - if (it->first < extra_offset) - continue; // skip symbols that occur before our chosen base address + if (c->session.need_symbols) + { - c->output << " { 0x" << hex << it->first-extra_offset << dec - << ", " << lex_cast_qstring (it->second) << " },\n"; - } + // We write out a *sorted* symbol table, so the runtime doesn't + // have to sort them later. + for (addrmap_t::iterator it = addrmap[secidx].begin(); + it != addrmap[secidx].end(); it++) + { + // skip symbols that occur before our chosen base address + if (it->first < extra_offset) + continue; - c->output << "#endif /* STP_NEED_SYMBOL_DATA */\n"; + c->output << " { 0x" << hex << it->first-extra_offset << dec + << ", " << lex_cast_qstring (it->second) << " },\n"; + } + } c->output << "};\n"; -- 2.43.5