From 440f755a3b886c6cfdca9f523302f1f0938f7fec Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 12 May 2009 19:33:14 -0700 Subject: Move dfwlpp into its own file It's not a terribly clean split, but moving it helps reveals some of the knots that need to be untangled. --- dwflpp.h | 383 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 383 insertions(+) create mode 100644 dwflpp.h (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h new file mode 100644 index 00000000..23015fdc --- /dev/null +++ b/dwflpp.h @@ -0,0 +1,383 @@ +// C++ interface to dwfl +// Copyright (C) 2005-2009 Red Hat Inc. +// Copyright (C) 2005-2007 Intel Corporation. +// Copyright (C) 2008 James.Bottomley@HansenPartnership.com +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. + +#ifndef DWFLPP_H +#define DWFLPP_H + +#include "config.h" +#include "dwarf_wrappers.h" +#include "elaborate.h" +#include "session.h" + +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_TR1_UNORDERED_MAP +#include +#else +#include +#endif + +extern "C" { +#include +} + + +struct func_info; +struct inline_instance_info; +struct symbol_table; +struct base_query; +struct dwarf_query; + +enum line_t { ABSOLUTE, RELATIVE, RANGE, WILDCARD }; +enum info_status { info_unknown, info_present, info_absent }; + +#ifdef HAVE_TR1_UNORDERED_MAP +typedef std::tr1::unordered_map cu_function_cache_t; +typedef std::tr1::unordered_map mod_cu_function_cache_t; // module:cu -> function -> die +#else +struct stringhash { + // __gnu_cxx:: is needed because our own hash.h has an ambiguous hash<> decl too. + size_t operator() (const std::string& s) const + { __gnu_cxx::hash h; return h(s.c_str()); } +}; + +typedef __gnu_cxx::hash_map cu_function_cache_t; +typedef __gnu_cxx::hash_map mod_cu_function_cache_t; // module:cu -> function -> die +#endif + +typedef std::vector func_info_map_t; +typedef std::vector inline_instance_map_t; + + +/* XXX FIXME functions that dwflpp needs from tapsets.cxx */ +int query_cu (Dwarf_Die * cudie, void * arg); +int query_module (Dwfl_Module *mod, void **, const char *name, + Dwarf_Addr addr, void *arg); +func_info_map_t *get_filtered_functions(dwarf_query *q); +inline_instance_map_t *get_filtered_inlines(dwarf_query *q); +void add_label_name(dwarf_query *q, const char *name); + + +struct +module_info +{ + Dwfl_Module* mod; + const char* name; + std::string elf_path; + Dwarf_Addr addr; + Dwarf_Addr bias; + symbol_table *sym_table; + info_status dwarf_status; // module has dwarf info? + info_status symtab_status; // symbol table cached? + + void get_symtab(dwarf_query *q); + + module_info(const char *name) : + mod(NULL), + name(name), + addr(0), + bias(0), + sym_table(NULL), + dwarf_status(info_unknown), + symtab_status(info_unknown) + {} + + ~module_info(); +}; + + +struct +module_cache +{ + std::map cache; + bool paths_collected; + bool dwarf_collected; + + module_cache() : paths_collected(false), dwarf_collected(false) {} +}; + + +struct func_info +{ + func_info() + : decl_file(NULL), decl_line(-1), addr(0), prologue_end(0), weak(false) + { + std::memset(&die, 0, sizeof(die)); + } + std::string name; + char const * decl_file; + int decl_line; + Dwarf_Die die; + Dwarf_Addr addr; + Dwarf_Addr entrypc; + Dwarf_Addr prologue_end; + bool weak; + + // Comparison functor for list of functions sorted by address. The + // two versions that take a Dwarf_Addr let us use the STL algorithms + // upper_bound, equal_range et al., but we don't know whether the + // searched-for value will be passed as the first or the second + // argument. + struct Compare + { + bool operator() (const func_info* f1, const func_info* f2) const + { + return f1->addr < f2->addr; + } + // For doing lookups by address. + bool operator() (Dwarf_Addr addr, const func_info* f2) const + { + return addr < f2->addr; + } + bool operator() (const func_info* f1, Dwarf_Addr addr) const + { + return f1->addr < addr; + } + }; +}; + + +struct inline_instance_info +{ + inline_instance_info() + : decl_file(NULL), decl_line(-1) + { + std::memset(&die, 0, sizeof(die)); + } + std::string name; + char const * decl_file; + int decl_line; + Dwarf_Addr entrypc; + Dwarf_Die die; +}; + + +struct dwflpp +{ + systemtap_session & sess; + Dwfl * dwfl; + + // These are "current" values we focus on. + Dwfl_Module * module; + Dwarf * module_dwarf; + Dwarf_Addr module_bias; + module_info * mod_info; + + // These describe the current module's PC address range + Dwarf_Addr module_start; + Dwarf_Addr module_end; + + Dwarf_Die * cu; + Dwarf_Die * function; + + std::string module_name; + std::string cu_name; + std::string function_name; + + dwflpp(systemtap_session & session, const std::string& user_module=""); + ~dwflpp(); + + std::string const default_name(char const * in, char const *); + + void get_module_dwarf(bool required = false, bool report = true); + + void focus_on_module(Dwfl_Module * m, module_info * mi); + void focus_on_cu(Dwarf_Die * c); + void focus_on_function(Dwarf_Die * f); + void focus_on_module_containing_global_address(Dwarf_Addr a); + + void query_cu_containing_global_address(Dwarf_Addr a, void *arg); + void query_cu_containing_module_address(Dwarf_Addr a, void *arg); + + Dwarf_Addr module_address_to_global(Dwarf_Addr a); + Dwarf_Addr global_address_to_module(Dwarf_Addr a); + + bool module_name_matches(std::string pattern); + bool name_has_wildcard(std::string pattern); + bool module_name_final_match(std::string pattern); + + bool function_name_matches_pattern(std::string name, std::string pattern); + bool function_name_matches(std::string pattern); + bool function_name_final_match(std::string pattern); + + bool cu_name_matches(std::string pattern); + + void setup_kernel(bool debuginfo_needed = true); + void setup_user(const std::string& module_name, bool debuginfo_needed = true); + + void iterate_over_modules(int (* callback)(Dwfl_Module *, void **, + const char *, Dwarf_Addr, + void *), + base_query *data); + void query_modules(base_query *q); + + typedef std::map*> module_cu_cache_t; + module_cu_cache_t module_cu_cache; + + void iterate_over_cus (int (*callback)(Dwarf_Die * die, void * arg), + void * data); + + bool func_is_inline(); + + typedef std::map*> cu_inl_function_cache_t; + cu_inl_function_cache_t cu_inl_function_cache; + + static int cu_inl_function_caching_callback (Dwarf_Die* func, void *arg); + + void iterate_over_inline_instances (int (* callback)(Dwarf_Die * die, void * arg), + void * data); + + /* The global alias cache is used to resolve any DIE found in a + * module that is stubbed out with DW_AT_declaration with a defining + * DIE found in a different module. The current assumption is that + * this only applies to structures and unions, which have a global + * namespace (it deliberately only traverses program scope), so this + * cache is indexed by name. If other declaration lookups were + * added to it, it would have to be indexed by name and tag + */ + mod_cu_function_cache_t global_alias_cache; + static int global_alias_caching_callback(Dwarf_Die *die, void *arg); + + Dwarf_Die *declaration_resolve(const char *name); + + mod_cu_function_cache_t cu_function_cache; + + static int cu_function_caching_callback (Dwarf_Die* func, void *arg); + + int iterate_over_functions (int (* callback)(Dwarf_Die * func, base_query * q), + base_query * q, const std::string& function, + bool has_statement_num=false); + int iterate_over_globals (int (* callback)(Dwarf_Die *, void *), + void * data); + + bool has_single_line_record (dwarf_query * q, char const * srcfile, int lineno); + + void iterate_over_srcfile_lines (char const * srcfile, + int lines[2], + bool need_single_match, + enum line_t line_type, + void (* callback) (const dwarf_line_t& line, + void * arg), + void *data); + + void iterate_over_labels (Dwarf_Die *begin_die, + const char *sym, + const char *symfunction, + void *data, + void (* callback)(const std::string &, + const char *, + int, + Dwarf_Die *, + Dwarf_Addr, + dwarf_query *)); + + void collect_srcfiles_matching (std::string const & pattern, + std::set & filtered_srcfiles); + + void resolve_prologue_endings (func_info_map_t & funcs); + + bool function_entrypc (Dwarf_Addr * addr); + bool die_entrypc (Dwarf_Die * die, Dwarf_Addr * addr); + + void function_die (Dwarf_Die *d); + void function_file (char const ** c); + void function_line (int *linep); + + bool die_has_pc (Dwarf_Die & die, Dwarf_Addr pc); + + static void loc2c_error (void *, const char *fmt, ...); + + // This function generates code used for addressing computations of + // target variables. + void emit_address (struct obstack *pool, Dwarf_Addr address); + + static void loc2c_emit_address (void *arg, struct obstack *pool, + Dwarf_Addr address); + + void print_locals(Dwarf_Die *die, std::ostream &o); + + Dwarf_Attribute *find_variable_and_frame_base (Dwarf_Die *scope_die, + Dwarf_Addr pc, + std::string const & local, + const target_symbol *e, + Dwarf_Die *vardie, + Dwarf_Attribute *fb_attr_mem); + + + struct location *translate_location(struct obstack *pool, + Dwarf_Attribute *attr, + Dwarf_Addr pc, + Dwarf_Attribute *fb_attr, + struct location **tail, + const target_symbol *e); + + void print_members(Dwarf_Die *vardie, std::ostream &o); + + bool find_struct_member(const std::string& member, + Dwarf_Die *parentdie, + const target_symbol *e, + Dwarf_Die *memberdie, + std::vector& locs); + + Dwarf_Die *translate_components(struct obstack *pool, + struct location **tail, + Dwarf_Addr pc, + const target_symbol *e, + Dwarf_Die *vardie, + Dwarf_Die *die_mem, + Dwarf_Attribute *attr_mem); + + Dwarf_Die *resolve_unqualified_inner_typedie (Dwarf_Die *typedie_mem, + Dwarf_Attribute *attr_mem, + const target_symbol *e); + + void translate_final_fetch_or_store (struct obstack *pool, + struct location **tail, + Dwarf_Addr module_bias, + Dwarf_Die *die, + Dwarf_Attribute *attr_mem, + bool lvalue, + const target_symbol *e, + std::string &, + std::string &, + exp_type & ty); + + std::string express_as_string (std::string prelude, + std::string postlude, + struct location *head); + + std::string literal_stmt_for_local (Dwarf_Die *scope_die, + Dwarf_Addr pc, + std::string const & local, + const target_symbol *e, + bool lvalue, + exp_type & ty); + + + std::string literal_stmt_for_return (Dwarf_Die *scope_die, + Dwarf_Addr pc, + const target_symbol *e, + bool lvalue, + exp_type & ty); + + std::string literal_stmt_for_pointer (Dwarf_Die *type_die, + const target_symbol *e, + bool lvalue, + exp_type & ty); +}; + +#endif // DWFLPP_H + +/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ -- cgit From aa214f4bf19e711e01998a07b390934c1b027f74 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 15 May 2009 12:29:19 -0700 Subject: Remove unused dwflpp methods These three methods had no callers, and are thus obsolete: dwflpp::focus_on_module_containing_global_address(Dwarf_Addr a) dwflpp::global_address_to_module(Dwarf_Addr a) dwflpp::cu_name_matches(string pattern) --- dwflpp.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 23015fdc..85817391 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -196,13 +196,11 @@ struct dwflpp void focus_on_module(Dwfl_Module * m, module_info * mi); void focus_on_cu(Dwarf_Die * c); void focus_on_function(Dwarf_Die * f); - void focus_on_module_containing_global_address(Dwarf_Addr a); void query_cu_containing_global_address(Dwarf_Addr a, void *arg); void query_cu_containing_module_address(Dwarf_Addr a, void *arg); Dwarf_Addr module_address_to_global(Dwarf_Addr a); - Dwarf_Addr global_address_to_module(Dwarf_Addr a); bool module_name_matches(std::string pattern); bool name_has_wildcard(std::string pattern); @@ -212,8 +210,6 @@ struct dwflpp bool function_name_matches(std::string pattern); bool function_name_final_match(std::string pattern); - bool cu_name_matches(std::string pattern); - void setup_kernel(bool debuginfo_needed = true); void setup_user(const std::string& module_name, bool debuginfo_needed = true); -- cgit From b6fa229bc4b361a23f23daa13af634a0515230d6 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 15 May 2009 13:14:52 -0700 Subject: Merge the dwflpp::query_cu_..._address methods The method query_cu_containing_global_address was only called by query_cu_containing_module_address, and the latter was just doing a simple argument transform. They are now merged into a single method, query_cu_containing_address. The function module_address_to_global is also merged here at its only call site. --- dwflpp.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 85817391..5ae00131 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -197,10 +197,7 @@ struct dwflpp void focus_on_cu(Dwarf_Die * c); void focus_on_function(Dwarf_Die * f); - void query_cu_containing_global_address(Dwarf_Addr a, void *arg); - void query_cu_containing_module_address(Dwarf_Addr a, void *arg); - - Dwarf_Addr module_address_to_global(Dwarf_Addr a); + void query_cu_containing_address(Dwarf_Addr a, void *arg); bool module_name_matches(std::string pattern); bool name_has_wildcard(std::string pattern); -- cgit From 511785011b1bd7092d9e093f6e954c131d83a3a0 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 15 May 2009 14:10:57 -0700 Subject: Break the dwflpp dependence on query_module --- dwflpp.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 5ae00131..3cd2a444 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -63,8 +63,6 @@ typedef std::vector inline_instance_map_t; /* XXX FIXME functions that dwflpp needs from tapsets.cxx */ int query_cu (Dwarf_Die * cudie, void * arg); -int query_module (Dwfl_Module *mod, void **, const char *name, - Dwarf_Addr addr, void *arg); func_info_map_t *get_filtered_functions(dwarf_query *q); inline_instance_map_t *get_filtered_inlines(dwarf_query *q); void add_label_name(dwarf_query *q, const char *name); @@ -214,7 +212,6 @@ struct dwflpp const char *, Dwarf_Addr, void *), base_query *data); - void query_modules(base_query *q); typedef std::map*> module_cu_cache_t; module_cu_cache_t module_cu_cache; -- cgit From 1adf8ef1ca448709a7a4527b916d65ada0b3fc04 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 15 May 2009 14:26:32 -0700 Subject: Break the dwflpp dependence on query_cu --- dwflpp.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 3cd2a444..649d241b 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -62,7 +62,6 @@ typedef std::vector inline_instance_map_t; /* XXX FIXME functions that dwflpp needs from tapsets.cxx */ -int query_cu (Dwarf_Die * cudie, void * arg); func_info_map_t *get_filtered_functions(dwarf_query *q); inline_instance_map_t *get_filtered_inlines(dwarf_query *q); void add_label_name(dwarf_query *q, const char *name); @@ -195,7 +194,7 @@ struct dwflpp void focus_on_cu(Dwarf_Die * c); void focus_on_function(Dwarf_Die * f); - void query_cu_containing_address(Dwarf_Addr a, void *arg); + Dwarf_Die *query_cu_containing_address(Dwarf_Addr a); bool module_name_matches(std::string pattern); bool name_has_wildcard(std::string pattern); -- cgit From 0d3ea790a5ee17df1600ccb377fbeeb9f5574642 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 15 May 2009 15:22:05 -0700 Subject: Simplify our unordered_map typedefs --- dwflpp.h | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 649d241b..970855f8 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -23,12 +23,6 @@ #include #include -#ifdef HAVE_TR1_UNORDERED_MAP -#include -#else -#include -#endif - extern "C" { #include } @@ -44,18 +38,20 @@ enum line_t { ABSOLUTE, RELATIVE, RANGE, WILDCARD }; enum info_status { info_unknown, info_present, info_absent }; #ifdef HAVE_TR1_UNORDERED_MAP -typedef std::tr1::unordered_map cu_function_cache_t; -typedef std::tr1::unordered_map mod_cu_function_cache_t; // module:cu -> function -> die +#include +template struct stap_map { + typedef std::tr1::unordered_map type; +}; #else -struct stringhash { - // __gnu_cxx:: is needed because our own hash.h has an ambiguous hash<> decl too. +#include +template struct stap_map { + typedef __gnu_cxx::hash_map type; size_t operator() (const std::string& s) const { __gnu_cxx::hash h; return h(s.c_str()); } }; - -typedef __gnu_cxx::hash_map cu_function_cache_t; -typedef __gnu_cxx::hash_map mod_cu_function_cache_t; // module:cu -> function -> die #endif +typedef stap_map::type cu_function_cache_t; // function -> die +typedef stap_map::type mod_cu_function_cache_t; // module:cu -> function -> die typedef std::vector func_info_map_t; typedef std::vector inline_instance_map_t; -- cgit From d0b4a5ffde2a86bc672097a4d5462b204364e59f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 15 May 2009 15:23:42 -0700 Subject: Privatize many dwflpp members This helps make it more obvious which methods are accessed by external classes, which should help in refactoring. --- dwflpp.h | 112 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 56 insertions(+), 56 deletions(-) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 970855f8..042b37a9 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -160,11 +160,9 @@ struct inline_instance_info struct dwflpp { systemtap_session & sess; - Dwfl * dwfl; // These are "current" values we focus on. Dwfl_Module * module; - Dwarf * module_dwarf; Dwarf_Addr module_bias; module_info * mod_info; @@ -173,7 +171,6 @@ struct dwflpp Dwarf_Addr module_end; Dwarf_Die * cu; - Dwarf_Die * function; std::string module_name; std::string cu_name; @@ -182,8 +179,6 @@ struct dwflpp dwflpp(systemtap_session & session, const std::string& user_module=""); ~dwflpp(); - std::string const default_name(char const * in, char const *); - void get_module_dwarf(bool required = false, bool report = true); void focus_on_module(Dwfl_Module * m, module_info * mi); @@ -200,54 +195,26 @@ struct dwflpp bool function_name_matches(std::string pattern); bool function_name_final_match(std::string pattern); - void setup_kernel(bool debuginfo_needed = true); - void setup_user(const std::string& module_name, bool debuginfo_needed = true); - void iterate_over_modules(int (* callback)(Dwfl_Module *, void **, const char *, Dwarf_Addr, void *), base_query *data); - typedef std::map*> module_cu_cache_t; - module_cu_cache_t module_cu_cache; - void iterate_over_cus (int (*callback)(Dwarf_Die * die, void * arg), void * data); bool func_is_inline(); - typedef std::map*> cu_inl_function_cache_t; - cu_inl_function_cache_t cu_inl_function_cache; - - static int cu_inl_function_caching_callback (Dwarf_Die* func, void *arg); - void iterate_over_inline_instances (int (* callback)(Dwarf_Die * die, void * arg), void * data); - /* The global alias cache is used to resolve any DIE found in a - * module that is stubbed out with DW_AT_declaration with a defining - * DIE found in a different module. The current assumption is that - * this only applies to structures and unions, which have a global - * namespace (it deliberately only traverses program scope), so this - * cache is indexed by name. If other declaration lookups were - * added to it, it would have to be indexed by name and tag - */ - mod_cu_function_cache_t global_alias_cache; - static int global_alias_caching_callback(Dwarf_Die *die, void *arg); - Dwarf_Die *declaration_resolve(const char *name); mod_cu_function_cache_t cu_function_cache; - static int cu_function_caching_callback (Dwarf_Die* func, void *arg); - int iterate_over_functions (int (* callback)(Dwarf_Die * func, base_query * q), base_query * q, const std::string& function, bool has_statement_num=false); - int iterate_over_globals (int (* callback)(Dwarf_Die *, void *), - void * data); - - bool has_single_line_record (dwarf_query * q, char const * srcfile, int lineno); void iterate_over_srcfile_lines (char const * srcfile, int lines[2], @@ -282,16 +249,71 @@ struct dwflpp bool die_has_pc (Dwarf_Die & die, Dwarf_Addr pc); + std::string literal_stmt_for_local (Dwarf_Die *scope_die, + Dwarf_Addr pc, + std::string const & local, + const target_symbol *e, + bool lvalue, + exp_type & ty); + + + std::string literal_stmt_for_return (Dwarf_Die *scope_die, + Dwarf_Addr pc, + const target_symbol *e, + bool lvalue, + exp_type & ty); + + std::string literal_stmt_for_pointer (Dwarf_Die *type_die, + const target_symbol *e, + bool lvalue, + exp_type & ty); + +private: + Dwfl * dwfl; + + // These are "current" values we focus on. + Dwarf * module_dwarf; + Dwarf_Die * function; + + std::string const default_name(char const * in, char const *); + + void setup_kernel(bool debuginfo_needed = true); + void setup_user(const std::string& module_name, bool debuginfo_needed = true); + + typedef std::map*> module_cu_cache_t; + module_cu_cache_t module_cu_cache; + + typedef std::map*> cu_inl_function_cache_t; + cu_inl_function_cache_t cu_inl_function_cache; + static int cu_inl_function_caching_callback (Dwarf_Die* func, void *arg); + + /* The global alias cache is used to resolve any DIE found in a + * module that is stubbed out with DW_AT_declaration with a defining + * DIE found in a different module. The current assumption is that + * this only applies to structures and unions, which have a global + * namespace (it deliberately only traverses program scope), so this + * cache is indexed by name. If other declaration lookups were + * added to it, it would have to be indexed by name and tag + */ + mod_cu_function_cache_t global_alias_cache; + static int global_alias_caching_callback(Dwarf_Die *die, void *arg); + int iterate_over_globals (int (* callback)(Dwarf_Die *, void *), + void * data); + + static int cu_function_caching_callback (Dwarf_Die* func, void *arg); + + bool has_single_line_record (dwarf_query * q, char const * srcfile, int lineno); + static void loc2c_error (void *, const char *fmt, ...); // This function generates code used for addressing computations of // target variables. void emit_address (struct obstack *pool, Dwarf_Addr address); - static void loc2c_emit_address (void *arg, struct obstack *pool, Dwarf_Addr address); void print_locals(Dwarf_Die *die, std::ostream &o); + void print_members(Dwarf_Die *vardie, std::ostream &o); Dwarf_Attribute *find_variable_and_frame_base (Dwarf_Die *scope_die, Dwarf_Addr pc, @@ -300,7 +322,6 @@ struct dwflpp Dwarf_Die *vardie, Dwarf_Attribute *fb_attr_mem); - struct location *translate_location(struct obstack *pool, Dwarf_Attribute *attr, Dwarf_Addr pc, @@ -308,8 +329,6 @@ struct dwflpp struct location **tail, const target_symbol *e); - void print_members(Dwarf_Die *vardie, std::ostream &o); - bool find_struct_member(const std::string& member, Dwarf_Die *parentdie, const target_symbol *e, @@ -342,25 +361,6 @@ struct dwflpp std::string express_as_string (std::string prelude, std::string postlude, struct location *head); - - std::string literal_stmt_for_local (Dwarf_Die *scope_die, - Dwarf_Addr pc, - std::string const & local, - const target_symbol *e, - bool lvalue, - exp_type & ty); - - - std::string literal_stmt_for_return (Dwarf_Die *scope_die, - Dwarf_Addr pc, - const target_symbol *e, - bool lvalue, - exp_type & ty); - - std::string literal_stmt_for_pointer (Dwarf_Die *type_die, - const target_symbol *e, - bool lvalue, - exp_type & ty); }; #endif // DWFLPP_H -- cgit From 276465828851648edc5b56f762a0d100051c9e32 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 1 Jun 2009 18:47:30 -0700 Subject: Move the blacklist functions into dwflpp For a call like "stap -l 'syscall.*'", I found that ~10% of the time was spent compiling the blacklist regexps over again for each probe point. By moving this functionality into the kernel dwflpp instance, we can reuse the regexps and get an easy speed boost. --- dwflpp.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 042b37a9..554e02d4 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -25,6 +25,7 @@ extern "C" { #include +#include } @@ -268,6 +269,19 @@ struct dwflpp bool lvalue, exp_type & ty); + bool blacklisted_p(const std::string& funcname, + const std::string& filename, + int line, + const std::string& module, + const std::string& section, + Dwarf_Addr addr, + bool has_return); + + Dwarf_Addr relocate_address(Dwarf_Addr addr, + std::string& reloc_section, + std::string& blacklist_section); + + private: Dwfl * dwfl; @@ -361,6 +375,13 @@ private: std::string express_as_string (std::string prelude, std::string postlude, struct location *head); + + regex_t blacklist_func; // function/statement probes + regex_t blacklist_func_ret; // only for .return probes + regex_t blacklist_file; // file name + bool blacklist_enabled; + void build_blacklist(); + std::string get_blacklist_section(Dwarf_Addr addr); }; #endif // DWFLPP_H -- cgit From c8ad068755e7424e767660f2c27cb3b1e2d5343d Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 2 Jun 2009 00:43:49 -0700 Subject: Cache the last result of dwarf_getscopes This one function accounted for ~30% of my callgrind profile of "stap -l 'syscall.*'", even though it was only called ~1200 times. We call dwarf_getscopes for each $target variable, with the same parameters within a given probe. Since they're no nicely grouped, it's easy to just cache the most recent call, and the next few calls will be a hit. Overall this cuts the number of calls down to about 300, for an easy speed gain. --- dwflpp.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 554e02d4..314e7583 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -382,6 +382,11 @@ private: bool blacklist_enabled; void build_blacklist(); std::string get_blacklist_section(Dwarf_Addr addr); + + Dwarf_Addr pc_cached_scopes; + int num_cached_scopes; + Dwarf_Die *cached_scopes; + int dwarf_getscopes_cached (Dwarf_Addr pc, Dwarf_Die **scopes); }; #endif // DWFLPP_H -- cgit From f517ee24c58413f7de89ede71c728579c12ace5b Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 8 Jun 2009 16:37:00 -0700 Subject: Remove dwflpp::default_name It was just a basic NULL check, but creating its string temporaries was causing a fair slowdown. Removing this function and adjusting the callers shaves ~5% off the syscall.* elaboration time. --- dwflpp.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'dwflpp.h') diff --git a/dwflpp.h b/dwflpp.h index 314e7583..9cd2cb59 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -289,8 +289,6 @@ private: Dwarf * module_dwarf; Dwarf_Die * function; - std::string const default_name(char const * in, char const *); - void setup_kernel(bool debuginfo_needed = true); void setup_user(const std::string& module_name, bool debuginfo_needed = true); -- cgit