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