]>
Commit | Line | Data |
---|---|---|
1 | // -*- C++ -*- | |
2 | // Copyright (C) 2005-2011 Red Hat Inc. | |
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 | ||
12 | #include "config.h" | |
13 | #include <libintl.h> | |
14 | #include <locale.h> | |
15 | ||
16 | #include <list> | |
17 | #include <string> | |
18 | #include <vector> | |
19 | #include <iostream> | |
20 | #include <sstream> | |
21 | #include <map> | |
22 | #include <set> | |
23 | ||
24 | extern "C" { | |
25 | #include <signal.h> | |
26 | #include <elfutils/libdw.h> | |
27 | } | |
28 | ||
29 | #if ENABLE_NLS | |
30 | #define _(string) gettext(string) | |
31 | #define _N(string, string_plural, count) \ | |
32 | ngettext((string), (string_plural), (count)) | |
33 | #else | |
34 | #define _(string) (string) | |
35 | #define _N(string, string_plural, count) \ | |
36 | ( (count) == 1 ? (string) : (string_plural) ) | |
37 | #endif | |
38 | #define _F(format, ...) autosprintf(_(format), __VA_ARGS__) | |
39 | #define _NF(format, format_plural, count, ...) \ | |
40 | autosprintf(_N((format), (format_plural), (count)), __VA_ARGS__) | |
41 | ||
42 | // forward decls for all referenced systemtap types | |
43 | struct hash; | |
44 | struct match_node; | |
45 | struct stapfile; | |
46 | struct vardecl; | |
47 | struct token; | |
48 | struct functiondecl; | |
49 | struct derived_probe; | |
50 | struct be_derived_probe_group; | |
51 | struct dwarf_derived_probe_group; | |
52 | struct kprobe_derived_probe_group; | |
53 | struct hwbkpt_derived_probe_group; | |
54 | struct perf_derived_probe_group; | |
55 | struct uprobe_derived_probe_group; | |
56 | struct utrace_derived_probe_group; | |
57 | struct itrace_derived_probe_group; | |
58 | struct task_finder_derived_probe_group; | |
59 | struct timer_derived_probe_group; | |
60 | struct profile_derived_probe_group; | |
61 | struct mark_derived_probe_group; | |
62 | struct tracepoint_derived_probe_group; | |
63 | struct hrtimer_derived_probe_group; | |
64 | struct procfs_derived_probe_group; | |
65 | struct embeddedcode; | |
66 | struct translator_output; | |
67 | struct unparser; | |
68 | struct semantic_error; | |
69 | struct module_cache; | |
70 | struct update_visitor; | |
71 | struct compile_server_cache; | |
72 | ||
73 | // XXX: a generalized form of this descriptor could be associated with | |
74 | // a vardecl instead of out here at the systemtap_session level. | |
75 | struct statistic_decl | |
76 | { | |
77 | statistic_decl() | |
78 | : type(none), | |
79 | linear_low(0), linear_high(0), linear_step(0) | |
80 | {} | |
81 | enum { none, linear, logarithmic } type; | |
82 | int64_t linear_low; | |
83 | int64_t linear_high; | |
84 | int64_t linear_step; | |
85 | bool operator==(statistic_decl const & other) | |
86 | { | |
87 | return type == other.type | |
88 | && linear_low == other.linear_low | |
89 | && linear_high == other.linear_high | |
90 | && linear_step == other.linear_step; | |
91 | } | |
92 | }; | |
93 | ||
94 | struct systemtap_session | |
95 | { | |
96 | private: | |
97 | // disable implicit constructors by not implementing these | |
98 | systemtap_session (const systemtap_session& other); | |
99 | systemtap_session& operator= (const systemtap_session& other); | |
100 | ||
101 | // copy constructor used by ::clone() | |
102 | systemtap_session (const systemtap_session& other, | |
103 | const std::string& arch, | |
104 | const std::string& kern); | |
105 | ||
106 | public: | |
107 | systemtap_session (); | |
108 | ~systemtap_session (); | |
109 | ||
110 | // NB: It is very important for all of the above (and below) fields | |
111 | // to be cleared in the systemtap_session ctor (session.cxx). | |
112 | void setup_kernel_release (const char* kstr); | |
113 | void insert_loaded_modules (); | |
114 | ||
115 | // command line parsing | |
116 | int parse_cmdline (int argc, char * const argv []); | |
117 | void version (); | |
118 | void usage (int exitcode); | |
119 | void check_options (int argc, char * const argv []); | |
120 | static const char* morehelp; | |
121 | ||
122 | // NB: It is very important for all of the above (and below) fields | |
123 | // to be cleared in the systemtap_session ctor (session.cxx). | |
124 | ||
125 | // command line args | |
126 | std::string script_file; // FILE | |
127 | std::string cmdline_script; // -e PROGRAM | |
128 | bool have_script; | |
129 | std::vector<std::string> include_path; | |
130 | int include_arg_start; | |
131 | std::vector<std::string> macros; | |
132 | std::vector<std::string> args; | |
133 | std::vector<std::string> kbuildflags; | |
134 | std::vector<std::string> globalopts; // -G var=val | |
135 | std::string release; | |
136 | std::string kernel_release; | |
137 | std::string kernel_base_release; | |
138 | std::string kernel_build_tree; | |
139 | std::string kernel_source_tree; | |
140 | std::map<std::string,std::string> kernel_config; | |
141 | std::set<std::string> kernel_exports; | |
142 | std::string machine; | |
143 | std::string architecture; | |
144 | std::string runtime_path; | |
145 | bool runtime_specified; | |
146 | std::string data_path; | |
147 | std::string module_name; | |
148 | std::string stapconf_name; | |
149 | std::string output_file; | |
150 | std::string size_option; | |
151 | std::string cmd; | |
152 | std::string compatible; // use (strverscmp(s.compatible.c_str(), "N.M") >= 0) | |
153 | int target_pid; | |
154 | int last_pass; | |
155 | unsigned perpass_verbose[5]; | |
156 | unsigned verbose; | |
157 | bool timing; | |
158 | bool save_module; | |
159 | bool modname_given; | |
160 | bool keep_tmpdir; | |
161 | bool guru_mode; | |
162 | bool listing_mode; | |
163 | bool listing_mode_vars; | |
164 | bool bulk_mode; | |
165 | bool unoptimized; | |
166 | bool suppress_warnings; | |
167 | bool panic_warnings; | |
168 | int buffer_size; | |
169 | bool prologue_searching; | |
170 | bool tapset_compile_coverage; | |
171 | bool need_uprobes; | |
172 | bool need_unwind; | |
173 | bool need_symbols; | |
174 | std::string uprobes_path; | |
175 | std::string uprobes_hash; | |
176 | bool load_only; // flight recorder mode | |
177 | bool omit_werror; | |
178 | bool unprivileged; | |
179 | bool systemtap_v_check; | |
180 | bool tmpdir_opt_set; | |
181 | bool dump_probe_types; | |
182 | int download_dbinfo; | |
183 | ||
184 | // NB: It is very important for all of the above (and below) fields | |
185 | // to be cleared in the systemtap_session ctor (session.cxx). | |
186 | ||
187 | // Client/server | |
188 | #if HAVE_NSS | |
189 | static bool NSPR_Initialized; // only once for all sessions | |
190 | void NSPR_init (); | |
191 | #endif | |
192 | bool client_options; | |
193 | std::string client_options_disallowed; | |
194 | std::vector<std::string> server_status_strings; | |
195 | std::vector<std::string> specified_servers; | |
196 | bool automatic_server_mode; | |
197 | std::string server_trust_spec; | |
198 | std::vector<std::string> server_args; | |
199 | std::string winning_server; | |
200 | compile_server_cache* server_cache; | |
201 | ||
202 | // NB: It is very important for all of the above (and below) fields | |
203 | // to be cleared in the systemtap_session ctor (session.cxx). | |
204 | ||
205 | // Mechanism for retrying compilation with a compile server should it fail due | |
206 | // to lack of resources on the local host. | |
207 | // Once it has been decided not to try the server (e.g. syntax error), | |
208 | // that decision cannot be changed. | |
209 | int try_server_status; | |
210 | bool use_server_on_error; | |
211 | ||
212 | enum { try_server_unset, dont_try_server, do_try_server }; | |
213 | void init_try_server (); | |
214 | void set_try_server (int t = do_try_server); | |
215 | bool try_server () const { return try_server_status == do_try_server; } | |
216 | ||
217 | // NB: It is very important for all of the above (and below) fields | |
218 | // to be cleared in the systemtap_session ctor (session.cxx). | |
219 | ||
220 | // Remote execution | |
221 | std::vector<std::string> remote_uris; | |
222 | bool use_remote_prefix; | |
223 | typedef std::map<std::pair<std::string, std::string>, systemtap_session*> session_map_t; | |
224 | session_map_t subsessions; | |
225 | systemtap_session* clone(const std::string& arch, const std::string& release); | |
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 | ||
230 | // Cache data | |
231 | bool use_cache; // control all caching | |
232 | bool use_script_cache; // control caching of pass-3/4 output | |
233 | bool poison_cache; // consider the cache to be write-only | |
234 | std::string cache_path; // usually ~/.systemtap/cache | |
235 | std::string hash_path; // path to the cached script module | |
236 | std::string stapconf_path; // path to the cached stapconf | |
237 | hash *base_hash; // hash common to all caching | |
238 | ||
239 | // dwarfless operation | |
240 | bool consult_symtab; | |
241 | std::string kernel_symtab_path; | |
242 | bool ignore_vmlinux; | |
243 | bool ignore_dwarf; | |
244 | ||
245 | // Skip bad $ vars | |
246 | bool skip_badvars; | |
247 | ||
248 | // NB: It is very important for all of the above (and below) fields | |
249 | // to be cleared in the systemtap_session ctor (session.cxx). | |
250 | ||
251 | // temporary directory for module builds etc. | |
252 | // hazardous - it is "rm -rf"'d at exit | |
253 | std::string tmpdir; | |
254 | std::string translated_source; // C source code | |
255 | ||
256 | match_node* pattern_root; | |
257 | void register_library_aliases(); | |
258 | ||
259 | // parse trees for the various script files | |
260 | stapfile* user_file; | |
261 | std::vector<stapfile*> library_files; | |
262 | ||
263 | // filters to run over all code before symbol resolution | |
264 | // e.g. @cast expansion | |
265 | std::vector<update_visitor*> code_filters; | |
266 | ||
267 | // resolved globals/functions/probes for the run as a whole | |
268 | std::vector<stapfile*> files; | |
269 | std::vector<vardecl*> globals; | |
270 | std::map<std::string,functiondecl*> functions; | |
271 | std::vector<derived_probe*> probes; // see also *_probes groups below | |
272 | std::vector<embeddedcode*> embeds; | |
273 | std::map<std::string, statistic_decl> stat_decls; | |
274 | // track things that are removed | |
275 | std::vector<vardecl*> unused_globals; | |
276 | std::vector<derived_probe*> unused_probes; // see also *_probes groups below | |
277 | std::vector<functiondecl*> unused_functions; | |
278 | // XXX: vector<*> instead please? | |
279 | ||
280 | // Every probe in these groups must also appear in the | |
281 | // session.probes vector. | |
282 | be_derived_probe_group* be_derived_probes; | |
283 | dwarf_derived_probe_group* dwarf_derived_probes; | |
284 | kprobe_derived_probe_group* kprobe_derived_probes; | |
285 | hwbkpt_derived_probe_group* hwbkpt_derived_probes; | |
286 | perf_derived_probe_group* perf_derived_probes; | |
287 | uprobe_derived_probe_group* uprobe_derived_probes; | |
288 | utrace_derived_probe_group* utrace_derived_probes; | |
289 | itrace_derived_probe_group* itrace_derived_probes; | |
290 | task_finder_derived_probe_group* task_finder_derived_probes; | |
291 | timer_derived_probe_group* timer_derived_probes; | |
292 | profile_derived_probe_group* profile_derived_probes; | |
293 | mark_derived_probe_group* mark_derived_probes; | |
294 | tracepoint_derived_probe_group* tracepoint_derived_probes; | |
295 | hrtimer_derived_probe_group* hrtimer_derived_probes; | |
296 | procfs_derived_probe_group* procfs_derived_probes; | |
297 | ||
298 | // NB: It is very important for all of the above (and below) fields | |
299 | // to be cleared in the systemtap_session ctor (session.cxx). | |
300 | ||
301 | // unparser data | |
302 | translator_output* op; | |
303 | unparser* up; | |
304 | ||
305 | // some symbol addresses | |
306 | // XXX: these belong elsewhere; perhaps the dwflpp instance | |
307 | Dwarf_Addr sym_kprobes_text_start; | |
308 | Dwarf_Addr sym_kprobes_text_end; | |
309 | Dwarf_Addr sym_stext; | |
310 | ||
311 | // List of libdwfl module names to extract symbol/unwind data for. | |
312 | std::set<std::string> unwindsym_modules; | |
313 | bool unwindsym_ldd; | |
314 | struct module_cache* module_cache; | |
315 | ||
316 | // NB: It is very important for all of the above (and below) fields | |
317 | // to be cleared in the systemtap_session ctor (session.cxx). | |
318 | ||
319 | std::set<std::string> seen_errors; | |
320 | std::set<std::string> seen_warnings; | |
321 | unsigned num_errors () { return seen_errors.size() + (panic_warnings ? seen_warnings.size() : 0); } | |
322 | ||
323 | std::set<std::string> rpms_to_install; | |
324 | ||
325 | // void print_error (const parse_error& e); | |
326 | const token* last_token; | |
327 | void print_token (std::ostream& o, const token* tok); | |
328 | void print_error (const semantic_error& e); | |
329 | void print_error_source (std::ostream&, std::string&, const token* tok); | |
330 | void print_warning (const std::string& w, const token* tok = 0); | |
331 | void printscript(std::ostream& o); | |
332 | ||
333 | // NB: It is very important for all of the above (and below) fields | |
334 | // to be cleared in the systemtap_session ctor (session.cxx). | |
335 | }; | |
336 | ||
337 | ||
338 | // global counter of SIGINT/SIGTERM's received | |
339 | extern int pending_interrupts; | |
340 | ||
341 | #endif // SESSION_H | |
342 | ||
343 | /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ |