elaborate.h - systemtap
Data types defined
Functions defined
Macros defined
Source code
#ifndef ELABORATE_H
#define ELABORATE_H
#include "staptree.h"
#include "parse.h"
#include <string>
#include <vector>
#include <iosfwd>
#include <sstream>
#include <map>
#include <list>
extern "C" {
#include <elfutils/libdw.h>
}
#include "privilege.h"
struct recursive_expansion_error : public semantic_error
{
~recursive_expansion_error () throw () {}
recursive_expansion_error (const std::string& msg, const token* t1=0):
SEMANTIC_ERROR (msg, t1) {}
recursive_expansion_error (const std::string& msg, const token* t1,
const token* t2):
SEMANTIC_ERROR (msg, t1, t2) {}
};
struct derived_probe;
class match_node;
struct symresolution_info: public traversing_visitor
{
protected:
systemtap_session& session;
public:
functiondecl* current_function;
derived_probe* current_probe;
symresolution_info (systemtap_session& s);
vardecl* find_var (const std::string& name, int arity, const token *tok);
functiondecl* find_function (const std::string& name, unsigned arity, const token *tok);
std::set<std::string> collect_functions(void);
void visit_block (block *s);
void visit_symbol (symbol* e);
void visit_foreach_loop (foreach_loop* e);
void visit_arrayindex (arrayindex* e);
void visit_arrayindex (arrayindex *e, bool wildcard_ok);
void visit_functioncall (functioncall* e);
void visit_delete_statement (delete_statement* s);
void visit_array_in (array_in *e);
};
struct typeresolution_info: public visitor
{
typeresolution_info (systemtap_session& s);
systemtap_session& session;
unsigned num_newly_resolved;
unsigned num_still_unresolved;
unsigned num_available_autocasts;
bool assert_resolvability;
int mismatch_complexity;
functiondecl* current_function;
derived_probe* current_probe;
struct resolved_type
{
const token *tok;
const symboldecl *decl;
int index;
resolved_type(const token *ct, const symboldecl *cdecl, int cindex):
tok(ct), decl(cdecl), index(cindex) {}
};
std::vector<resolved_type> resolved_types;
void check_arg_type (exp_type wanted, expression* arg);
void check_local (vardecl* v);
void unresolved (const token* tok);
void invalid (const token* tok, exp_type t);
void mismatch (const binary_expression* e);
void mismatch (const token* tok, exp_type t1, exp_type t2);
void mismatch (const token* tok, exp_type type,
const symboldecl* decl, int index = -1);
void resolved (const token* tok, exp_type type,
const symboldecl* decl = NULL, int index = -1);
void resolved_details (const exp_type_ptr& src, exp_type_ptr& dest);
exp_type t;
const exp_type_ptr null_type;
void visit_block (block* s);
void visit_try_block (try_block* s);
void visit_embeddedcode (embeddedcode* s);
void visit_null_statement (null_statement* s);
void visit_expr_statement (expr_statement* s);
void visit_if_statement (if_statement* s);
void visit_for_loop (for_loop* s);
void visit_foreach_loop (foreach_loop* s);
void visit_return_statement (return_statement* s);
void visit_delete_statement (delete_statement* s);
void visit_next_statement (next_statement* s);
void visit_break_statement (break_statement* s);
void visit_continue_statement (continue_statement* s);
void visit_literal_string (literal_string* e);
void visit_literal_number (literal_number* e);
void visit_embedded_expr (embedded_expr* e);
void visit_binary_expression (binary_expression* e);
void visit_unary_expression (unary_expression* e);
void visit_pre_crement (pre_crement* e);
void visit_post_crement (post_crement* e);
void visit_logical_or_expr (logical_or_expr* e);
void visit_logical_and_expr (logical_and_expr* e);
void visit_array_in (array_in* e);
void visit_regex_query (regex_query* e);
void visit_comparison (comparison* e);
void visit_concatenation (concatenation* e);
void visit_ternary_expression (ternary_expression* e);
void visit_assignment (assignment* e);
void visit_symbol (symbol* e);
void visit_target_symbol (target_symbol* e);
void visit_arrayindex (arrayindex* e);
void visit_functioncall (functioncall* e);
void visit_print_format (print_format* e);
void visit_stat_op (stat_op* e);
void visit_hist_op (hist_op* e);
void visit_cast_op (cast_op* e);
void visit_autocast_op (autocast_op* e);
void visit_atvar_op (atvar_op* e);
void visit_defined_op (defined_op* e);
void visit_entry_op (entry_op* e);
void visit_perf_op (perf_op* e);
};
class translator_output;
struct derived_probe_group;
struct derived_probe: public probe
{
derived_probe (probe* b, probe_point* l, bool rewrite_loc=false);
probe* base; probe_point* base_pp; derived_probe_group* group; virtual ~derived_probe () {}
virtual void join_group (systemtap_session& s) = 0;
virtual probe_point* sole_location () const;
virtual probe_point* script_location () const;
virtual void printsig (std::ostream &o) const;
virtual void getargs (std::list<std::string> &) const {}
void printsig_nested (std::ostream &o) const;
virtual void collect_derivation_chain (std::vector<probe*> &probes_list) const;
virtual void collect_derivation_pp_chain (std::vector<probe_point*> &pp_list) const;
std::string derived_locations ();
virtual void print_dupe_stamp(std::ostream&) {}
virtual void initialize_probe_context_vars (translator_output*) {}
virtual void emit_probe_local_init (systemtap_session& s, translator_output*) {}
virtual void emit_privilege_assertion (translator_output*);
public:
static void emit_common_header (translator_output* o);
XXX
static void emit_process_owner_assertion (translator_output*);
static void print_dupe_stamp_unprivileged(std::ostream& o);
static void print_dupe_stamp_unprivileged_process_owner(std::ostream& o);
virtual bool needs_global_locks () { return true; }
Dwarf_Addr sdt_semaphore_addr;
std::set<std::string> perf_counter_refs;
unsigned session_index;
std::set<derived_probe*> probes_with_affected_conditions;
};
struct unparser;
struct derived_probe_group
{
virtual ~derived_probe_group () {}
virtual void emit_kernel_module_init (systemtap_session& s) {}
virtual void emit_kernel_module_exit (systemtap_session& s) {}
virtual void emit_module_decls (systemtap_session& s) = 0;
virtual void emit_module_init (systemtap_session& s) = 0;
virtual void emit_module_post_init (systemtap_session& s) {}
virtual void emit_module_refresh (systemtap_session& s) {}
virtual void emit_module_exit (systemtap_session& s) = 0;
virtual bool otf_supported (systemtap_session& s) { return false; }
virtual bool otf_safe_context (systemtap_session& s) { return false; }
};
typedef std::map<std::string, literal*> literal_map_t;
struct derived_probe_builder
{
virtual void build(systemtap_session & sess,
probe* base,
probe_point* location,
literal_map_t const & parameters,
std::vector<derived_probe*> & finished_results) = 0;
virtual void build_with_suffix(systemtap_session & sess,
probe * use,
probe_point * location,
std::map<std::string, literal *>
const & parameters,
std::vector<derived_probe *>
& finished_results,
std::vector<probe_point::component *>
const & suffix);
virtual ~derived_probe_builder() {}
virtual void build_no_more (systemtap_session &) {}
virtual bool is_alias () const { return false; }
static bool has_null_param (literal_map_t const & parameters,
const std::string& key);
static bool get_param (literal_map_t const & parameters,
const std::string& key, std::string& value);
static bool get_param (literal_map_t const & parameters,
const std::string& key, int64_t& value);
static bool has_param (literal_map_t const & parameters,
const std::string& key);
};
struct
match_key
{
std::string name;
bool have_parameter;
exp_type parameter_type;
match_key(std::string const & n);
match_key(probe_point::component const & c);
match_key & with_number();
match_key & with_string();
std::string str() const;
bool operator<(match_key const & other) const;
bool globmatch(match_key const & other) const;
};
class
match_node
{
typedef std::map<match_key, match_node*> sub_map_t;
typedef std::map<match_key, match_node*>::iterator sub_map_iterator_t;
sub_map_t sub;
std::vector<derived_probe_builder*> ends;
public:
match_node();
void find_and_build (systemtap_session& s,
probe* p, probe_point *loc, unsigned pos,
std::vector<derived_probe *>& results);
std::string suggest_functors(std::string functor);
void try_suffix_expansion (systemtap_session& s,
probe *p, probe_point *loc, unsigned pos,
std::vector<derived_probe *>& results);
void build_no_more (systemtap_session &s);
void dump (systemtap_session &s, const std::string &name = "");
match_node* bind(match_key const & k);
match_node* bind(std::string const & k);
match_node* bind_str(std::string const & k);
match_node* bind_num(std::string const & k);
match_node* bind_privilege(privilege_t p = privilege_t (pr_stapdev | pr_stapsys));
void bind(derived_probe_builder* e);
private:
privilege_t privilege;
};
struct
alias_expansion_builder
: public derived_probe_builder
{
probe_alias * alias;
alias_expansion_builder(probe_alias * a)
: alias(a)
{}
virtual void build(systemtap_session & sess,
probe * use,
probe_point * location,
std::map<std::string, literal *> const &,
std::vector<derived_probe *> & finished_results);
virtual void build_with_suffix(systemtap_session & sess,
probe * use,
probe_point * location,
std::map<std::string, literal *>
const &,
std::vector<derived_probe *>
& finished_results,
std::vector<probe_point::component *>
const & suffix);
virtual bool is_alias () const { return true; }
bool checkForRecursiveExpansion (probe *use);
};
int semantic_pass (systemtap_session& s);
void derive_probes (systemtap_session& s,
probe *p, std::vector<derived_probe*>& dps,
bool optional = false, bool rethrow_errors = false);
symbol * get_symbol_within_expression (expression *e);
struct unparser;
#endif