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