2 // Copyright (C) 2005-2015 Red Hat Inc.
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
29 #include <elfutils/libdw.h>
32 #include "privilege.h"
34 #include "stringtable.h"
36 // forward decls for all referenced systemtap types
44 struct be_derived_probe_group
;
45 struct generic_kprobe_derived_probe_group
;
46 struct hwbkpt_derived_probe_group
;
47 struct perf_derived_probe_group
;
48 struct uprobe_derived_probe_group
;
49 struct utrace_derived_probe_group
;
50 struct itrace_derived_probe_group
;
51 struct task_finder_derived_probe_group
;
52 struct timer_derived_probe_group
;
53 struct netfilter_derived_probe_group
;
54 struct profile_derived_probe_group
;
55 struct mark_derived_probe_group
;
56 struct tracepoint_derived_probe_group
;
57 struct hrtimer_derived_probe_group
;
58 struct procfs_derived_probe_group
;
59 struct dynprobe_derived_probe_group
;
62 class translator_output
;
64 struct semantic_error
;
66 struct update_visitor
;
67 struct compile_server_cache
;
69 // XXX: a generalized form of this descriptor could be associated with
70 // a vardecl instead of out here at the systemtap_session level.
75 linear_low(0), linear_high(0), linear_step(0)
77 enum { none
, linear
, logarithmic
} type
;
81 bool operator==(statistic_decl
const & other
)
83 return type
== other
.type
84 && linear_low
== other
.linear_low
85 && linear_high
== other
.linear_high
86 && linear_step
== other
.linear_step
;
90 struct macrodecl
; // defined in parse.h
92 struct parse_error
: public std::runtime_error
96 const parse_error
*chain
;
97 const std::string errsrc
;
98 ~parse_error () throw () {}
99 parse_error (const std::string
& src
, const std::string
& msg
):
100 runtime_error (msg
), tok (0), skip_some (true), chain(0), errsrc(src
) {}
101 parse_error (const std::string
& src
, const std::string
& msg
, const token
* t
):
102 runtime_error (msg
), tok (t
), skip_some (true), chain(0), errsrc(src
) {}
103 parse_error (const std::string
& src
, const std::string
& msg
, bool skip
):
104 runtime_error (msg
), tok (0), skip_some (skip
), chain(0), errsrc(src
) {}
106 std::string
errsrc_chain(void) const
108 return errsrc
+ (chain
? "|" + chain
->errsrc_chain() : "");
112 struct systemtap_session
115 // disable implicit constructors by not implementing these
116 systemtap_session (const systemtap_session
& other
);
117 systemtap_session
& operator= (const systemtap_session
& other
);
119 // copy constructor used by ::clone()
120 systemtap_session (const systemtap_session
& other
,
121 const std::string
& arch
,
122 const std::string
& kern
);
125 systemtap_session ();
126 ~systemtap_session ();
128 // To reset the tmp_dir
129 void create_tmp_dir();
130 void remove_tmp_dir();
131 void reset_tmp_dir();
133 // NB: It is very important for all of the above (and below) fields
134 // to be cleared in the systemtap_session ctor (session.cxx).
135 void setup_kernel_release (const char* kstr
);
136 void insert_loaded_modules ();
138 // command line parsing
139 int parse_cmdline (int argc
, char * const argv
[]);
140 bool parse_cmdline_runtime (const std::string
& opt_runtime
);
141 std::string
version_string ();
143 void usage (int exitcode
);
144 void check_options (int argc
, char * const argv
[]);
145 static const char* morehelp
;
147 // NB: It is very important for all of the above (and below) fields
148 // to be cleared in the systemtap_session ctor (session.cxx).
151 std::string script_file
; // FILE
152 std::string cmdline_script
; // -e PROGRAM
153 std::vector
<std::string
> additional_scripts
; // -E SCRIPT
155 std::vector
<std::string
> include_path
;
156 int include_arg_start
;
157 std::vector
<std::string
> c_macros
;
158 std::vector
<std::string
> args
;
159 std::vector
<std::string
> kbuildflags
; // -B var=val
160 std::vector
<std::string
> globalopts
; // -G var=val
161 std::vector
<std::string
> modinfos
; // --modinfo tag=value
164 std::string kernel_release
;
165 std::string kernel_base_release
;
166 std::string kernel_build_tree
;
167 std::string kernel_source_tree
;
168 std::vector
<std::string
> kernel_extra_cflags
;
169 std::map
<interned_string
,interned_string
> kernel_config
;
170 std::set
<interned_string
> kernel_exports
;
171 std::set
<interned_string
> kernel_functions
;
172 int parse_kernel_config ();
173 int parse_kernel_exports ();
174 int parse_kernel_functions ();
177 std::map
<std::string
,std::string
> sysenv
;
178 bool update_release_sysroot
;
180 std::string architecture
;
182 std::string runtime_path
;
183 bool runtime_specified
;
184 std::string data_path
;
185 std::string module_name
;
186 const std::string
module_filename() const;
187 std::string stapconf_name
;
188 std::string output_file
;
189 std::string size_option
;
191 std::string
cmd_file();
192 std::string compatible
; // use (strverscmp(s.compatible.c_str(), "N.M") >= 0)
195 unsigned perpass_verbose
[5];
205 bool suppress_warnings
;
208 bool tapset_compile_coverage
;
213 std::string uprobes_path
;
214 std::string uprobes_hash
;
215 bool load_only
; // flight recorder mode
216 privilege_t privilege
;
218 bool systemtap_v_check
;
221 int monitor_interval
;
222 int timeout
; // in ms
225 { dump_none
, // no dumping requested
226 dump_probe_types
, // dump standard tapset probes
227 dump_probe_aliases
, // dump tapset probe aliases
228 dump_functions
, // dump tapset functions
229 dump_matched_probes
, // dump matching probes (-l)
230 dump_matched_probes_vars
// dump matching probes and their variables (-L)
233 // Pattern to match against in listing mode (-l/-L)
234 std::string dump_matched_pattern
;
237 bool suppress_handler_errors
;
238 bool suppress_time_limits
;
240 bool interactive_mode
;
241 bool pass_1a_complete
;
243 enum { color_never
, color_auto
, color_always
} color_mode
;
244 enum { prologue_searching_never
, prologue_searching_auto
, prologue_searching_always
} prologue_searching_mode
;
246 enum { kernel_runtime
, dyninst_runtime
} runtime_mode
;
247 bool runtime_usermode_p() const { return runtime_mode
== dyninst_runtime
; }
249 // NB: It is very important for all of the above (and below) fields
250 // to be cleared in the systemtap_session ctor (session.cxx).
254 static bool NSPR_Initialized
; // only once for all sessions
258 std::string client_options_disallowed_for_unprivileged
;
259 std::vector
<std::string
> server_status_strings
;
260 std::vector
<std::string
> specified_servers
;
261 std::string server_trust_spec
;
262 std::vector
<std::string
> server_args
;
263 std::string winning_server
;
264 compile_server_cache
* server_cache
;
265 std::vector
<std::string
> mok_fingerprints
;
266 std::string auto_privilege_level_msg
;
267 std::vector
<std::string
> auto_server_msgs
;
269 bool modules_must_be_signed();
272 // NB: It is very important for all of the above (and below) fields
273 // to be cleared in the systemtap_session ctor (session.cxx).
275 // Mechanism for retrying compilation with a compile server should it fail due
276 // to lack of resources on the local host.
277 // Once it has been decided not to try the server (e.g. syntax error),
278 // that decision cannot be changed.
279 int try_server_status
;
280 bool use_server_on_error
;
282 enum { try_server_unset
, dont_try_server
, do_try_server
};
283 void init_try_server ();
284 void set_try_server (int t
= do_try_server
);
285 bool try_server () const { return try_server_status
== do_try_server
; }
287 // NB: It is very important for all of the above (and below) fields
288 // to be cleared in the systemtap_session ctor (session.cxx).
291 std::vector
<std::string
> remote_uris
;
292 bool use_remote_prefix
;
293 typedef std::map
<std::pair
<std::string
, std::string
>, systemtap_session
*> session_map_t
;
294 session_map_t subsessions
;
295 systemtap_session
* clone(const std::string
& arch
, const std::string
& release
);
297 // NB: It is very important for all of the above (and below) fields
298 // to be cleared in the systemtap_session ctor (session.cxx).
301 bool use_cache
; // control all caching
302 bool use_script_cache
; // control caching of pass-3/4 output
303 bool poison_cache
; // consider the cache to be write-only
304 std::string cache_path
; // usually ~/.systemtap/cache
305 std::string hash_path
; // path to the cached script module
306 std::string stapconf_path
; // path to the cached stapconf
307 stap_hash
*base_hash
; // hash common to all caching
312 // NB: It is very important for all of the above (and below) fields
313 // to be cleared in the systemtap_session ctor (session.cxx).
315 // temporary directory for module builds etc.
316 // hazardous - it is "rm -rf"'d at exit
318 std::string translated_source
; // C source code
320 match_node
* pattern_root
;
321 void register_library_aliases();
323 // data for various preprocessor library macros
324 std::map
<std::string
, macrodecl
*> library_macros
;
326 // parse trees for the various script files
327 std::vector
<stapfile
*> user_files
;
328 std::vector
<stapfile
*> library_files
;
330 // filters to run over all code before symbol resolution
331 // e.g. @cast expansion
332 std::vector
<update_visitor
*> code_filters
;
334 // resolved globals/functions/probes for the run as a whole
335 std::vector
<stapfile
*> files
;
336 std::vector
<vardecl
*> globals
;
337 std::map
<std::string
,functiondecl
*> functions
;
338 std::map
<std::string
,unsigned> overload_count
;
339 // probe counter name -> probe associated with counter
340 std::vector
<std::pair
<std::string
,std::string
> > perf_counters
;
341 std::vector
<derived_probe
*> probes
; // see also *_probes groups below
342 std::vector
<embeddedcode
*> embeds
;
343 std::map
<interned_string
, statistic_decl
> stat_decls
;
344 // track things that are removed
345 std::vector
<vardecl
*> unused_globals
;
346 std::vector
<derived_probe
*> unused_probes
; // see also *_probes groups below
347 std::vector
<functiondecl
*> unused_functions
;
349 // resolved/compiled regular expressions for the run
350 std::map
<std::string
, stapdfa
*> dfas
;
351 unsigned dfa_counter
; // used to give unique names
352 unsigned dfa_maxstate
; // used for subexpression-tracking data structure
353 unsigned dfa_maxtag
; // ditto
354 bool need_tagged_dfa
; // triggered by /* pragma:tagged_dfa */
356 // Every probe in these groups must also appear in the
357 // session.probes vector.
358 be_derived_probe_group
* be_derived_probes
;
359 generic_kprobe_derived_probe_group
* generic_kprobe_derived_probes
;
360 hwbkpt_derived_probe_group
* hwbkpt_derived_probes
;
361 perf_derived_probe_group
* perf_derived_probes
;
362 uprobe_derived_probe_group
* uprobe_derived_probes
;
363 utrace_derived_probe_group
* utrace_derived_probes
;
364 itrace_derived_probe_group
* itrace_derived_probes
;
365 task_finder_derived_probe_group
* task_finder_derived_probes
;
366 timer_derived_probe_group
* timer_derived_probes
;
367 netfilter_derived_probe_group
* netfilter_derived_probes
;
368 profile_derived_probe_group
* profile_derived_probes
;
369 mark_derived_probe_group
* mark_derived_probes
;
370 tracepoint_derived_probe_group
* tracepoint_derived_probes
;
371 hrtimer_derived_probe_group
* hrtimer_derived_probes
;
372 procfs_derived_probe_group
* procfs_derived_probes
;
373 dynprobe_derived_probe_group
* dynprobe_derived_probes
;
375 // NB: It is very important for all of the above (and below) fields
376 // to be cleared in the systemtap_session ctor (session.cxx).
379 translator_output
* op
;
380 std::vector
<translator_output
*> auxiliary_outputs
;
383 // some symbol addresses
384 // XXX: these belong elsewhere; perhaps the dwflpp instance
385 Dwarf_Addr sym_kprobes_text_start
;
386 Dwarf_Addr sym_kprobes_text_end
;
387 Dwarf_Addr sym_stext
;
389 // List of libdwfl module names to extract symbol/unwind data for.
390 std::set
<std::string
> unwindsym_modules
;
392 struct module_cache
* module_cache
;
393 std::vector
<std::string
> build_ids
;
395 // Secret benchmarking options
396 unsigned long benchmark_sdt_loops
;
397 unsigned long benchmark_sdt_threads
;
399 // NB: It is very important for all of the above (and below) fields
400 // to be cleared in the systemtap_session ctor (session.cxx).
402 std::set
<std::string
> seen_warnings
;
403 int suppressed_warnings
;
404 std::map
<std::string
, int> seen_errors
; // NB: can change to a set if threshold is 1
405 int suppressed_errors
;
406 int warningerr_count
; // see comment in systemtap_session::print_error
408 // Returns number of critical errors (not counting those part of warnings)
409 unsigned num_errors ()
411 return (seen_errors
.size() // all the errors we've encountered
412 - warningerr_count
// except those considered warningerrs
413 + (panic_warnings
? seen_warnings
.size() : 0)); // plus warnings if -W given
416 std::set
<std::string
> rpms_checked
; // enlisted by filename+rpm_type
417 std::set
<std::string
> rpms_to_install
; // resulting rpms
419 translator_output
* op_create_auxiliary(bool trailer_p
= false);
421 int target_namespaces_pid
;
423 const token
* last_token
;
424 void print_token (std::ostream
& o
, const token
* tok
);
425 void print_error (const semantic_error
& e
);
426 std::string
build_error_msg (const semantic_error
& e
);
427 void print_error_source (std::ostream
&, std::string
&, const token
* tok
);
428 void print_error_details (std::ostream
&, std::string
&, const semantic_error
&);
429 void print_error (const parse_error
&pe
,
431 const std::string
&input_name
,
432 bool is_warningerr
= false);
433 std::string
build_error_msg (const parse_error
&pe
,
435 const std::string
&input_name
);
436 void print_warning (const std::string
& w
, const token
* tok
= 0);
437 void printscript(std::ostream
& o
);
438 void report_suppression();
440 // NB: It is very important for all of the above (and below) fields
441 // to be cleared in the systemtap_session ctor (session.cxx).
443 std::string
colorize(const std::string
& str
, const std::string
& type
);
444 std::string
colorize(const token
* tok
);
445 std::string
parse_stap_color(const std::string
& type
);
447 // Some automatic options settings require explanation.
448 void enable_auto_server (const std::string
&message
);
449 void explain_auto_options();
451 bool is_user_file (const std::string
& name
);
452 bool is_primary_probe (derived_probe
*dp
);
454 void clear_script_data();
456 // NB: It is very important for all of the above (and below) fields
457 // to be cleared in the systemtap_session ctor (session.cxx).
460 struct exit_exception
: public std::runtime_error
463 exit_exception (int rc
):
464 runtime_error (_F("early exit requested, rc=%d", rc
)), rc(rc
) {}
468 // global counter of SIGINT/SIGTERM's received
469 extern int pending_interrupts
;
471 // Interrupt exception subclass for catching
472 // interrupts (i.e. ctrl-c).
473 struct interrupt_exception
: public std::runtime_error
475 interrupt_exception ():
476 runtime_error (_("interrupt received")){}
479 void assert_no_interrupts();
483 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */