]> sourceware.org Git - systemtap.git/blame_incremental - session.h
pre-release update-docs
[systemtap.git] / session.h
... / ...
CommitLineData
1// -*- C++ -*-
2// Copyright (C) 2005-2019 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
27extern "C" {
28#include <signal.h>
29#include <elfutils/libdw.h>
30#include <pwd.h>
31}
32
33#include "privilege.h"
34#include "util.h"
35#include "stringtable.h"
36
37/* statistical operations used with a global */
38#define STAT_OP_NONE 1 << 0
39#define STAT_OP_COUNT 1 << 1
40#define STAT_OP_SUM 1 << 2
41#define STAT_OP_MIN 1 << 3
42#define STAT_OP_MAX 1 << 4
43#define STAT_OP_AVG 1 << 5
44#define STAT_OP_VARIANCE 1 << 6
45
46// forward decls for all referenced systemtap types
47class stap_hash;
48class match_node;
49struct stapfile;
50struct vardecl;
51struct token;
52struct functiondecl;
53struct derived_probe;
54struct be_derived_probe_group;
55struct generic_kprobe_derived_probe_group;
56struct hwbkpt_derived_probe_group;
57struct perf_derived_probe_group;
58struct uprobe_derived_probe_group;
59struct utrace_derived_probe_group;
60struct itrace_derived_probe_group;
61struct task_finder_derived_probe_group;
62struct vma_tracker_derived_probe_group;
63struct timer_derived_probe_group;
64struct netfilter_derived_probe_group;
65struct profile_derived_probe_group;
66struct mark_derived_probe_group;
67struct tracepoint_derived_probe_group;
68struct hrtimer_derived_probe_group;
69struct procfs_derived_probe_group;
70struct dynprobe_derived_probe_group;
71struct python_derived_probe_group;
72struct embeddedcode;
73struct stapdfa;
74class translator_output;
75struct unparser;
76struct semantic_error;
77struct module_cache;
78struct update_visitor;
79struct compile_server_cache;
80class language_server;
81struct typeresolution_info;
82
83// XXX: a generalized form of this descriptor could be associated with
84// a vardecl instead of out here at the systemtap_session level.
85struct statistic_decl
86{
87 statistic_decl(int _stat_ops = 0)
88 : type(none),
89 linear_low(0), linear_high(0), linear_step(0), bit_shift(0),
90 stat_ops(_stat_ops)
91 {}
92 enum { none, linear, logarithmic } type;
93 int64_t linear_low;
94 int64_t linear_high;
95 int64_t linear_step;
96 int bit_shift;
97 int stat_ops;
98 bool operator==(statistic_decl const & other)
99 {
100 return type == other.type
101 && linear_low == other.linear_low
102 && linear_high == other.linear_high
103 && linear_step == other.linear_step;
104 }
105};
106
107struct macrodecl; // defined in parse.h
108
109struct parse_error: public std::runtime_error
110{
111 const token* tok;
112 bool skip_some;
113 const parse_error *chain;
114 const std::string errsrc;
115 ~parse_error () throw () {}
116 parse_error (const std::string& src, const std::string& msg):
117 runtime_error (msg), tok (0), skip_some (true), chain(0), errsrc(src) {}
118 parse_error (const std::string& src, const std::string& msg, const token* t):
119 runtime_error (msg), tok (t), skip_some (true), chain(0), errsrc(src) {}
120 parse_error (const std::string& src, const std::string& msg, bool skip):
121 runtime_error (msg), tok (0), skip_some (skip), chain(0), errsrc(src) {}
122
123 std::string errsrc_chain(void) const
124 {
125 return errsrc + (chain ? "|" + chain->errsrc_chain() : "");
126 }
127};
128
129
130struct symresolution_info;
131
132struct systemtap_session
133{
134private:
135 // disable implicit constructors by not implementing these
136 systemtap_session (const systemtap_session& other);
137 systemtap_session& operator= (const systemtap_session& other);
138
139 // copy constructor used by ::clone()
140 systemtap_session (const systemtap_session& other,
141 const std::string& arch,
142 const std::string& kern);
143
144public:
145 systemtap_session ();
146 ~systemtap_session ();
147
148 // To reset the tmp_dir
149 void create_tmp_dir();
150 void remove_tmp_dir();
151 void reset_tmp_dir();
152
153 // NB: It is very important for all of the above (and below) fields
154 // to be cleared in the systemtap_session ctor (session.cxx).
155 void setup_kernel_release (const std::string& kstr);
156 void insert_loaded_modules ();
157
158 // command line parsing
159 int parse_cmdline (int argc, char * const argv []);
160 bool parse_cmdline_runtime (const std::string& opt_runtime);
161 std::string version_string ();
162 std::pair <std::string,std::string> kernel_version_range();
163 void version ();
164 void usage (int exitcode);
165 void check_options (int argc, char * const argv []);
166 // Mark morehelp as used, otherwise LTO might optimize
167 // this one out, and testcases such as at_var_mark.exp
168 // would miss it.
169 static const char* morehelp __attribute__ ((used));
170
171 // NB: It is very important for all of the above (and below) fields
172 // to be cleared in the systemtap_session ctor (session.cxx).
173
174 // command line args
175 std::string script_file; // FILE
176 std::string cmdline_script; // -e PROGRAM
177 std::vector<std::string> additional_scripts; // -E SCRIPT
178 std::stringstream stdin_script; // stdin script (stap -)
179 bool have_script;
180 std::vector<std::string> include_path;
181 int include_arg_start;
182 std::vector<std::string> c_macros;
183 std::vector<std::string> args;
184 std::vector<bool> used_args;
185 std::vector<std::string> kbuildflags; // -B var=val
186 std::vector<std::string> globalopts; // -G var=val
187 std::vector<std::string> modinfos; // --modinfo tag=value
188
189 std::string release;
190 std::string kernel_release;
191 std::string kernel_base_release;
192 std::string kernel_build_tree;
193 std::string kernel_source_tree;
194 std::vector<std::string> kernel_extra_cflags;
195 std::map<interned_string,interned_string> kernel_config;
196 std::set<interned_string> kernel_exports;
197 std::set<interned_string> kernel_functions;
198 int parse_kernel_config ();
199 int parse_kernel_exports ();
200 int parse_kernel_functions ();
201
202 std::string sysroot;
203 std::map<std::string,std::string> sysenv;
204 bool update_release_sysroot;
205 std::string machine;
206 std::string architecture;
207 bool native_build;
208 std::string runtime_path;
209 bool runtime_specified;
210 std::string data_path;
211 std::string module_name;
212 const std::string module_filename() const;
213 std::string stapconf_name;
214 std::string output_file;
215 std::string size_option;
216 std::string cmd;
217 std::string cmd_file();
218 std::string compatible; // use (strverscmp(s.compatible.c_str(), "N.M") >= 0)
219 int target_pid;
220 int last_pass;
221 unsigned perpass_verbose[5];
222 unsigned verbose;
223 bool timing;
224 bool save_module;
225 bool save_uprobes;
226 bool modname_given;
227 bool keep_tmpdir;
228 bool guru_mode;
229 bool bulk_mode;
230 bool unoptimized;
231 bool suppress_warnings;
232 bool panic_warnings;
233 int buffer_size;
234 bool tapset_compile_coverage;
235 bool need_uprobes;
236 bool need_unwind;
237 bool need_symbols;
238 bool need_lines;
239 std::string uprobes_path;
240 std::string uprobes_hash;
241 bool load_only; // flight recorder mode
242 privilege_t privilege;
243 bool privilege_set;
244 bool systemtap_v_check;
245 bool tmpdir_opt_set;
246 bool read_stdin;
247 bool monitor;
248 int monitor_interval;
249 int timeout; // in ms
250 std::map<std::string,std::string> typequery_memo;
251
252 enum
253 { dump_none, // no dumping requested
254 dump_probe_types, // dump standard tapset probes
255 dump_probe_aliases, // dump tapset probe aliases
256 dump_functions, // dump tapset functions
257 dump_matched_probes, // dump matching probes (-l)
258 dump_matched_probes_vars // dump matching probes and their variables (-L)
259 } dump_mode;
260
261 // Pattern to match against in listing mode (-l/-L)
262 std::string dump_matched_pattern;
263
264 int download_dbinfo;
265 bool suppress_handler_errors;
266 bool suppress_time_limits;
267 bool color_errors;
268 bool interactive_mode;
269 bool run_example;
270 bool no_global_var_display;
271 bool pass_1a_complete;
272
273 enum { color_never, color_auto, color_always } color_mode;
274 enum { prologue_searching_never, prologue_searching_auto, prologue_searching_always } prologue_searching_mode;
275
276 enum { kernel_runtime, dyninst_runtime, bpf_runtime } runtime_mode;
277 bool runtime_usermode_p() const { return runtime_mode == dyninst_runtime; }
278 bool use_bpf_raw_tracepoint;
279
280 // NB: It is very important for all of the above (and below) fields
281 // to be cleared in the systemtap_session ctor (session.cxx).
282
283 // Client/server
284#if HAVE_NSS
285 static bool NSPR_Initialized; // only once for all sessions
286 void NSPR_init ();
287#endif
288 bool client_options;
289 std::string client_options_disallowed_for_unprivileged;
290 std::vector<std::string> server_status_strings;
291 std::vector<std::string> specified_servers;
292 std::string server_trust_spec;
293 std::vector<std::string> server_args;
294 std::string winning_server;
295 compile_server_cache* server_cache;
296 std::vector<std::string> mok_fingerprints;
297 std::string auto_privilege_level_msg;
298 std::vector<std::string> auto_server_msgs;
299
300 bool modules_must_be_signed();
301 void get_mok_info();
302
303 bool module_sign_given;
304 std::string module_sign_mok_path;
305
306 // NB: It is very important for all of the above (and below) fields
307 // to be cleared in the systemtap_session ctor (session.cxx).
308
309 // Mechanism for retrying compilation with a compile server should it fail due
310 // to lack of resources on the local host.
311 // Once it has been decided not to try the server (e.g. syntax error),
312 // that decision cannot be changed.
313 int try_server_status;
314 bool use_server_on_error;
315
316 enum { try_server_unset, dont_try_server, do_try_server };
317 void init_try_server ();
318 void set_try_server (int t = do_try_server);
319 bool try_server () const { return try_server_status == do_try_server; }
320
321 // HTTP client/server
322 std::vector<std::string> http_servers;
323
324 // NB: It is very important for all of the above (and below) fields
325 // to be cleared in the systemtap_session ctor (session.cxx).
326
327 // Remote execution
328 std::vector<std::string> remote_uris;
329 bool use_remote_prefix;
330 typedef std::map<std::pair<std::string, std::string>, systemtap_session*> session_map_t;
331 session_map_t subsessions;
332 systemtap_session* clone(const std::string& arch, const std::string& release);
333
334 // NB: It is very important for all of the above (and below) fields
335 // to be cleared in the systemtap_session ctor (session.cxx).
336
337 // Cache data
338 bool use_cache; // control all caching
339 bool use_script_cache; // control caching of pass-3/4 output
340 bool poison_cache; // consider the cache to be write-only
341 std::string cache_path; // usually ~/.systemtap/cache
342 std::string hash_path; // path to the cached script module
343 std::string stapconf_path; // path to the cached stapconf
344 stap_hash *base_hash; // hash common to all caching
345
346 // Skip bad $ vars
347 bool skip_badvars;
348
349 // NB: It is very important for all of the above (and below) fields
350 // to be cleared in the systemtap_session ctor (session.cxx).
351
352 // temporary directory for module builds etc.
353 // hazardous - it is "rm -rf"'d at exit
354 std::string tmpdir;
355 std::string translated_source; // main C source code
356 std::string symbols_source; // C source code for stap_symbols.c
357
358 match_node* pattern_root;
359 void register_library_aliases();
360
361 // data for various preprocessor library macros
362 std::map<std::string, macrodecl*> library_macros;
363
364 // parse trees for the various script files
365 std::vector<stapfile*> user_files;
366 std::vector<stapfile*> library_files;
367
368 std::string script_name(); // usually user_files[0]->name
369 std::string script_basename(); // basename of script_name()
370
371 // filters to run over all code before symbol resolution
372 // e.g. @cast expansion
373 std::vector<update_visitor*> code_filters;
374
375 // resolved globals/functions/probes for the run as a whole
376 std::vector<stapfile*> files;
377 std::vector<vardecl*> globals;
378 std::map<std::string,functiondecl*> functions;
379 std::map<std::string,unsigned> overload_count;
380 // probe counter name -> probe associated with counter
381 std::vector<std::pair<std::string,std::string> > perf_counters;
382 std::vector<derived_probe*> probes; // see also *_probes groups below
383 std::vector<embeddedcode*> embeds;
384 std::map<interned_string, statistic_decl> stat_decls;
385 // track things that are removed
386 std::vector<vardecl*> unused_globals;
387 std::vector<derived_probe*> unused_probes; // see also *_probes groups below
388 std::vector<functiondecl*> unused_functions;
389 std::set<derived_probe*> empty_probes;
390
391 // resolved/compiled regular expressions for the run
392 std::map<std::string, stapdfa*> dfas;
393 unsigned dfa_counter; // used to give unique names
394 unsigned dfa_maxmap; // used for subexpression-tracking data structure
395 unsigned dfa_maxtag; // ditto
396 bool need_tagged_dfa; // triggered by /* pragma:tagged_dfa */
397
398 // Every probe in these groups must also appear in the
399 // session.probes vector.
400 be_derived_probe_group* be_derived_probes;
401 generic_kprobe_derived_probe_group* generic_kprobe_derived_probes;
402 hwbkpt_derived_probe_group* hwbkpt_derived_probes;
403 perf_derived_probe_group* perf_derived_probes;
404 uprobe_derived_probe_group* uprobe_derived_probes;
405 utrace_derived_probe_group* utrace_derived_probes;
406 itrace_derived_probe_group* itrace_derived_probes;
407 task_finder_derived_probe_group* task_finder_derived_probes;
408 vma_tracker_derived_probe_group* vma_tracker_derived_probes;
409 timer_derived_probe_group* timer_derived_probes;
410 netfilter_derived_probe_group* netfilter_derived_probes;
411 profile_derived_probe_group* profile_derived_probes;
412 mark_derived_probe_group* mark_derived_probes;
413 tracepoint_derived_probe_group* tracepoint_derived_probes;
414 hrtimer_derived_probe_group* hrtimer_derived_probes;
415 procfs_derived_probe_group* procfs_derived_probes;
416 dynprobe_derived_probe_group* dynprobe_derived_probes;
417 python_derived_probe_group* python_derived_probes;
418
419 // NB: It is very important for all of the above (and below) fields
420 // to be cleared in the systemtap_session ctor (session.cxx).
421
422 // unparser data
423 translator_output* op;
424 std::vector<translator_output*> auxiliary_outputs;
425 unparser* up;
426
427 // some symbol addresses
428 // XXX: these belong elsewhere; perhaps the dwflpp instance
429 Dwarf_Addr sym_kprobes_text_start;
430 Dwarf_Addr sym_kprobes_text_end;
431 Dwarf_Addr sym_stext;
432
433 // List of libdwfl module names to extract symbol/unwind data for.
434 std::set<std::string> unwindsym_modules;
435 bool unwindsym_ldd;
436 struct module_cache* module_cache;
437 std::vector<std::string> build_ids;
438
439 // Secret benchmarking options
440 unsigned long benchmark_sdt_loops;
441 unsigned long benchmark_sdt_threads;
442
443 // NB: It is very important for all of the above (and below) fields
444 // to be cleared in the systemtap_session ctor (session.cxx).
445
446 std::set<std::string> seen_warnings;
447 int suppressed_warnings;
448 std::map<std::string, int> seen_errors; // NB: can change to a set if threshold is 1
449 int suppressed_errors;
450 int warningerr_count; // see comment in systemtap_session::print_error
451
452 // Returns number of critical errors (not counting those part of warnings)
453 unsigned num_errors ()
454 {
455 return (seen_errors.size() // all the errors we've encountered
456 - warningerr_count // except those considered warningerrs
457 + (panic_warnings ? seen_warnings.size() : 0)); // plus warnings if -W given
458 }
459
460 std::set<std::string> rpms_checked; // enlisted by filename+rpm_type
461 std::set<std::string> rpms_to_install; // resulting rpms
462
463 translator_output* op_create_auxiliary(bool trailer_p = false);
464
465 int target_namespaces_pid;
466
467 unsigned suppress_costly_diagnostics; /* set during processing of optional probes */
468
469 const token* last_token;
470
471 // Used during the -semantic pass- for tabulating still-unresolved counts
472 typeresolution_info* type_res_info;
473
474 void print_token (std::ostream& o, const token* tok);
475 void print_error (const semantic_error& e);
476 std::string build_error_msg (const semantic_error& e);
477 void print_error_source (std::ostream&, std::string&, const token* tok);
478 void print_error_details (std::ostream&, std::string&, const semantic_error&);
479 void print_error (const parse_error &pe,
480 const token* tok,
481 const std::string &input_name,
482 bool is_warningerr = false);
483 std::string build_error_msg (const parse_error &pe,
484 const token* tok,
485 const std::string &input_name);
486 void print_warning (const std::string& w, const token* tok = 0);
487 void printscript(std::ostream& o);
488 void report_suppression();
489
490 // PR25841, for early probe-derivation-time symbol resolution
491 symresolution_info* symbol_resolver; // may be NULL
492
493 bool language_server_mode;
494 language_server* lang_server;
495
496 std::string build_as;
497 uid_t build_as_uid;
498 gid_t build_as_gid;
499
500 // NB: It is very important for all of the above (and below) fields
501 // to be cleared in the systemtap_session ctor (session.cxx).
502
503 std::string colorize(const std::string& str, const std::string& type);
504 std::string colorize(const token* tok);
505 std::string parse_stap_color(const std::string& type);
506
507 // Some automatic options settings require explanation.
508 void enable_auto_server (const std::string &message);
509 void explain_auto_options();
510
511 bool is_user_file (const std::string& name);
512 bool is_primary_probe (derived_probe *dp);
513
514 void clear_script_data();
515
516 // NB: It is very important for all of the above (and below) fields
517 // to be cleared in the systemtap_session ctor (session.cxx).
518};
519
520struct exit_exception: public std::runtime_error
521{
522 int rc;
523 exit_exception (int rc):
524 runtime_error (_F("early exit requested, rc=%d", rc)), rc(rc) {}
525};
526
527
528// global counter of SIGINT/SIGTERM's received
529extern int pending_interrupts;
530
531// Interrupt exception subclass for catching
532// interrupts (i.e. ctrl-c).
533struct interrupt_exception: public std::runtime_error
534{
535 interrupt_exception ():
536 runtime_error (_("interrupt received")){}
537};
538
539void assert_no_interrupts();
540
541#endif // SESSION_H
542
543/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.026776 seconds and 6 git commands to generate.