]>
Commit | Line | Data |
---|---|---|
177a8ead | 1 | // -*- C++ -*- |
73f52eb4 | 2 | // Copyright (C) 2005-2012 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" |
79bc39ab LB |
13 | #include <libintl.h> |
14 | #include <locale.h> | |
9456e4c1 | 15 | |
aa4d21c0 | 16 | #include <list> |
177a8ead FCE |
17 | #include <string> |
18 | #include <vector> | |
19 | #include <iostream> | |
20 | #include <sstream> | |
21 | #include <map> | |
7e41d3dc | 22 | #include <set> |
985892de | 23 | #include <stdexcept> |
177a8ead | 24 | |
1d3a40b6 | 25 | extern "C" { |
2dce8c42 | 26 | #include <signal.h> |
1d3a40b6 DS |
27 | #include <elfutils/libdw.h> |
28 | } | |
29 | ||
3892d516 | 30 | #include "privilege.h" |
0d98c8da | 31 | #include "util.h" |
177a8ead FCE |
32 | |
33 | // forward decls for all referenced systemtap types | |
dec33462 | 34 | class stap_hash; |
b9aa5bb4 | 35 | class match_node; |
177a8ead FCE |
36 | struct stapfile; |
37 | struct vardecl; | |
cfd621bc | 38 | struct token; |
177a8ead | 39 | struct functiondecl; |
b20febf3 FCE |
40 | struct derived_probe; |
41 | struct be_derived_probe_group; | |
42 | struct dwarf_derived_probe_group; | |
e6fe60e7 | 43 | struct kprobe_derived_probe_group; |
dd225250 | 44 | struct hwbkpt_derived_probe_group; |
83ea76b1 | 45 | struct perf_derived_probe_group; |
888af770 | 46 | struct uprobe_derived_probe_group; |
935447c8 | 47 | struct utrace_derived_probe_group; |
a96d1db0 | 48 | struct itrace_derived_probe_group; |
935447c8 | 49 | struct task_finder_derived_probe_group; |
b20febf3 | 50 | struct timer_derived_probe_group; |
8d9609f5 | 51 | struct netfilter_derived_probe_group; |
b20febf3 FCE |
52 | struct profile_derived_probe_group; |
53 | struct mark_derived_probe_group; | |
0a6f5a3f | 54 | struct tracepoint_derived_probe_group; |
b20febf3 | 55 | struct hrtimer_derived_probe_group; |
604eef3b | 56 | struct procfs_derived_probe_group; |
f31a77f5 | 57 | struct dynprobe_derived_probe_group; |
177a8ead | 58 | struct embeddedcode; |
be87f53a | 59 | struct stapdfa; |
b9aa5bb4 | 60 | class translator_output; |
177a8ead FCE |
61 | struct unparser; |
62 | struct semantic_error; | |
405b71b8 | 63 | struct module_cache; |
f80d9004 | 64 | struct update_visitor; |
eff14db3 | 65 | struct compile_server_cache; |
177a8ead | 66 | |
177a8ead FCE |
67 | // XXX: a generalized form of this descriptor could be associated with |
68 | // a vardecl instead of out here at the systemtap_session level. | |
69 | struct statistic_decl | |
70 | { | |
71 | statistic_decl() | |
dff50e09 | 72 | : type(none), |
177a8ead | 73 | linear_low(0), linear_high(0), linear_step(0) |
dff50e09 | 74 | {} |
177a8ead | 75 | enum { none, linear, logarithmic } type; |
177a8ead FCE |
76 | int64_t linear_low; |
77 | int64_t linear_high; | |
78 | int64_t linear_step; | |
07c17d67 GH |
79 | bool operator==(statistic_decl const & other) |
80 | { | |
dff50e09 | 81 | return type == other.type |
07c17d67 GH |
82 | && linear_low == other.linear_low |
83 | && linear_high == other.linear_high | |
84 | && linear_step == other.linear_step; | |
85 | } | |
177a8ead FCE |
86 | }; |
87 | ||
fe410f52 SM |
88 | struct macrodecl; // defined in parse.h |
89 | ||
177a8ead FCE |
90 | struct systemtap_session |
91 | { | |
abc15290 JS |
92 | private: |
93 | // disable implicit constructors by not implementing these | |
94 | systemtap_session (const systemtap_session& other); | |
95 | systemtap_session& operator= (const systemtap_session& other); | |
96 | ||
97 | // copy constructor used by ::clone() | |
98 | systemtap_session (const systemtap_session& other, | |
99 | const std::string& arch, | |
100 | const std::string& kern); | |
101 | ||
102 | public: | |
177a8ead | 103 | systemtap_session (); |
b0e5fa85 | 104 | ~systemtap_session (); |
aa4d21c0 | 105 | |
b96901b7 CM |
106 | // To reset the tmp_dir |
107 | void create_tmp_dir(); | |
108 | void remove_tmp_dir(); | |
109 | void reset_tmp_dir(); | |
110 | ||
28f569c2 | 111 | // NB: It is very important for all of the above (and below) fields |
85007c04 | 112 | // to be cleared in the systemtap_session ctor (session.cxx). |
e2012a7a | 113 | void setup_kernel_release (const char* kstr); |
bb153adb | 114 | void insert_loaded_modules (); |
e2012a7a DB |
115 | |
116 | // command line parsing | |
117 | int parse_cmdline (int argc, char * const argv []); | |
45402f2a | 118 | bool parse_cmdline_runtime (const std::string& opt_runtime); |
e2012a7a DB |
119 | void version (); |
120 | void usage (int exitcode); | |
121 | void check_options (int argc, char * const argv []); | |
122 | static const char* morehelp; | |
177a8ead | 123 | |
aa4d21c0 | 124 | // NB: It is very important for all of the above (and below) fields |
85007c04 | 125 | // to be cleared in the systemtap_session ctor (session.cxx). |
aa4d21c0 | 126 | |
177a8ead | 127 | // command line args |
e2012a7a DB |
128 | std::string script_file; // FILE |
129 | std::string cmdline_script; // -e PROGRAM | |
130 | bool have_script; | |
177a8ead | 131 | std::vector<std::string> include_path; |
2fad97fd | 132 | int include_arg_start; |
08fce398 | 133 | std::vector<std::string> c_macros; |
177a8ead | 134 | std::vector<std::string> args; |
633e5ca7 | 135 | std::vector<std::string> kbuildflags; // -B var=val |
bb25d08f | 136 | std::vector<std::string> globalopts; // -G var=val |
633e5ca7 | 137 | std::vector<std::string> modinfos; // --modinfo tag=value |
8dfad013 | 138 | |
e2012a7a | 139 | std::string release; |
177a8ead | 140 | std::string kernel_release; |
197a4d62 | 141 | std::string kernel_base_release; |
7471ea1f | 142 | std::string kernel_build_tree; |
d4393459 | 143 | std::string kernel_source_tree; |
8dfad013 JS |
144 | std::map<std::string,std::string> kernel_config; |
145 | std::set<std::string> kernel_exports; | |
2a639817 | 146 | std::set<std::string> kernel_functions; |
8dfad013 JS |
147 | int parse_kernel_config (); |
148 | int parse_kernel_exports (); | |
2a639817 | 149 | int parse_kernel_functions (); |
8dfad013 | 150 | |
05fb3e0c WF |
151 | std::string sysroot; |
152 | std::map<std::string,std::string> sysenv; | |
153 | bool update_release_sysroot; | |
e2012a7a | 154 | std::string machine; |
44ce8ed5 | 155 | std::string architecture; |
50f2545f | 156 | bool native_build; |
177a8ead | 157 | std::string runtime_path; |
2fad97fd | 158 | bool runtime_specified; |
1b78aef5 | 159 | std::string data_path; |
177a8ead | 160 | std::string module_name; |
4441e344 | 161 | const std::string module_filename() const; |
de0db58a | 162 | std::string stapconf_name; |
177a8ead | 163 | std::string output_file; |
701c41be | 164 | std::string size_option; |
177a8ead | 165 | std::string cmd; |
db135493 | 166 | std::string compatible; // use (strverscmp(s.compatible.c_str(), "N.M") >= 0) |
177a8ead FCE |
167 | int target_pid; |
168 | int last_pass; | |
e0b4e89d | 169 | unsigned perpass_verbose[5]; |
b0ee93c4 | 170 | unsigned verbose; |
a9e8f7e0 | 171 | bool timing; |
e2012a7a | 172 | bool save_module; |
5c854d7c | 173 | bool modname_given; |
177a8ead FCE |
174 | bool keep_tmpdir; |
175 | bool guru_mode; | |
16442b90 | 176 | bool listing_mode; |
8c39844b | 177 | bool listing_mode_vars; |
177a8ead | 178 | bool bulk_mode; |
cbfbbf69 | 179 | bool unoptimized; |
a9e8f7e0 | 180 | bool suppress_warnings; |
57a56e00 | 181 | bool panic_warnings; |
177a8ead | 182 | int buffer_size; |
44f75386 | 183 | bool prologue_searching; |
c3a3c0c9 | 184 | bool tapset_compile_coverage; |
6274464e | 185 | bool need_uprobes; |
08badca8 | 186 | bool need_unwind; |
8af41ec2 | 187 | bool need_symbols; |
474d17ad | 188 | std::string uprobes_path; |
7d26ee02 | 189 | std::string uprobes_hash; |
2fa2a091 | 190 | bool load_only; // flight recorder mode |
2dce8c42 | 191 | bool omit_werror; |
42e38653 | 192 | privilege_t privilege; |
73f52eb4 | 193 | bool privilege_set; |
a07a2c28 | 194 | bool systemtap_v_check; |
305fac7d | 195 | bool tmpdir_opt_set; |
b82d77b4 | 196 | bool dump_probe_types; |
ea60076d | 197 | int download_dbinfo; |
7baf48e9 | 198 | bool suppress_handler_errors; |
152fa051 | 199 | bool suppress_time_limits; |
2dce8c42 | 200 | |
4441e344 | 201 | enum { kernel_runtime, dyninst_runtime } runtime_mode; |
ac3af990 | 202 | bool runtime_usermode_p() const { return runtime_mode == dyninst_runtime; } |
4441e344 | 203 | |
2dce8c42 | 204 | // NB: It is very important for all of the above (and below) fields |
85007c04 | 205 | // to be cleared in the systemtap_session ctor (session.cxx). |
2dce8c42 DB |
206 | |
207 | // Client/server | |
48e74294 | 208 | #if HAVE_NSS |
44edbcd6 | 209 | static bool NSPR_Initialized; // only once for all sessions |
3d9dfde6 | 210 | void NSPR_init (); |
48e74294 | 211 | #endif |
e2012a7a | 212 | bool client_options; |
372c6458 | 213 | std::string client_options_disallowed_for_unprivileged; |
2dce8c42 DB |
214 | std::vector<std::string> server_status_strings; |
215 | std::vector<std::string> specified_servers; | |
a46f9abe | 216 | bool automatic_server_mode; |
c77af0d0 | 217 | std::string server_trust_spec; |
2fad97fd | 218 | std::vector<std::string> server_args; |
920be590 | 219 | std::string winning_server; |
eff14db3 | 220 | compile_server_cache* server_cache; |
ce286ff0 | 221 | |
44edbcd6 JS |
222 | // NB: It is very important for all of the above (and below) fields |
223 | // to be cleared in the systemtap_session ctor (session.cxx). | |
224 | ||
225 | // Mechanism for retrying compilation with a compile server should it fail due | |
226 | // to lack of resources on the local host. | |
227 | // Once it has been decided not to try the server (e.g. syntax error), | |
228 | // that decision cannot be changed. | |
229 | int try_server_status; | |
230 | bool use_server_on_error; | |
231 | ||
3e1ec884 | 232 | enum { try_server_unset, dont_try_server, do_try_server }; |
44edbcd6 JS |
233 | void init_try_server (); |
234 | void set_try_server (int t = do_try_server); | |
235 | bool try_server () const { return try_server_status == do_try_server; } | |
236 | ||
237 | // NB: It is very important for all of the above (and below) fields | |
238 | // to be cleared in the systemtap_session ctor (session.cxx). | |
239 | ||
daa75206 JS |
240 | // Remote execution |
241 | std::vector<std::string> remote_uris; | |
756cfd49 | 242 | bool use_remote_prefix; |
ebff2ed0 JS |
243 | typedef std::map<std::pair<std::string, std::string>, systemtap_session*> session_map_t; |
244 | session_map_t subsessions; | |
245 | systemtap_session* clone(const std::string& arch, const std::string& release); | |
daa75206 | 246 | |
28f569c2 | 247 | // NB: It is very important for all of the above (and below) fields |
85007c04 | 248 | // to be cleared in the systemtap_session ctor (session.cxx). |
28f569c2 | 249 | |
1b78aef5 | 250 | // Cache data |
d105f664 JS |
251 | bool use_cache; // control all caching |
252 | bool use_script_cache; // control caching of pass-3/4 output | |
253 | bool poison_cache; // consider the cache to be write-only | |
254 | std::string cache_path; // usually ~/.systemtap/cache | |
255 | std::string hash_path; // path to the cached script module | |
256 | std::string stapconf_path; // path to the cached stapconf | |
dec33462 | 257 | stap_hash *base_hash; // hash common to all caching |
1b78aef5 | 258 | |
5f0a03a6 JK |
259 | // dwarfless operation |
260 | bool consult_symtab; | |
261 | std::string kernel_symtab_path; | |
5f0a03a6 | 262 | |
3bd0d4df RA |
263 | // Skip bad $ vars |
264 | bool skip_badvars; | |
265 | ||
28f569c2 | 266 | // NB: It is very important for all of the above (and below) fields |
85007c04 | 267 | // to be cleared in the systemtap_session ctor (session.cxx). |
28f569c2 | 268 | |
177a8ead FCE |
269 | // temporary directory for module builds etc. |
270 | // hazardous - it is "rm -rf"'d at exit | |
271 | std::string tmpdir; | |
272 | std::string translated_source; // C source code | |
273 | ||
274 | match_node* pattern_root; | |
275 | void register_library_aliases(); | |
276 | ||
f7a557ae | 277 | // data for various preprocessor library macros |
fe410f52 SM |
278 | std::map<std::string, macrodecl*> library_macros; |
279 | std::vector<stapfile*> library_macro_files; // for error reporting purposes | |
f7a557ae | 280 | |
177a8ead FCE |
281 | // parse trees for the various script files |
282 | stapfile* user_file; | |
283 | std::vector<stapfile*> library_files; | |
284 | ||
f80d9004 JS |
285 | // filters to run over all code before symbol resolution |
286 | // e.g. @cast expansion | |
287 | std::vector<update_visitor*> code_filters; | |
288 | ||
177a8ead FCE |
289 | // resolved globals/functions/probes for the run as a whole |
290 | std::vector<stapfile*> files; | |
291 | std::vector<vardecl*> globals; | |
f76427a2 | 292 | std::map<std::string,functiondecl*> functions; |
3689db05 SC |
293 | // probe counter name -> probe associated with counter |
294 | std::map<std::string, std::pair<std::string,derived_probe*> > perf_counters; | |
b20febf3 | 295 | std::vector<derived_probe*> probes; // see also *_probes groups below |
177a8ead FCE |
296 | std::vector<embeddedcode*> embeds; |
297 | std::map<std::string, statistic_decl> stat_decls; | |
d2548fe7 SM |
298 | std::map<std::string, stapdfa*> dfas; |
299 | unsigned dfa_counter; // used to give unique names | |
c3a3c0c9 WC |
300 | // track things that are removed |
301 | std::vector<vardecl*> unused_globals; | |
302 | std::vector<derived_probe*> unused_probes; // see also *_probes groups below | |
303 | std::vector<functiondecl*> unused_functions; | |
177a8ead FCE |
304 | // XXX: vector<*> instead please? |
305 | ||
b20febf3 FCE |
306 | // Every probe in these groups must also appear in the |
307 | // session.probes vector. | |
308 | be_derived_probe_group* be_derived_probes; | |
309 | dwarf_derived_probe_group* dwarf_derived_probes; | |
e6fe60e7 | 310 | kprobe_derived_probe_group* kprobe_derived_probes; |
dd225250 | 311 | hwbkpt_derived_probe_group* hwbkpt_derived_probes; |
83ea76b1 | 312 | perf_derived_probe_group* perf_derived_probes; |
888af770 | 313 | uprobe_derived_probe_group* uprobe_derived_probes; |
935447c8 | 314 | utrace_derived_probe_group* utrace_derived_probes; |
a96d1db0 | 315 | itrace_derived_probe_group* itrace_derived_probes; |
935447c8 | 316 | task_finder_derived_probe_group* task_finder_derived_probes; |
b20febf3 | 317 | timer_derived_probe_group* timer_derived_probes; |
8d9609f5 | 318 | netfilter_derived_probe_group* netfilter_derived_probes; |
b20febf3 FCE |
319 | profile_derived_probe_group* profile_derived_probes; |
320 | mark_derived_probe_group* mark_derived_probes; | |
0a6f5a3f | 321 | tracepoint_derived_probe_group* tracepoint_derived_probes; |
b20febf3 | 322 | hrtimer_derived_probe_group* hrtimer_derived_probes; |
604eef3b | 323 | procfs_derived_probe_group* procfs_derived_probes; |
f31a77f5 | 324 | dynprobe_derived_probe_group* dynprobe_derived_probes; |
28f569c2 | 325 | |
f9355a6c | 326 | // NB: It is very important for all of the above (and below) fields |
85007c04 | 327 | // to be cleared in the systemtap_session ctor (session.cxx). |
177a8ead FCE |
328 | |
329 | // unparser data | |
330 | translator_output* op; | |
a4b9c3b3 | 331 | std::vector<translator_output*> auxiliary_outputs; |
177a8ead FCE |
332 | unparser* up; |
333 | ||
84048984 FCE |
334 | // some symbol addresses |
335 | // XXX: these belong elsewhere; perhaps the dwflpp instance | |
336 | Dwarf_Addr sym_kprobes_text_start; | |
337 | Dwarf_Addr sym_kprobes_text_end; | |
338 | Dwarf_Addr sym_stext; | |
1d3a40b6 | 339 | |
a8368458 | 340 | // List of libdwfl module names to extract symbol/unwind data for. |
1a0dbc5a | 341 | std::set<std::string> unwindsym_modules; |
ef06c938 | 342 | bool unwindsym_ldd; |
cbf5ebe1 | 343 | struct module_cache* module_cache; |
ecd129af | 344 | std::vector<std::string> build_ids; |
a8368458 | 345 | |
3d0a328d JS |
346 | // Secret benchmarking options |
347 | unsigned long benchmark_sdt_loops; | |
348 | unsigned long benchmark_sdt_threads; | |
349 | ||
28f569c2 | 350 | // NB: It is very important for all of the above (and below) fields |
85007c04 | 351 | // to be cleared in the systemtap_session ctor (session.cxx). |
28f569c2 | 352 | |
7e41d3dc | 353 | std::set<std::string> seen_errors; |
ab54fa85 | 354 | std::set<std::string> seen_warnings; |
57a56e00 | 355 | unsigned num_errors () { return seen_errors.size() + (panic_warnings ? seen_warnings.size() : 0); } |
cfd621bc | 356 | |
2ed04863 WC |
357 | std::set<std::string> rpms_to_install; |
358 | ||
a4b9c3b3 FCE |
359 | translator_output* op_create_auxiliary(); |
360 | ||
177a8ead | 361 | // void print_error (const parse_error& e); |
cfd621bc FCE |
362 | const token* last_token; |
363 | void print_token (std::ostream& o, const token* tok); | |
177a8ead | 364 | void print_error (const semantic_error& e); |
1b1b4ceb | 365 | void print_error_source (std::ostream&, std::string&, const token* tok); |
cfd621bc | 366 | void print_warning (const std::string& w, const token* tok = 0); |
aa4d21c0 | 367 | void printscript(std::ostream& o); |
b20febf3 | 368 | |
28f569c2 | 369 | // NB: It is very important for all of the above (and below) fields |
85007c04 DB |
370 | // to be cleared in the systemtap_session ctor (session.cxx). |
371 | }; | |
372 | ||
177a8ead | 373 | |
e2d0f787 JS |
374 | struct exit_exception: public std::runtime_error |
375 | { | |
376 | int rc; | |
377 | exit_exception (int rc): | |
378 | runtime_error (_F("early exit requested, rc=%d", rc)), rc(rc) {} | |
379 | }; | |
380 | ||
381 | ||
49abf162 | 382 | // global counter of SIGINT/SIGTERM's received |
85007c04 DB |
383 | extern int pending_interrupts; |
384 | ||
985892de CM |
385 | // Interrupt exception subclass for catching |
386 | // interrupts (i.e. ctrl-c). | |
387 | struct interrupt_exception: public std::runtime_error | |
388 | { | |
389 | interrupt_exception (): | |
390 | runtime_error (_("interrupt received")){} | |
391 | }; | |
392 | ||
e19ebcf7 CM |
393 | void assert_no_interrupts(); |
394 | ||
177a8ead | 395 | #endif // SESSION_H |
73267b89 JS |
396 | |
397 | /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ |