From 7d007451c5a8de2fc3f691dfc58f3d004320e7d2 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Tue, 18 Feb 2014 14:31:20 -0500 Subject: [PATCH] template-ify iterate_over_functions() and iterate_single_function() --- dwflpp.cxx | 23 +++++++++++------------ dwflpp.h | 28 +++++++++++++++++++++++----- tapsets.cxx | 8 +++----- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/dwflpp.cxx b/dwflpp.cxx index e742a3c4c..0acc834a2 100644 --- a/dwflpp.cxx +++ b/dwflpp.cxx @@ -956,9 +956,9 @@ dwflpp::mod_function_caching_callback (Dwarf_Die* cu, cu_function_cache_t *v) } -int -dwflpp::iterate_over_functions (int (* callback)(Dwarf_Die *, void *), - void * arg, const string& function) +template<> int +dwflpp::iterate_over_functions(int (*callback)(Dwarf_Die*, void*), + void *data, const string& function) { int rc = DWARF_CB_OK; assert (module); @@ -988,7 +988,7 @@ dwflpp::iterate_over_functions (int (* callback)(Dwarf_Die *, void *), if (sess.verbose > 4) clog << _F("function cache %s:%s hit %s", module_name.c_str(), cu_name().c_str(), function.c_str()) << endl; - rc = (*callback)(& die, arg); + rc = (*callback)(& die, data); if (rc != DWARF_CB_OK) break; } } @@ -1011,7 +1011,7 @@ dwflpp::iterate_over_functions (int (* callback)(Dwarf_Die *, void *), clog << _F("function cache %s:%s match %s vs %s", module_name.c_str(), cu_name().c_str(), linkage_name, function.c_str()) << endl; - rc = (*callback)(& die, arg); + rc = (*callback)(& die, data); if (rc != DWARF_CB_OK) break; } } @@ -1029,7 +1029,7 @@ dwflpp::iterate_over_functions (int (* callback)(Dwarf_Die *, void *), clog << _F("function cache %s:%s match %s vs %s", module_name.c_str(), cu_name().c_str(), func_name.c_str(), function.c_str()) << endl; - rc = (*callback)(& die, arg); + rc = (*callback)(& die, data); if (rc != DWARF_CB_OK) break; } } @@ -1042,9 +1042,9 @@ dwflpp::iterate_over_functions (int (* callback)(Dwarf_Die *, void *), } -int -dwflpp::iterate_single_function (int (* callback)(Dwarf_Die * func, void * arg), - void * arg, const string& function) +template<> int +dwflpp::iterate_single_function(int (*callback)(Dwarf_Die*, void*), + void *data, const string& function) { int rc = DWARF_CB_OK; assert (module); @@ -1080,7 +1080,7 @@ dwflpp::iterate_single_function (int (* callback)(Dwarf_Die * func, void * arg), // since we're iterating out of cu-context, we need each focus focus_on_cu(dwarf_diecu(&die, &cu_mem, NULL, NULL)); - rc = (*callback)(& die, arg); + rc = (*callback)(& die, data); if (rc != DWARF_CB_OK) break; } } @@ -1814,9 +1814,8 @@ dwflpp::external_function_cu_callback (Dwarf_Die* cu, external_function_query *e } int -dwflpp::external_function_func_callback (Dwarf_Die* func, void * arg) +dwflpp::external_function_func_callback (Dwarf_Die* func, external_function_query *efq) { - external_function_query * efq = static_cast(arg); Dwarf_Attribute external; Dwarf_Addr func_addr; if (dwarf_attr_integrate(func, DW_AT_external, &external) != NULL && diff --git a/dwflpp.h b/dwflpp.h index ce6d9d5b8..8301b756c 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -259,11 +259,23 @@ struct dwflpp Dwarf_Die *declaration_resolve(const std::string& name); Dwarf_Die *declaration_resolve_other_cus(const std::string& name); - int iterate_over_functions (int (* callback)(Dwarf_Die *, void *), - void * arg, const std::string& function); + template + int iterate_over_functions (int (* callback)(Dwarf_Die*, T*), + T *data, const std::string& function) + { + // See comment block in iterate_over_modules() + return iterate_over_functions((int (*)(Dwarf_Die*, void*))callback, + (void*)data, function); + } - int iterate_single_function (int (* callback)(Dwarf_Die * func, void * arg), - void * arg, const std::string& function); + template + int iterate_single_function (int (* callback)(Dwarf_Die*, T*), + T *data, const std::string& function) + { + // See comment block in iterate_over_modules() + return iterate_single_function((int (*)(Dwarf_Die*, void*))callback, + (void*)data, function); + } void iterate_over_srcfile_lines (char const * srcfile, int lines[2], @@ -425,7 +437,7 @@ private: static int mod_function_caching_callback (Dwarf_Die* func, cu_function_cache_t *v); static int cu_function_caching_callback (Dwarf_Die* func, cu_function_cache_t *v); static int external_function_cu_callback (Dwarf_Die* cu, external_function_query *efq); - static int external_function_func_callback (Dwarf_Die* func, void *arg); + static int external_function_func_callback (Dwarf_Die* func, external_function_query *efq); bool has_single_line_record (dwarf_query * q, char const * srcfile, int lineno); @@ -525,6 +537,12 @@ dwflpp::iterate_over_cus(int (*callback)(Dwarf_Die*, void*), template<> void dwflpp::iterate_over_inline_instances(int (*callback)(Dwarf_Die*, void*), void *data); +template<> int +dwflpp::iterate_over_functions(int (*callback)(Dwarf_Die*, void*), + void *data, const std::string& function); +template<> int +dwflpp::iterate_single_function(int (*callback)(Dwarf_Die*, void*), + void *data, const std::string& function); #endif // DWFLPP_H diff --git a/tapsets.cxx b/tapsets.cxx index dc2f3ac2a..37a48760d 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -1780,9 +1780,8 @@ query_dwarf_inline_instance (Dwarf_Die * die, dwarf_query * q) } static int -query_dwarf_func (Dwarf_Die * func, void * arg) +query_dwarf_func (Dwarf_Die * func, dwarf_query * q) { - dwarf_query * q = static_cast(arg); assert (q->has_statement_str || q->has_function_str); // weed out functions whose decl_file isn't one of @@ -10373,7 +10372,7 @@ struct tracepoint_query : public base_query void query_plt (const char *entry, size_t addr) {} static int tracepoint_query_cu (Dwarf_Die * cudie, tracepoint_query * q); - static int tracepoint_query_func (Dwarf_Die * func, void * arg); + static int tracepoint_query_func (Dwarf_Die * func, tracepoint_query * q); }; @@ -10427,9 +10426,8 @@ tracepoint_query::tracepoint_query_cu (Dwarf_Die * cudie, tracepoint_query * q) int -tracepoint_query::tracepoint_query_func (Dwarf_Die * func, void * arg) +tracepoint_query::tracepoint_query_func (Dwarf_Die * func, tracepoint_query * q) { - tracepoint_query * q = static_cast(arg); if (pending_interrupts) return DWARF_CB_ABORT; return q->handle_query_func(func); } -- 2.43.5