]> sourceware.org Git - systemtap.git/blame - session.h
task_finder2: update an unprivileged check for stapsys
[systemtap.git] / session.h
CommitLineData
177a8ead 1// -*- C++ -*-
44edbcd6 2// Copyright (C) 2005-2011 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>
177a8ead 23
1d3a40b6 24extern "C" {
2dce8c42 25#include <signal.h>
1d3a40b6
DS
26#include <elfutils/libdw.h>
27}
28
3892d516 29#include "privilege.h"
42e38653 30
ce4086c8 31#if ENABLE_NLS
79bc39ab 32#define _(string) gettext(string)
46a1a151
JS
33#define _N(string, string_plural, count) \
34 ngettext((string), (string_plural), (count))
ce4086c8
LB
35#else
36#define _(string) (string)
46a1a151
JS
37#define _N(string, string_plural, count) \
38 ( (count) == 1 ? (string) : (string_plural) )
ce4086c8 39#endif
46a1a151
JS
40#define _F(format, ...) autosprintf(_(format), __VA_ARGS__)
41#define _NF(format, format_plural, count, ...) \
42 autosprintf(_N((format), (format_plural), (count)), __VA_ARGS__)
177a8ead
FCE
43
44// forward decls for all referenced systemtap types
9b3c54b2 45struct hash;
177a8ead
FCE
46struct match_node;
47struct stapfile;
48struct vardecl;
cfd621bc 49struct token;
177a8ead 50struct functiondecl;
b20febf3
FCE
51struct derived_probe;
52struct be_derived_probe_group;
53struct dwarf_derived_probe_group;
e6fe60e7 54struct kprobe_derived_probe_group;
dd225250 55struct hwbkpt_derived_probe_group;
83ea76b1 56struct perf_derived_probe_group;
888af770 57struct uprobe_derived_probe_group;
935447c8 58struct utrace_derived_probe_group;
a96d1db0 59struct itrace_derived_probe_group;
935447c8 60struct task_finder_derived_probe_group;
b20febf3
FCE
61struct timer_derived_probe_group;
62struct profile_derived_probe_group;
63struct mark_derived_probe_group;
0a6f5a3f 64struct tracepoint_derived_probe_group;
b20febf3 65struct hrtimer_derived_probe_group;
604eef3b 66struct procfs_derived_probe_group;
177a8ead
FCE
67struct embeddedcode;
68struct translator_output;
69struct unparser;
70struct semantic_error;
405b71b8 71struct module_cache;
f80d9004 72struct update_visitor;
eff14db3 73struct compile_server_cache;
177a8ead 74
177a8ead
FCE
75// XXX: a generalized form of this descriptor could be associated with
76// a vardecl instead of out here at the systemtap_session level.
77struct statistic_decl
78{
79 statistic_decl()
dff50e09 80 : type(none),
177a8ead 81 linear_low(0), linear_high(0), linear_step(0)
dff50e09 82 {}
177a8ead 83 enum { none, linear, logarithmic } type;
177a8ead
FCE
84 int64_t linear_low;
85 int64_t linear_high;
86 int64_t linear_step;
07c17d67
GH
87 bool operator==(statistic_decl const & other)
88 {
dff50e09 89 return type == other.type
07c17d67
GH
90 && linear_low == other.linear_low
91 && linear_high == other.linear_high
92 && linear_step == other.linear_step;
93 }
177a8ead
FCE
94};
95
177a8ead
FCE
96struct systemtap_session
97{
abc15290
JS
98private:
99 // disable implicit constructors by not implementing these
100 systemtap_session (const systemtap_session& other);
101 systemtap_session& operator= (const systemtap_session& other);
102
103 // copy constructor used by ::clone()
104 systemtap_session (const systemtap_session& other,
105 const std::string& arch,
106 const std::string& kern);
107
108public:
177a8ead 109 systemtap_session ();
b0e5fa85 110 ~systemtap_session ();
aa4d21c0 111
28f569c2 112 // NB: It is very important for all of the above (and below) fields
85007c04 113 // to be cleared in the systemtap_session ctor (session.cxx).
e2012a7a 114 void setup_kernel_release (const char* kstr);
bb153adb 115 void insert_loaded_modules ();
e2012a7a
DB
116
117 // command line parsing
118 int parse_cmdline (int argc, char * const argv []);
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;
177a8ead
FCE
133 std::vector<std::string> macros;
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
e2012a7a 138 std::string release;
177a8ead 139 std::string kernel_release;
197a4d62 140 std::string kernel_base_release;
7471ea1f 141 std::string kernel_build_tree;
d4393459 142 std::string kernel_source_tree;
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;
de0db58a 152 std::string stapconf_name;
177a8ead 153 std::string output_file;
701c41be 154 std::string size_option;
177a8ead 155 std::string cmd;
db135493 156 std::string compatible; // use (strverscmp(s.compatible.c_str(), "N.M") >= 0)
177a8ead
FCE
157 int target_pid;
158 int last_pass;
e0b4e89d 159 unsigned perpass_verbose[5];
b0ee93c4 160 unsigned verbose;
a9e8f7e0 161 bool timing;
e2012a7a 162 bool save_module;
5c854d7c 163 bool modname_given;
177a8ead
FCE
164 bool keep_tmpdir;
165 bool guru_mode;
16442b90 166 bool listing_mode;
8c39844b 167 bool listing_mode_vars;
177a8ead 168 bool bulk_mode;
cbfbbf69 169 bool unoptimized;
a9e8f7e0 170 bool suppress_warnings;
57a56e00 171 bool panic_warnings;
177a8ead 172 int buffer_size;
44f75386 173 bool prologue_searching;
c3a3c0c9 174 bool tapset_compile_coverage;
6274464e 175 bool need_uprobes;
08badca8 176 bool need_unwind;
8af41ec2 177 bool need_symbols;
474d17ad 178 std::string uprobes_path;
7d26ee02 179 std::string uprobes_hash;
2fa2a091 180 bool load_only; // flight recorder mode
2dce8c42 181 bool omit_werror;
42e38653 182 privilege_t privilege;
a07a2c28 183 bool systemtap_v_check;
305fac7d 184 bool tmpdir_opt_set;
b82d77b4 185 bool dump_probe_types;
ea60076d 186 int download_dbinfo;
7baf48e9 187 bool suppress_handler_errors;
2dce8c42
DB
188
189 // NB: It is very important for all of the above (and below) fields
85007c04 190 // to be cleared in the systemtap_session ctor (session.cxx).
2dce8c42
DB
191
192 // Client/server
48e74294 193#if HAVE_NSS
44edbcd6 194 static bool NSPR_Initialized; // only once for all sessions
3d9dfde6 195 void NSPR_init ();
48e74294 196#endif
e2012a7a
DB
197 bool client_options;
198 std::string client_options_disallowed;
2dce8c42
DB
199 std::vector<std::string> server_status_strings;
200 std::vector<std::string> specified_servers;
a46f9abe 201 bool automatic_server_mode;
c77af0d0 202 std::string server_trust_spec;
2fad97fd 203 std::vector<std::string> server_args;
920be590 204 std::string winning_server;
eff14db3 205 compile_server_cache* server_cache;
ce286ff0 206
44edbcd6
JS
207 // NB: It is very important for all of the above (and below) fields
208 // to be cleared in the systemtap_session ctor (session.cxx).
209
210 // Mechanism for retrying compilation with a compile server should it fail due
211 // to lack of resources on the local host.
212 // Once it has been decided not to try the server (e.g. syntax error),
213 // that decision cannot be changed.
214 int try_server_status;
215 bool use_server_on_error;
216
3e1ec884 217 enum { try_server_unset, dont_try_server, do_try_server };
44edbcd6
JS
218 void init_try_server ();
219 void set_try_server (int t = do_try_server);
220 bool try_server () const { return try_server_status == do_try_server; }
221
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
daa75206
JS
225 // Remote execution
226 std::vector<std::string> remote_uris;
756cfd49 227 bool use_remote_prefix;
ebff2ed0
JS
228 typedef std::map<std::pair<std::string, std::string>, systemtap_session*> session_map_t;
229 session_map_t subsessions;
230 systemtap_session* clone(const std::string& arch, const std::string& release);
daa75206 231
28f569c2 232 // NB: It is very important for all of the above (and below) fields
85007c04 233 // to be cleared in the systemtap_session ctor (session.cxx).
28f569c2 234
1b78aef5 235 // Cache data
d105f664
JS
236 bool use_cache; // control all caching
237 bool use_script_cache; // control caching of pass-3/4 output
238 bool poison_cache; // consider the cache to be write-only
239 std::string cache_path; // usually ~/.systemtap/cache
240 std::string hash_path; // path to the cached script module
241 std::string stapconf_path; // path to the cached stapconf
242 hash *base_hash; // hash common to all caching
1b78aef5 243
5f0a03a6
JK
244 // dwarfless operation
245 bool consult_symtab;
246 std::string kernel_symtab_path;
247 bool ignore_vmlinux;
248 bool ignore_dwarf;
249
3bd0d4df
RA
250 // Skip bad $ vars
251 bool skip_badvars;
252
28f569c2 253 // NB: It is very important for all of the above (and below) fields
85007c04 254 // to be cleared in the systemtap_session ctor (session.cxx).
28f569c2 255
177a8ead
FCE
256 // temporary directory for module builds etc.
257 // hazardous - it is "rm -rf"'d at exit
258 std::string tmpdir;
259 std::string translated_source; // C source code
260
261 match_node* pattern_root;
262 void register_library_aliases();
263
264 // parse trees for the various script files
265 stapfile* user_file;
266 std::vector<stapfile*> library_files;
267
f80d9004
JS
268 // filters to run over all code before symbol resolution
269 // e.g. @cast expansion
270 std::vector<update_visitor*> code_filters;
271
177a8ead
FCE
272 // resolved globals/functions/probes for the run as a whole
273 std::vector<stapfile*> files;
274 std::vector<vardecl*> globals;
f76427a2 275 std::map<std::string,functiondecl*> functions;
b20febf3 276 std::vector<derived_probe*> probes; // see also *_probes groups below
177a8ead
FCE
277 std::vector<embeddedcode*> embeds;
278 std::map<std::string, statistic_decl> stat_decls;
c3a3c0c9
WC
279 // track things that are removed
280 std::vector<vardecl*> unused_globals;
281 std::vector<derived_probe*> unused_probes; // see also *_probes groups below
282 std::vector<functiondecl*> unused_functions;
177a8ead
FCE
283 // XXX: vector<*> instead please?
284
b20febf3
FCE
285 // Every probe in these groups must also appear in the
286 // session.probes vector.
287 be_derived_probe_group* be_derived_probes;
288 dwarf_derived_probe_group* dwarf_derived_probes;
e6fe60e7 289 kprobe_derived_probe_group* kprobe_derived_probes;
dd225250 290 hwbkpt_derived_probe_group* hwbkpt_derived_probes;
83ea76b1 291 perf_derived_probe_group* perf_derived_probes;
888af770 292 uprobe_derived_probe_group* uprobe_derived_probes;
935447c8 293 utrace_derived_probe_group* utrace_derived_probes;
a96d1db0 294 itrace_derived_probe_group* itrace_derived_probes;
935447c8 295 task_finder_derived_probe_group* task_finder_derived_probes;
b20febf3
FCE
296 timer_derived_probe_group* timer_derived_probes;
297 profile_derived_probe_group* profile_derived_probes;
298 mark_derived_probe_group* mark_derived_probes;
0a6f5a3f 299 tracepoint_derived_probe_group* tracepoint_derived_probes;
b20febf3 300 hrtimer_derived_probe_group* hrtimer_derived_probes;
604eef3b 301 procfs_derived_probe_group* procfs_derived_probes;
28f569c2 302
f9355a6c 303 // NB: It is very important for all of the above (and below) fields
85007c04 304 // to be cleared in the systemtap_session ctor (session.cxx).
177a8ead
FCE
305
306 // unparser data
307 translator_output* op;
a4b9c3b3 308 std::vector<translator_output*> auxiliary_outputs;
177a8ead
FCE
309 unparser* up;
310
84048984
FCE
311 // some symbol addresses
312 // XXX: these belong elsewhere; perhaps the dwflpp instance
313 Dwarf_Addr sym_kprobes_text_start;
314 Dwarf_Addr sym_kprobes_text_end;
315 Dwarf_Addr sym_stext;
1d3a40b6 316
a8368458 317 // List of libdwfl module names to extract symbol/unwind data for.
1a0dbc5a 318 std::set<std::string> unwindsym_modules;
ef06c938 319 bool unwindsym_ldd;
cbf5ebe1 320 struct module_cache* module_cache;
ecd129af 321 std::vector<std::string> build_ids;
a8368458 322
28f569c2 323 // NB: It is very important for all of the above (and below) fields
85007c04 324 // to be cleared in the systemtap_session ctor (session.cxx).
28f569c2 325
7e41d3dc 326 std::set<std::string> seen_errors;
ab54fa85 327 std::set<std::string> seen_warnings;
57a56e00 328 unsigned num_errors () { return seen_errors.size() + (panic_warnings ? seen_warnings.size() : 0); }
cfd621bc 329
2ed04863
WC
330 std::set<std::string> rpms_to_install;
331
a4b9c3b3
FCE
332 translator_output* op_create_auxiliary();
333
177a8ead 334 // void print_error (const parse_error& e);
cfd621bc
FCE
335 const token* last_token;
336 void print_token (std::ostream& o, const token* tok);
177a8ead 337 void print_error (const semantic_error& e);
1b1b4ceb 338 void print_error_source (std::ostream&, std::string&, const token* tok);
cfd621bc 339 void print_warning (const std::string& w, const token* tok = 0);
aa4d21c0 340 void printscript(std::ostream& o);
b20febf3 341
28f569c2 342 // NB: It is very important for all of the above (and below) fields
85007c04
DB
343 // to be cleared in the systemtap_session ctor (session.cxx).
344};
345
177a8ead 346
49abf162 347// global counter of SIGINT/SIGTERM's received
85007c04
DB
348extern int pending_interrupts;
349
177a8ead 350#endif // SESSION_H
73267b89
JS
351
352/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 1.900026 seconds and 5 git commands to generate.