]> sourceware.org Git - systemtap.git/blame - session.h
Fix rawhide compile problems in aux_syscalls.stp.
[systemtap.git] / session.h
CommitLineData
177a8ead 1// -*- C++ -*-
b3104a15 2// Copyright (C) 2005-2015 Red Hat Inc.
177a8ead
FCE
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
9456e4c1 12#include "config.h"
52c2652f 13#if ENABLE_NLS
79bc39ab
LB
14#include <libintl.h>
15#include <locale.h>
52c2652f 16#endif
9456e4c1 17
aa4d21c0 18#include <list>
177a8ead
FCE
19#include <string>
20#include <vector>
21#include <iostream>
22#include <sstream>
23#include <map>
7e41d3dc 24#include <set>
985892de 25#include <stdexcept>
177a8ead 26
1d3a40b6 27extern "C" {
2dce8c42 28#include <signal.h>
1d3a40b6
DS
29#include <elfutils/libdw.h>
30}
31
3892d516 32#include "privilege.h"
0d98c8da 33#include "util.h"
47d349b1 34#include "stringtable.h"
177a8ead
FCE
35
36// forward decls for all referenced systemtap types
dec33462 37class stap_hash;
b9aa5bb4 38class match_node;
177a8ead
FCE
39struct stapfile;
40struct vardecl;
cfd621bc 41struct token;
177a8ead 42struct functiondecl;
b20febf3
FCE
43struct derived_probe;
44struct be_derived_probe_group;
a7fbce1f 45struct generic_kprobe_derived_probe_group;
dd225250 46struct hwbkpt_derived_probe_group;
83ea76b1 47struct perf_derived_probe_group;
888af770 48struct uprobe_derived_probe_group;
935447c8 49struct utrace_derived_probe_group;
a96d1db0 50struct itrace_derived_probe_group;
935447c8 51struct task_finder_derived_probe_group;
b20febf3 52struct timer_derived_probe_group;
8d9609f5 53struct netfilter_derived_probe_group;
b20febf3
FCE
54struct profile_derived_probe_group;
55struct mark_derived_probe_group;
0a6f5a3f 56struct tracepoint_derived_probe_group;
b20febf3 57struct hrtimer_derived_probe_group;
604eef3b 58struct procfs_derived_probe_group;
f31a77f5 59struct dynprobe_derived_probe_group;
177a8ead 60struct embeddedcode;
be87f53a 61struct stapdfa;
b9aa5bb4 62class translator_output;
177a8ead
FCE
63struct unparser;
64struct semantic_error;
405b71b8 65struct module_cache;
f80d9004 66struct update_visitor;
eff14db3 67struct compile_server_cache;
177a8ead 68
177a8ead
FCE
69// XXX: a generalized form of this descriptor could be associated with
70// a vardecl instead of out here at the systemtap_session level.
71struct statistic_decl
72{
73 statistic_decl()
dff50e09 74 : type(none),
177a8ead 75 linear_low(0), linear_high(0), linear_step(0)
dff50e09 76 {}
177a8ead 77 enum { none, linear, logarithmic } type;
177a8ead
FCE
78 int64_t linear_low;
79 int64_t linear_high;
80 int64_t linear_step;
07c17d67
GH
81 bool operator==(statistic_decl const & other)
82 {
dff50e09 83 return type == other.type
07c17d67
GH
84 && linear_low == other.linear_low
85 && linear_high == other.linear_high
86 && linear_step == other.linear_step;
87 }
177a8ead
FCE
88};
89
fe410f52
SM
90struct macrodecl; // defined in parse.h
91
6b7d7185
JL
92struct parse_error: public std::runtime_error
93{
94 const token* tok;
95 bool skip_some;
78ab2de3 96 const parse_error *chain;
9e1a2390
JL
97 const std::string errsrc;
98 ~parse_error () throw () {}
f0454224
JL
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) {}
9e1a2390
JL
105
106 std::string errsrc_chain(void) const
107 {
108 return errsrc + (chain ? "|" + chain->errsrc_chain() : "");
109 }
6b7d7185
JL
110};
111
177a8ead
FCE
112struct systemtap_session
113{
abc15290
JS
114private:
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
124public:
177a8ead 125 systemtap_session ();
b0e5fa85 126 ~systemtap_session ();
aa4d21c0 127
b96901b7
CM
128 // To reset the tmp_dir
129 void create_tmp_dir();
130 void remove_tmp_dir();
131 void reset_tmp_dir();
132
28f569c2 133 // NB: It is very important for all of the above (and below) fields
85007c04 134 // to be cleared in the systemtap_session ctor (session.cxx).
e2012a7a 135 void setup_kernel_release (const char* kstr);
bb153adb 136 void insert_loaded_modules ();
e2012a7a
DB
137
138 // command line parsing
139 int parse_cmdline (int argc, char * const argv []);
45402f2a 140 bool parse_cmdline_runtime (const std::string& opt_runtime);
b58abde1 141 std::string version_string ();
e2012a7a
DB
142 void version ();
143 void usage (int exitcode);
144 void check_options (int argc, char * const argv []);
145 static const char* morehelp;
177a8ead 146
aa4d21c0 147 // NB: It is very important for all of the above (and below) fields
85007c04 148 // to be cleared in the systemtap_session ctor (session.cxx).
aa4d21c0 149
177a8ead 150 // command line args
e2012a7a
DB
151 std::string script_file; // FILE
152 std::string cmdline_script; // -e PROGRAM
ba48c27a 153 std::vector<std::string> additional_scripts; // -E SCRIPT
e2012a7a 154 bool have_script;
177a8ead 155 std::vector<std::string> include_path;
2fad97fd 156 int include_arg_start;
08fce398 157 std::vector<std::string> c_macros;
177a8ead 158 std::vector<std::string> args;
633e5ca7 159 std::vector<std::string> kbuildflags; // -B var=val
bb25d08f 160 std::vector<std::string> globalopts; // -G var=val
633e5ca7 161 std::vector<std::string> modinfos; // --modinfo tag=value
8dfad013 162
e2012a7a 163 std::string release;
177a8ead 164 std::string kernel_release;
197a4d62 165 std::string kernel_base_release;
7471ea1f 166 std::string kernel_build_tree;
d4393459 167 std::string kernel_source_tree;
ac4f2837 168 std::vector<std::string> kernel_extra_cflags;
45a63356 169 std::map<interned_string,interned_string> kernel_config;
47d349b1
FCE
170 std::set<interned_string> kernel_exports;
171 std::set<interned_string> kernel_functions;
8dfad013
JS
172 int parse_kernel_config ();
173 int parse_kernel_exports ();
2a639817 174 int parse_kernel_functions ();
8dfad013 175
05fb3e0c
WF
176 std::string sysroot;
177 std::map<std::string,std::string> sysenv;
178 bool update_release_sysroot;
e2012a7a 179 std::string machine;
44ce8ed5 180 std::string architecture;
50f2545f 181 bool native_build;
177a8ead 182 std::string runtime_path;
2fad97fd 183 bool runtime_specified;
1b78aef5 184 std::string data_path;
177a8ead 185 std::string module_name;
4441e344 186 const std::string module_filename() const;
de0db58a 187 std::string stapconf_name;
177a8ead 188 std::string output_file;
701c41be 189 std::string size_option;
177a8ead 190 std::string cmd;
48cd804a 191 std::string cmd_file();
db135493 192 std::string compatible; // use (strverscmp(s.compatible.c_str(), "N.M") >= 0)
177a8ead
FCE
193 int target_pid;
194 int last_pass;
e0b4e89d 195 unsigned perpass_verbose[5];
b0ee93c4 196 unsigned verbose;
a9e8f7e0 197 bool timing;
e2012a7a 198 bool save_module;
50f92d4e 199 bool save_uprobes;
5c854d7c 200 bool modname_given;
177a8ead
FCE
201 bool keep_tmpdir;
202 bool guru_mode;
203 bool bulk_mode;
cbfbbf69 204 bool unoptimized;
a9e8f7e0 205 bool suppress_warnings;
57a56e00 206 bool panic_warnings;
177a8ead 207 int buffer_size;
c3a3c0c9 208 bool tapset_compile_coverage;
6274464e 209 bool need_uprobes;
08badca8 210 bool need_unwind;
8af41ec2 211 bool need_symbols;
ee533a58 212 bool need_lines;
474d17ad 213 std::string uprobes_path;
7d26ee02 214 std::string uprobes_hash;
2fa2a091 215 bool load_only; // flight recorder mode
42e38653 216 privilege_t privilege;
73f52eb4 217 bool privilege_set;
a07a2c28 218 bool systemtap_v_check;
305fac7d 219 bool tmpdir_opt_set;
6120441d 220 bool monitor;
09ddc83c 221 int monitor_interval;
bba368c5
JL
222
223 enum
224 { dump_none, // no dumping requested
225 dump_probe_types, // dump standard tapset probes
226 dump_probe_aliases, // dump tapset probe aliases
227 dump_functions, // dump tapset functions
228 dump_matched_probes, // dump matching probes (-l)
229 dump_matched_probes_vars // dump matching probes and their variables (-L)
230 } dump_mode;
231
232 // Pattern to match against in listing mode (-l/-L)
233 std::string dump_matched_pattern;
234
ea60076d 235 int download_dbinfo;
7baf48e9 236 bool suppress_handler_errors;
152fa051 237 bool suppress_time_limits;
a8c9365c 238 bool color_errors;
11a046b7
DS
239 bool interactive_mode;
240 bool pass_1a_complete;
d5d3a90b 241
6d3599fc 242 enum { color_never, color_auto, color_always } color_mode;
8c1cf686 243 enum { prologue_searching_never, prologue_searching_auto, prologue_searching_always } prologue_searching_mode;
6d3599fc 244
4441e344 245 enum { kernel_runtime, dyninst_runtime } runtime_mode;
ac3af990 246 bool runtime_usermode_p() const { return runtime_mode == dyninst_runtime; }
4441e344 247
2dce8c42 248 // NB: It is very important for all of the above (and below) fields
85007c04 249 // to be cleared in the systemtap_session ctor (session.cxx).
2dce8c42
DB
250
251 // Client/server
48e74294 252#if HAVE_NSS
44edbcd6 253 static bool NSPR_Initialized; // only once for all sessions
3d9dfde6 254 void NSPR_init ();
48e74294 255#endif
e2012a7a 256 bool client_options;
372c6458 257 std::string client_options_disallowed_for_unprivileged;
2dce8c42
DB
258 std::vector<std::string> server_status_strings;
259 std::vector<std::string> specified_servers;
c77af0d0 260 std::string server_trust_spec;
2fad97fd 261 std::vector<std::string> server_args;
920be590 262 std::string winning_server;
eff14db3 263 compile_server_cache* server_cache;
cd1418c7 264 std::vector<std::string> mok_fingerprints;
4e78c716
DB
265 std::string auto_privilege_level_msg;
266 std::vector<std::string> auto_server_msgs;
b3367f63
DS
267
268 bool modules_must_be_signed();
269 void get_mok_info();
ce286ff0 270
44edbcd6
JS
271 // NB: It is very important for all of the above (and below) fields
272 // to be cleared in the systemtap_session ctor (session.cxx).
273
274 // Mechanism for retrying compilation with a compile server should it fail due
275 // to lack of resources on the local host.
276 // Once it has been decided not to try the server (e.g. syntax error),
277 // that decision cannot be changed.
278 int try_server_status;
279 bool use_server_on_error;
280
3e1ec884 281 enum { try_server_unset, dont_try_server, do_try_server };
44edbcd6
JS
282 void init_try_server ();
283 void set_try_server (int t = do_try_server);
284 bool try_server () const { return try_server_status == do_try_server; }
285
286 // NB: It is very important for all of the above (and below) fields
287 // to be cleared in the systemtap_session ctor (session.cxx).
288
daa75206
JS
289 // Remote execution
290 std::vector<std::string> remote_uris;
756cfd49 291 bool use_remote_prefix;
ebff2ed0
JS
292 typedef std::map<std::pair<std::string, std::string>, systemtap_session*> session_map_t;
293 session_map_t subsessions;
294 systemtap_session* clone(const std::string& arch, const std::string& release);
daa75206 295
28f569c2 296 // NB: It is very important for all of the above (and below) fields
85007c04 297 // to be cleared in the systemtap_session ctor (session.cxx).
28f569c2 298
1b78aef5 299 // Cache data
d105f664
JS
300 bool use_cache; // control all caching
301 bool use_script_cache; // control caching of pass-3/4 output
302 bool poison_cache; // consider the cache to be write-only
303 std::string cache_path; // usually ~/.systemtap/cache
304 std::string hash_path; // path to the cached script module
305 std::string stapconf_path; // path to the cached stapconf
dec33462 306 stap_hash *base_hash; // hash common to all caching
1b78aef5 307
3bd0d4df
RA
308 // Skip bad $ vars
309 bool skip_badvars;
310
28f569c2 311 // NB: It is very important for all of the above (and below) fields
85007c04 312 // to be cleared in the systemtap_session ctor (session.cxx).
28f569c2 313
177a8ead
FCE
314 // temporary directory for module builds etc.
315 // hazardous - it is "rm -rf"'d at exit
316 std::string tmpdir;
317 std::string translated_source; // C source code
318
319 match_node* pattern_root;
320 void register_library_aliases();
321
f7a557ae 322 // data for various preprocessor library macros
fe410f52 323 std::map<std::string, macrodecl*> library_macros;
f7a557ae 324
177a8ead 325 // parse trees for the various script files
ba48c27a 326 std::vector<stapfile*> user_files;
177a8ead
FCE
327 std::vector<stapfile*> library_files;
328
f80d9004
JS
329 // filters to run over all code before symbol resolution
330 // e.g. @cast expansion
331 std::vector<update_visitor*> code_filters;
332
177a8ead
FCE
333 // resolved globals/functions/probes for the run as a whole
334 std::vector<stapfile*> files;
335 std::vector<vardecl*> globals;
f76427a2 336 std::map<std::string,functiondecl*> functions;
3689db05 337 // probe counter name -> probe associated with counter
aa2c662f 338 std::vector<std::pair<std::string,std::string> > perf_counters;
b20febf3 339 std::vector<derived_probe*> probes; // see also *_probes groups below
177a8ead 340 std::vector<embeddedcode*> embeds;
47d349b1 341 std::map<interned_string, statistic_decl> stat_decls;
c3a3c0c9
WC
342 // track things that are removed
343 std::vector<vardecl*> unused_globals;
344 std::vector<derived_probe*> unused_probes; // see also *_probes groups below
345 std::vector<functiondecl*> unused_functions;
177a8ead 346
60cf5fae
SM
347 // resolved/compiled regular expressions for the run
348 std::map<std::string, stapdfa*> dfas;
349 unsigned dfa_counter; // used to give unique names
350 unsigned dfa_maxstate; // used for subexpression-tracking data structure
351 unsigned dfa_maxtag; // ditto
26c2e4c2 352 bool need_tagged_dfa; // triggered by /* pragma:tagged_dfa */
60cf5fae 353
b20febf3
FCE
354 // Every probe in these groups must also appear in the
355 // session.probes vector.
356 be_derived_probe_group* be_derived_probes;
a7fbce1f 357 generic_kprobe_derived_probe_group* generic_kprobe_derived_probes;
dd225250 358 hwbkpt_derived_probe_group* hwbkpt_derived_probes;
83ea76b1 359 perf_derived_probe_group* perf_derived_probes;
888af770 360 uprobe_derived_probe_group* uprobe_derived_probes;
935447c8 361 utrace_derived_probe_group* utrace_derived_probes;
a96d1db0 362 itrace_derived_probe_group* itrace_derived_probes;
935447c8 363 task_finder_derived_probe_group* task_finder_derived_probes;
b20febf3 364 timer_derived_probe_group* timer_derived_probes;
8d9609f5 365 netfilter_derived_probe_group* netfilter_derived_probes;
b20febf3
FCE
366 profile_derived_probe_group* profile_derived_probes;
367 mark_derived_probe_group* mark_derived_probes;
0a6f5a3f 368 tracepoint_derived_probe_group* tracepoint_derived_probes;
b20febf3 369 hrtimer_derived_probe_group* hrtimer_derived_probes;
604eef3b 370 procfs_derived_probe_group* procfs_derived_probes;
f31a77f5 371 dynprobe_derived_probe_group* dynprobe_derived_probes;
28f569c2 372
f9355a6c 373 // NB: It is very important for all of the above (and below) fields
85007c04 374 // to be cleared in the systemtap_session ctor (session.cxx).
177a8ead
FCE
375
376 // unparser data
377 translator_output* op;
a4b9c3b3 378 std::vector<translator_output*> auxiliary_outputs;
177a8ead
FCE
379 unparser* up;
380
84048984
FCE
381 // some symbol addresses
382 // XXX: these belong elsewhere; perhaps the dwflpp instance
383 Dwarf_Addr sym_kprobes_text_start;
384 Dwarf_Addr sym_kprobes_text_end;
385 Dwarf_Addr sym_stext;
1d3a40b6 386
a8368458 387 // List of libdwfl module names to extract symbol/unwind data for.
1a0dbc5a 388 std::set<std::string> unwindsym_modules;
ef06c938 389 bool unwindsym_ldd;
cbf5ebe1 390 struct module_cache* module_cache;
ecd129af 391 std::vector<std::string> build_ids;
a8368458 392
3d0a328d
JS
393 // Secret benchmarking options
394 unsigned long benchmark_sdt_loops;
395 unsigned long benchmark_sdt_threads;
396
28f569c2 397 // NB: It is very important for all of the above (and below) fields
85007c04 398 // to be cleared in the systemtap_session ctor (session.cxx).
28f569c2 399
ab54fa85 400 std::set<std::string> seen_warnings;
1c1f304d 401 int suppressed_warnings;
9e1a2390
JL
402 std::map<std::string, int> seen_errors; // NB: can change to a set if threshold is 1
403 int suppressed_errors;
7ac01ea0
JL
404 int warningerr_count; // see comment in systemtap_session::print_error
405
406 // Returns number of critical errors (not counting those part of warnings)
407 unsigned num_errors ()
408 {
409 return (seen_errors.size() // all the errors we've encountered
410 - warningerr_count // except those considered warningerrs
411 + (panic_warnings ? seen_warnings.size() : 0)); // plus warnings if -W given
412 }
cfd621bc 413
5f429a70
JS
414 std::set<std::string> rpms_checked; // enlisted by filename+rpm_type
415 std::set<std::string> rpms_to_install; // resulting rpms
2ed04863 416
80d74c6b 417 translator_output* op_create_auxiliary(bool trailer_p = false);
a4b9c3b3 418
b3104a15
FCE
419 int target_namespaces_pid;
420
cfd621bc
FCE
421 const token* last_token;
422 void print_token (std::ostream& o, const token* tok);
177a8ead 423 void print_error (const semantic_error& e);
9e1a2390 424 std::string build_error_msg (const semantic_error& e);
1b1b4ceb 425 void print_error_source (std::ostream&, std::string&, const token* tok);
48f6d208 426 void print_error_details (std::ostream&, std::string&, const semantic_error&);
6b7d7185 427 void print_error (const parse_error &pe,
9e1a2390 428 const token* tok,
7ac01ea0
JL
429 const std::string &input_name,
430 bool is_warningerr = false);
9e1a2390
JL
431 std::string build_error_msg (const parse_error &pe,
432 const token* tok,
433 const std::string &input_name);
cfd621bc 434 void print_warning (const std::string& w, const token* tok = 0);
aa4d21c0 435 void printscript(std::ostream& o);
678b7381 436 void report_suppression();
b20febf3 437
28f569c2 438 // NB: It is very important for all of the above (and below) fields
85007c04 439 // to be cleared in the systemtap_session ctor (session.cxx).
85007c04 440
eada930e
JL
441 std::string colorize(const std::string& str, const std::string& type);
442 std::string colorize(const token* tok);
443 std::string parse_stap_color(const std::string& type);
4e78c716
DB
444
445 // Some automatic options settings require explanation.
446 void enable_auto_server (const std::string &message);
447 void explain_auto_options();
ba48c27a
AJ
448
449 bool is_user_file (const std::string& name);
1ee0d3ba 450 bool is_primary_probe (derived_probe *dp);
2aca52e2 451
11a046b7
DS
452 void clear_script_data();
453
b3104a15
FCE
454 // NB: It is very important for all of the above (and below) fields
455 // to be cleared in the systemtap_session ctor (session.cxx).
d4d892e1 456};
177a8ead 457
e2d0f787
JS
458struct exit_exception: public std::runtime_error
459{
460 int rc;
461 exit_exception (int rc):
462 runtime_error (_F("early exit requested, rc=%d", rc)), rc(rc) {}
463};
464
465
49abf162 466// global counter of SIGINT/SIGTERM's received
85007c04
DB
467extern int pending_interrupts;
468
985892de
CM
469// Interrupt exception subclass for catching
470// interrupts (i.e. ctrl-c).
471struct interrupt_exception: public std::runtime_error
472{
473 interrupt_exception ():
474 runtime_error (_("interrupt received")){}
475};
476
e19ebcf7
CM
477void assert_no_interrupts();
478
177a8ead 479#endif // SESSION_H
73267b89
JS
480
481/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.219823 seconds and 5 git commands to generate.