]> sourceware.org Git - systemtap.git/commitdiff
template-ify iterate_over_cus()
authorJonathan Lebon <jlebon@redhat.com>
Tue, 18 Feb 2014 17:26:37 +0000 (12:26 -0500)
committerJonathan Lebon <jlebon@redhat.com>
Wed, 19 Feb 2014 15:33:05 +0000 (10:33 -0500)
dwflpp.cxx
dwflpp.h
tapsets.cxx

index 3b6585f5d30b21696b05053d5027b696d36aec7b..a5b0ef2212c2cba6f1a1822ea56eebd799a2f55b 100644 (file)
@@ -411,9 +411,10 @@ dwflpp::iterate_over_modules<void>(int (*callback)(Dwfl_Module*,
 }
 
 
-void
-dwflpp::iterate_over_cus (int (*callback)(Dwarf_Die * die, void * arg),
-                          void * data, bool want_types)
+template<> void
+dwflpp::iterate_over_cus<void>(int (*callback)(Dwarf_Die*, void*),
+                               void *data,
+                               bool want_types)
 {
   get_module_dwarf(false);
   Dwarf *dw = module_dwarf;
@@ -865,10 +866,10 @@ dwflpp::global_alias_caching_callback(Dwarf_Die *die, bool has_inner_types,
 }
 
 int
-dwflpp::global_alias_caching_callback_cus(Dwarf_Die *die, void *arg)
+dwflpp::global_alias_caching_callback_cus(Dwarf_Die *die, dwflpp *dw)
 {
   mod_cu_type_cache_t *global_alias_cache;
-  global_alias_cache = &static_cast<dwflpp *>(arg)->global_alias_cache;
+  global_alias_cache = &dw->global_alias_cache;
 
   cu_type_cache_t *v = (*global_alias_cache)[die->addr];
   if (v != 0)
@@ -934,9 +935,8 @@ dwflpp::declaration_resolve(Dwarf_Die *type)
 
 
 int
-dwflpp::cu_function_caching_callback (Dwarf_Die* func, void *arg)
+dwflpp::cu_function_caching_callback (Dwarf_Die* func, cu_function_cache_t *v)
 {
-  cu_function_cache_t* v = static_cast<cu_function_cache_t*>(arg);
   const char *name = dwarf_diename(func);
   if (!name)
     return DWARF_CB_OK;
@@ -947,9 +947,11 @@ dwflpp::cu_function_caching_callback (Dwarf_Die* func, void *arg)
 
 
 int
-dwflpp::mod_function_caching_callback (Dwarf_Die* cu, void *arg)
+dwflpp::mod_function_caching_callback (Dwarf_Die* cu, cu_function_cache_t *v)
 {
-  dwarf_getfuncs (cu, cu_function_caching_callback, arg, 0);
+  // need to cast callback to func which accepts void*
+  dwarf_getfuncs (cu, (int (*)(Dwarf_Die*, void*))cu_function_caching_callback,
+                  v, 0);
   return DWARF_CB_OK;
 }
 
@@ -967,7 +969,9 @@ dwflpp::iterate_over_functions (int (* callback)(Dwarf_Die *, void *),
     {
       v = new cu_function_cache_t;
       cu_function_cache[cu->addr] = v;
-      dwarf_getfuncs (cu, cu_function_caching_callback, v, 0);
+      // need to cast callback to func which accepts void*
+      dwarf_getfuncs (cu, (int (*)(Dwarf_Die*, void*))cu_function_caching_callback,
+                      v, 0);
       if (sess.verbose > 4)
         clog << _F("function cache %s:%s size %zu", module_name.c_str(),
                    cu_name().c_str(), v->size()) << endl;
@@ -1802,9 +1806,8 @@ struct external_function_query {
 };
 
 int
-dwflpp::external_function_cu_callback (Dwarf_Die* cu, void *arg)
+dwflpp::external_function_cu_callback (Dwarf_Die* cu, external_function_query *efq)
 {
-  external_function_query * efq = static_cast<external_function_query *>(arg);
   efq->dw->focus_on_cu(cu);
   return efq->dw->iterate_over_functions(external_function_func_callback,
                                          efq, efq->name);
index 8e5b6685e567d348efeeb042d644a8428b563a6b..48f6b6ccd76349e30f86513489f405f23db7ae66 100644 (file)
--- a/dwflpp.h
+++ b/dwflpp.h
@@ -36,6 +36,7 @@ struct inline_instance_info;
 struct symbol_table;
 struct base_query;
 struct dwarf_query;
+struct external_function_query;
 
 enum line_t { ABSOLUTE, RELATIVE, RANGE, WILDCARD };
 enum info_status { info_unknown, info_present, info_absent };
@@ -226,8 +227,16 @@ struct dwflpp
                                   (void*)data);
     }
 
-  void iterate_over_cus (int (*callback)(Dwarf_Die * die, void * arg),
-                         void * data, bool want_types);
+  template<typename T>
+  void iterate_over_cus(int (* callback)(Dwarf_Die*, T*),
+                        T *data,
+                        bool want_types)
+    {
+      // See comment block in iterate_over_modules()
+      iterate_over_cus<void>((int (*)(Dwarf_Die*, void*))callback,
+                             (void*)data,
+                             want_types);
+    }
 
   bool func_is_inline();
 
@@ -396,8 +405,7 @@ private:
   mod_cu_type_cache_t global_alias_cache;
   static int global_alias_caching_callback(Dwarf_Die *die, bool has_inner_types,
                                            const std::string& prefix, void *arg);
-  static int global_alias_caching_callback_cus(Dwarf_Die *die, void *arg);
-
+  static int global_alias_caching_callback_cus(Dwarf_Die *die, dwflpp *dw);
 
   static int iterate_over_globals (Dwarf_Die *,
                                    int (* callback)(Dwarf_Die *, bool,
@@ -408,9 +416,9 @@ private:
                                                   const std::string&, void *),
                                  void * data);
 
-  static int mod_function_caching_callback (Dwarf_Die* func, void *arg);
-  static int cu_function_caching_callback (Dwarf_Die* func, void *arg);
-  static int external_function_cu_callback (Dwarf_Die* cu, void *arg);
+  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);
 
   bool has_single_line_record (dwarf_query * q, char const * srcfile, int lineno);
@@ -502,6 +510,10 @@ dwflpp::iterate_over_modules<void>(int (*callback)(Dwfl_Module*,
                                                    Dwarf_Addr,
                                                    void*),
                                    void *data);
+template<> void
+dwflpp::iterate_over_cus<void>(int (*callback)(Dwarf_Die*, void*),
+                               void *data,
+                               bool want_types);
 
 #endif // DWFLPP_H
 
index 80047e32904ce1b103c914762b116732b0a20c7c..4fba229ba776e473418a050d90c312ed00d28fd5 100644 (file)
@@ -406,7 +406,7 @@ static const string TOK_CLASS("class");;
 static const string TOK_CALLEE("callee");;
 static const string TOK_CALLEES("callees");;
 
-static int query_cu (Dwarf_Die * cudie, void * arg);
+static int query_cu (Dwarf_Die * cudie, dwarf_query *q);
 static void query_addr(Dwarf_Addr addr, dwarf_query *q);
 static void query_plt_statement(dwarf_query *q);
 
@@ -1848,9 +1848,8 @@ query_dwarf_func (Dwarf_Die * func, void * arg)
 }
 
 static int
-query_cu (Dwarf_Die * cudie, void * arg)
+query_cu (Dwarf_Die * cudie, dwarf_query * q)
 {
-  dwarf_query * q = static_cast<dwarf_query *>(arg);
   assert (q->has_statement_str || q->has_function_str);
 
   if (pending_interrupts) return DWARF_CB_ABORT;
@@ -4260,15 +4259,13 @@ struct dwarf_atvar_query: public base_query
   void handle_query_module ();
   void query_library (const char *) {}
   void query_plt (const char *entry, size_t addr) {}
-  static int atvar_query_cu (Dwarf_Die *cudie, void *data);
+  static int atvar_query_cu (Dwarf_Die *cudie, dwarf_atvar_query *q);
 };
 
 
 int
-dwarf_atvar_query::atvar_query_cu (Dwarf_Die * cudie, void * data)
+dwarf_atvar_query::atvar_query_cu (Dwarf_Die * cudie, dwarf_atvar_query *q)
 {
-  dwarf_atvar_query * q = static_cast<dwarf_atvar_query *>(data);
-
   if (! q->e.cu_name.empty())
     {
       const char *die_name = dwarf_diename(cudie) ?: "";
@@ -10376,7 +10373,7 @@ struct tracepoint_query : public base_query
   void query_library (const char *) {}
   void query_plt (const char *entry, size_t addr) {}
 
-  static int tracepoint_query_cu (Dwarf_Die * cudie, void * arg);
+  static int tracepoint_query_cu (Dwarf_Die * cudie, tracepoint_query * q);
   static int tracepoint_query_func (Dwarf_Die * func, void * arg);
 };
 
@@ -10423,9 +10420,8 @@ tracepoint_query::handle_query_func(Dwarf_Die * func)
 
 
 int
-tracepoint_query::tracepoint_query_cu (Dwarf_Die * cudie, void * arg)
+tracepoint_query::tracepoint_query_cu (Dwarf_Die * cudie, tracepoint_query * q)
 {
-  tracepoint_query * q = static_cast<tracepoint_query *>(arg);
   if (pending_interrupts) return DWARF_CB_ABORT;
   return q->handle_query_cu(cudie);
 }
This page took 0.05019 seconds and 5 git commands to generate.