]> sourceware.org Git - systemtap.git/blob - elaborate.h
Add a function for getting a probe's script location
[systemtap.git] / elaborate.h
1 // -*- C++ -*-
2 // Copyright (C) 2005-2010 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 ELABORATE_H
10 #define ELABORATE_H
11
12 #include "staptree.h"
13 #include "parse.h"
14 #include <string>
15 #include <vector>
16 //#include <iostream>
17 #include <iosfwd>
18 #include <sstream>
19 #include <map>
20 #include <list>
21
22 extern "C" {
23 #include <elfutils/libdw.h>
24 }
25
26 // ------------------------------------------------------------------------
27
28 struct derived_probe;
29 struct match_node;
30
31 struct symresolution_info: public traversing_visitor
32 {
33 protected:
34 systemtap_session& session;
35
36 public:
37 functiondecl* current_function;
38 derived_probe* current_probe;
39 symresolution_info (systemtap_session& s);
40
41 vardecl* find_var (const std::string& name, int arity, const token *tok);
42 functiondecl* find_function (const std::string& name, unsigned arity);
43
44 void visit_block (block *s);
45 void visit_symbol (symbol* e);
46 void visit_foreach_loop (foreach_loop* e);
47 void visit_arrayindex (arrayindex* e);
48 void visit_functioncall (functioncall* e);
49 void visit_delete_statement (delete_statement* s);
50 };
51
52
53 struct typeresolution_info: public visitor
54 {
55 typeresolution_info (systemtap_session& s);
56 systemtap_session& session;
57 unsigned num_newly_resolved;
58 unsigned num_still_unresolved;
59 bool assert_resolvability;
60 functiondecl* current_function;
61 derived_probe* current_probe;
62 std::vector <const token*> resolved_toks; // account for type mis-
63 std::vector <const token*> printed_toks; // matches (BZ 9719)
64
65 void check_arg_type (exp_type wanted, expression* arg);
66 void check_local (vardecl* v);
67 void mismatch (const token* tok, exp_type t1, exp_type t2);
68 void unresolved (const token* tok);
69 void resolved (const token* tok, exp_type t);
70 void invalid (const token* tok, exp_type t);
71
72 exp_type t; // implicit parameter for nested visit call; may clobber
73
74 void visit_block (block* s);
75 void visit_try_block (try_block* s);
76 void visit_embeddedcode (embeddedcode* s);
77 void visit_null_statement (null_statement* s);
78 void visit_expr_statement (expr_statement* s);
79 void visit_if_statement (if_statement* s);
80 void visit_for_loop (for_loop* s);
81 void visit_foreach_loop (foreach_loop* s);
82 void visit_return_statement (return_statement* s);
83 void visit_delete_statement (delete_statement* s);
84 void visit_next_statement (next_statement* s);
85 void visit_break_statement (break_statement* s);
86 void visit_continue_statement (continue_statement* s);
87 void visit_literal_string (literal_string* e);
88 void visit_literal_number (literal_number* e);
89 void visit_embedded_expr (embedded_expr* e);
90 void visit_binary_expression (binary_expression* e);
91 void visit_unary_expression (unary_expression* e);
92 void visit_pre_crement (pre_crement* e);
93 void visit_post_crement (post_crement* e);
94 void visit_logical_or_expr (logical_or_expr* e);
95 void visit_logical_and_expr (logical_and_expr* e);
96 void visit_array_in (array_in* e);
97 void visit_comparison (comparison* e);
98 void visit_concatenation (concatenation* e);
99 void visit_ternary_expression (ternary_expression* e);
100 void visit_assignment (assignment* e);
101 void visit_symbol (symbol* e);
102 void visit_target_symbol (target_symbol* e);
103 void visit_arrayindex (arrayindex* e);
104 void visit_functioncall (functioncall* e);
105 void visit_print_format (print_format* e);
106 void visit_stat_op (stat_op* e);
107 void visit_hist_op (hist_op* e);
108 void visit_cast_op (cast_op* e);
109 void visit_defined_op (defined_op* e);
110 };
111
112
113 // ------------------------------------------------------------------------
114
115
116 // A derived_probe is a probe that has been elaborated by
117 // binding to a matching provider. The locations std::vector
118 // may be smaller or larger than the base probe, since a
119 // provider may transform it.
120
121 class translator_output;
122 class derived_probe_group;
123
124 struct derived_probe: public probe
125 {
126 derived_probe (probe* b);
127 derived_probe (probe* b, probe_point* l);
128 probe* base; // the original parsed probe
129 virtual const probe* basest () const { return base->basest(); }
130 virtual const probe* almost_basest () const { return base->almost_basest() ?: this; }
131 virtual ~derived_probe () {}
132 virtual void join_group (systemtap_session& s) = 0;
133 virtual probe_point* sole_location () const;
134 virtual probe_point* script_location () const;
135 virtual void printsig (std::ostream &o) const;
136 // return arguments of probe if there
137 virtual void getargs (std::list<std::string> &arg_set) const {}
138 void printsig_nested (std::ostream &o) const;
139 virtual void collect_derivation_chain (std::vector<probe*> &probes_list);
140
141 virtual void print_dupe_stamp(std::ostream&) {}
142 // To aid duplication elimination, print a stamp which uniquely identifies
143 // the code that will be added to the probe body. (Doesn't need to be the
144 // actual code...)
145
146 virtual void initialize_probe_context_vars (translator_output*) {}
147 // From within unparser::emit_probe, initialized any extra variables
148 // in this probe's context locals.
149
150 virtual void emit_probe_local_init (translator_output*) {}
151 // From within unparser::emit_probe, emit any extra processing block
152 // for this probe.
153
154 virtual void emit_unprivileged_assertion (translator_output*);
155 // From within unparser::emit_probe, emit any unprivileged mode
156 // checking for this probe.
157
158 public:
159 static void emit_common_header (translator_output* o);
160 // from c_unparser::emit_common_header
161 // XXX: probably can move this stuff to a probe_group::emit_module_decls
162
163 static void emit_process_owner_assertion (translator_output*);
164 // From within unparser::emit_probe, emit a check that the current
165 // process belongs to the user.
166
167 static void print_dupe_stamp_unprivileged(std::ostream& o);
168 static void print_dupe_stamp_unprivileged_process_owner(std::ostream& o);
169
170 virtual bool needs_global_locks () { return true; }
171 // by default, probes need locks around global variables
172
173 // Location of semaphores to activate sdt probes
174 Dwarf_Addr sdt_semaphore_addr;
175 };
176
177 // ------------------------------------------------------------------------
178
179 struct unparser;
180
181 // Various derived classes derived_probe_group manage the
182 // registration/invocation/unregistration of sibling probes.
183 struct derived_probe_group
184 {
185 virtual ~derived_probe_group () {}
186
187 virtual void emit_module_decls (systemtap_session& s) = 0;
188 // The _decls-generated code may assume that declarations such as
189 // the context, embedded-C code, function and probe handler bodies
190 // are all already generated. That is, _decls is called near the
191 // end of the code generation process. It should minimize the
192 // number of separate variables (and to a lesser extent, their
193 // size).
194
195 virtual void emit_module_init (systemtap_session& s) = 0;
196 // The _init-generated code may assume that it is called only once.
197 // If that code fails at run time, it must set rc=1 and roll back
198 // any partial initializations, for its _exit friend will NOT be
199 // invoked. The generated code may use pre-declared "int i, j;".
200
201 virtual void emit_module_exit (systemtap_session& s) = 0;
202 // The _exit-generated code may assume that it is executed exactly
203 // zero times (if the _init-generated code failed) or once. (_exit
204 // itself may be called a few times, to generate the code in a few
205 // different places in the probe module.)
206 // The generated code may use pre-declared "int i, j;".
207 };
208
209
210 // ------------------------------------------------------------------------
211
212 typedef std::map<std::string, literal*> literal_map_t;
213
214 struct derived_probe_builder
215 {
216 virtual void build(systemtap_session & sess,
217 probe* base,
218 probe_point* location,
219 literal_map_t const & parameters,
220 std::vector<derived_probe*> & finished_results) = 0;
221 virtual ~derived_probe_builder() {}
222 virtual void build_no_more (systemtap_session &) {}
223
224 static bool has_null_param (literal_map_t const & parameters,
225 const std::string& key);
226 static bool get_param (literal_map_t const & parameters,
227 const std::string& key, std::string& value);
228 static bool get_param (literal_map_t const & parameters,
229 const std::string& key, int64_t& value);
230 };
231
232
233 struct
234 match_key
235 {
236 std::string name;
237 bool have_parameter;
238 exp_type parameter_type;
239
240 match_key(std::string const & n);
241 match_key(probe_point::component const & c);
242
243 match_key & with_number();
244 match_key & with_string();
245 std::string str() const;
246 bool operator<(match_key const & other) const;
247 bool globmatch(match_key const & other) const;
248 };
249
250
251 class
252 match_node
253 {
254 typedef std::map<match_key, match_node*> sub_map_t;
255 typedef std::map<match_key, match_node*>::iterator sub_map_iterator_t;
256 sub_map_t sub;
257 std::vector<derived_probe_builder*> ends;
258
259 public:
260 match_node();
261
262 void find_and_build (systemtap_session& s,
263 probe* p, probe_point *loc, unsigned pos,
264 std::vector<derived_probe *>& results);
265 void build_no_more (systemtap_session &s);
266
267 match_node* bind(match_key const & k);
268 match_node* bind(std::string const & k);
269 match_node* bind_str(std::string const & k);
270 match_node* bind_num(std::string const & k);
271 match_node* bind_unprivileged(bool b = true);
272 void bind(derived_probe_builder* e);
273
274 private:
275 bool unprivileged_ok;
276 };
277
278 // ------------------------------------------------------------------------
279
280 struct
281 alias_expansion_builder
282 : public derived_probe_builder
283 {
284 probe_alias * alias;
285
286 alias_expansion_builder(probe_alias * a)
287 : alias(a)
288 {}
289
290 virtual void build(systemtap_session & sess,
291 probe * use,
292 probe_point * location,
293 std::map<std::string, literal *> const &,
294 std::vector<derived_probe *> & finished_results);
295
296 bool checkForRecursiveExpansion (probe *use);
297 };
298
299 // ------------------------------------------------------------------------
300
301 /* struct systemtap_session moved to session.h */
302
303 int semantic_pass (systemtap_session& s);
304 void derive_probes (systemtap_session& s,
305 probe *p, std::vector<derived_probe*>& dps,
306 bool optional = false);
307
308 // A helper we use here and in translate, for pulling symbols out of lvalue
309 // expressions.
310 symbol * get_symbol_within_expression (expression *e);
311
312
313 struct unparser;
314
315
316 #endif // ELABORATE_H
317
318 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.05379 seconds and 6 git commands to generate.