]> sourceware.org Git - systemtap.git/blob - session.h
Fix PR20504 by updating xfs/nfs4 tracepoint support for kernel 4.7+.
[systemtap.git] / session.h
1 // -*- C++ -*-
2 // Copyright (C) 2005-2015 Red Hat Inc.
3 //
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
7 // later version.
8
9 #ifndef SESSION_H
10 #define SESSION_H
11
12 #include "config.h"
13 #if ENABLE_NLS
14 #include <libintl.h>
15 #include <locale.h>
16 #endif
17
18 #include <list>
19 #include <string>
20 #include <vector>
21 #include <iostream>
22 #include <sstream>
23 #include <map>
24 #include <set>
25 #include <stdexcept>
26
27 extern "C" {
28 #include <signal.h>
29 #include <elfutils/libdw.h>
30 }
31
32 #include "privilege.h"
33 #include "util.h"
34 #include "stringtable.h"
35
36 // forward decls for all referenced systemtap types
37 class stap_hash;
38 class match_node;
39 struct stapfile;
40 struct vardecl;
41 struct token;
42 struct functiondecl;
43 struct derived_probe;
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;
60 struct embeddedcode;
61 struct stapdfa;
62 class translator_output;
63 struct unparser;
64 struct semantic_error;
65 struct module_cache;
66 struct update_visitor;
67 struct compile_server_cache;
68
69 // XXX: a generalized form of this descriptor could be associated with
70 // a vardecl instead of out here at the systemtap_session level.
71 struct statistic_decl
72 {
73 statistic_decl()
74 : type(none),
75 linear_low(0), linear_high(0), linear_step(0)
76 {}
77 enum { none, linear, logarithmic } type;
78 int64_t linear_low;
79 int64_t linear_high;
80 int64_t linear_step;
81 bool operator==(statistic_decl const & other)
82 {
83 return type == other.type
84 && linear_low == other.linear_low
85 && linear_high == other.linear_high
86 && linear_step == other.linear_step;
87 }
88 };
89
90 struct macrodecl; // defined in parse.h
91
92 struct parse_error: public std::runtime_error
93 {
94 const token* tok;
95 bool skip_some;
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) {}
105
106 std::string errsrc_chain(void) const
107 {
108 return errsrc + (chain ? "|" + chain->errsrc_chain() : "");
109 }
110 };
111
112 struct systemtap_session
113 {
114 private:
115 // disable implicit constructors by not implementing these
116 systemtap_session (const systemtap_session& other);
117 systemtap_session& operator= (const systemtap_session& other);
118
119 // copy constructor used by ::clone()
120 systemtap_session (const systemtap_session& other,
121 const std::string& arch,
122 const std::string& kern);
123
124 public:
125 systemtap_session ();
126 ~systemtap_session ();
127
128 // To reset the tmp_dir
129 void create_tmp_dir();
130 void remove_tmp_dir();
131 void reset_tmp_dir();
132
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 ();
137
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 ();
142 void version ();
143 void usage (int exitcode);
144 void check_options (int argc, char * const argv []);
145 static const char* morehelp;
146
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).
149
150 // command line args
151 std::string script_file; // FILE
152 std::string cmdline_script; // -e PROGRAM
153 std::vector<std::string> additional_scripts; // -E SCRIPT
154 bool have_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
162
163 std::string release;
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 ();
175
176 std::string sysroot;
177 std::map<std::string,std::string> sysenv;
178 bool update_release_sysroot;
179 std::string machine;
180 std::string architecture;
181 bool native_build;
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;
190 std::string cmd;
191 std::string cmd_file();
192 std::string compatible; // use (strverscmp(s.compatible.c_str(), "N.M") >= 0)
193 int target_pid;
194 int last_pass;
195 unsigned perpass_verbose[5];
196 unsigned verbose;
197 bool timing;
198 bool save_module;
199 bool save_uprobes;
200 bool modname_given;
201 bool keep_tmpdir;
202 bool guru_mode;
203 bool bulk_mode;
204 bool unoptimized;
205 bool suppress_warnings;
206 bool panic_warnings;
207 int buffer_size;
208 bool tapset_compile_coverage;
209 bool need_uprobes;
210 bool need_unwind;
211 bool need_symbols;
212 bool need_lines;
213 std::string uprobes_path;
214 std::string uprobes_hash;
215 bool load_only; // flight recorder mode
216 privilege_t privilege;
217 bool privilege_set;
218 bool systemtap_v_check;
219 bool tmpdir_opt_set;
220 bool monitor;
221 int monitor_interval;
222 int timeout; // in ms
223
224 enum
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)
231 } dump_mode;
232
233 // Pattern to match against in listing mode (-l/-L)
234 std::string dump_matched_pattern;
235
236 int download_dbinfo;
237 bool suppress_handler_errors;
238 bool suppress_time_limits;
239 bool color_errors;
240 bool interactive_mode;
241 bool pass_1a_complete;
242
243 enum { color_never, color_auto, color_always } color_mode;
244 enum { prologue_searching_never, prologue_searching_auto, prologue_searching_always } prologue_searching_mode;
245
246 enum { kernel_runtime, dyninst_runtime } runtime_mode;
247 bool runtime_usermode_p() const { return runtime_mode == dyninst_runtime; }
248
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).
251
252 // Client/server
253 #if HAVE_NSS
254 static bool NSPR_Initialized; // only once for all sessions
255 void NSPR_init ();
256 #endif
257 bool client_options;
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;
268
269 bool modules_must_be_signed();
270 void get_mok_info();
271
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).
274
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;
281
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; }
286
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).
289
290 // Remote execution
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);
296
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).
299
300 // Cache data
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
308
309 // Skip bad $ vars
310 bool skip_badvars;
311
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).
314
315 // temporary directory for module builds etc.
316 // hazardous - it is "rm -rf"'d at exit
317 std::string tmpdir;
318 std::string translated_source; // C source code
319
320 match_node* pattern_root;
321 void register_library_aliases();
322
323 // data for various preprocessor library macros
324 std::map<std::string, macrodecl*> library_macros;
325
326 // parse trees for the various script files
327 std::vector<stapfile*> user_files;
328 std::vector<stapfile*> library_files;
329
330 // filters to run over all code before symbol resolution
331 // e.g. @cast expansion
332 std::vector<update_visitor*> code_filters;
333
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;
348
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 */
355
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;
374
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).
377
378 // unparser data
379 translator_output* op;
380 std::vector<translator_output*> auxiliary_outputs;
381 unparser* up;
382
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;
388
389 // List of libdwfl module names to extract symbol/unwind data for.
390 std::set<std::string> unwindsym_modules;
391 bool unwindsym_ldd;
392 struct module_cache* module_cache;
393 std::vector<std::string> build_ids;
394
395 // Secret benchmarking options
396 unsigned long benchmark_sdt_loops;
397 unsigned long benchmark_sdt_threads;
398
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).
401
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
407
408 // Returns number of critical errors (not counting those part of warnings)
409 unsigned num_errors ()
410 {
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
414 }
415
416 std::set<std::string> rpms_checked; // enlisted by filename+rpm_type
417 std::set<std::string> rpms_to_install; // resulting rpms
418
419 translator_output* op_create_auxiliary(bool trailer_p = false);
420
421 int target_namespaces_pid;
422
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,
430 const token* tok,
431 const std::string &input_name,
432 bool is_warningerr = false);
433 std::string build_error_msg (const parse_error &pe,
434 const token* tok,
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();
439
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).
442
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);
446
447 // Some automatic options settings require explanation.
448 void enable_auto_server (const std::string &message);
449 void explain_auto_options();
450
451 bool is_user_file (const std::string& name);
452 bool is_primary_probe (derived_probe *dp);
453
454 void clear_script_data();
455
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).
458 };
459
460 struct exit_exception: public std::runtime_error
461 {
462 int rc;
463 exit_exception (int rc):
464 runtime_error (_F("early exit requested, rc=%d", rc)), rc(rc) {}
465 };
466
467
468 // global counter of SIGINT/SIGTERM's received
469 extern int pending_interrupts;
470
471 // Interrupt exception subclass for catching
472 // interrupts (i.e. ctrl-c).
473 struct interrupt_exception: public std::runtime_error
474 {
475 interrupt_exception ():
476 runtime_error (_("interrupt received")){}
477 };
478
479 void assert_no_interrupts();
480
481 #endif // SESSION_H
482
483 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.053333 seconds and 5 git commands to generate.