2 // Copyright (C) 2005-2010 Red Hat Inc.
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
23 #include <elfutils/libdw.h>
26 // ------------------------------------------------------------------------
31 struct symresolution_info
: public traversing_visitor
34 systemtap_session
& session
;
37 functiondecl
* current_function
;
38 derived_probe
* current_probe
;
39 symresolution_info (systemtap_session
& s
);
41 vardecl
* find_var (const std::string
& name
, int arity
, const token
*tok
);
42 functiondecl
* find_function (const std::string
& name
, unsigned arity
);
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
);
53 struct typeresolution_info
: public visitor
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)
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
);
72 exp_type t
; // implicit parameter for nested visit call; may clobber
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
);
113 // ------------------------------------------------------------------------
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.
121 class translator_output
;
122 class derived_probe_group
;
124 struct derived_probe
: public probe
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
);
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
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.
150 virtual void emit_probe_local_init (translator_output
*) {}
151 // From within unparser::emit_probe, emit any extra processing block
154 virtual void emit_unprivileged_assertion (translator_output
*);
155 // From within unparser::emit_probe, emit any unprivileged mode
156 // checking for this probe.
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
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.
167 static void print_dupe_stamp_unprivileged(std::ostream
& o
);
168 static void print_dupe_stamp_unprivileged_process_owner(std::ostream
& o
);
170 virtual bool needs_global_locks () { return true; }
171 // by default, probes need locks around global variables
173 // Location of semaphores to activate sdt probes
174 Dwarf_Addr sdt_semaphore_addr
;
177 // ------------------------------------------------------------------------
181 // Various derived classes derived_probe_group manage the
182 // registration/invocation/unregistration of sibling probes.
183 struct derived_probe_group
185 virtual ~derived_probe_group () {}
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
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;".
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;".
210 // ------------------------------------------------------------------------
212 typedef std::map
<std::string
, literal
*> literal_map_t
;
214 struct derived_probe_builder
216 virtual void build(systemtap_session
& sess
,
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
&) {}
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
);
238 exp_type parameter_type
;
240 match_key(std::string
const & n
);
241 match_key(probe_point::component
const & c
);
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;
254 typedef std::map
<match_key
, match_node
*> sub_map_t
;
255 typedef std::map
<match_key
, match_node
*>::iterator sub_map_iterator_t
;
257 std::vector
<derived_probe_builder
*> ends
;
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
);
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
);
275 bool unprivileged_ok
;
278 // ------------------------------------------------------------------------
281 alias_expansion_builder
282 : public derived_probe_builder
286 alias_expansion_builder(probe_alias
* a
)
290 virtual void build(systemtap_session
& sess
,
292 probe_point
* location
,
293 std::map
<std::string
, literal
*> const &,
294 std::vector
<derived_probe
*> & finished_results
);
296 bool checkForRecursiveExpansion (probe
*use
);
299 // ------------------------------------------------------------------------
301 /* struct systemtap_session moved to session.h */
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);
308 // A helper we use here and in translate, for pulling symbols out of lvalue
310 symbol
* get_symbol_within_expression (expression
*e
);
316 #endif // ELABORATE_H
318 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */