libcsdbg  1.28
C++ exception (and generic) stack trace debug library
void csdbg::__cyg_profile_func_enter ( void *  this_fn,
void *  call_site 
)

In code compiled with -finstrument-functions, g++ injects code to call this function at the beginning of instrumented functions. By implementing this function (and __cyg_profile_func_exit), libcsdbg simulates the call stack of each thread.

Parameters
[in]this_fnthe address of the called function
[in]call_sitethe address where the function was called
Note
If an exception occurs, the process exits

Definition at line 36 of file tracer.cpp.

References __D_ASSERT, csdbg::filter::apply(), csdbg::plugin::begin(), csdbg::thread::called(), csdbg::process::current_thread(), csdbg::tracer::filter_count(), csdbg::tracer::get_filter(), csdbg::tracer::get_plugin(), csdbg::util::header(), csdbg::process::ilookup(), csdbg::tracer::interface(), likely, csdbg::util::lock(), csdbg::process::lookup(), csdbg::filter::mode(), csdbg::tracer::plugin_count(), csdbg::tracer::proc(), unlikely, and csdbg::util::unlock().

37 {
38  __D_ASSERT(this_fn != NULL);
39  __D_ASSERT(call_site != NULL);
40 
41  util::lock();
42  tracer *iface = tracer::interface();
43 
44  __D_ASSERT(iface != NULL);
45  if ( unlikely(iface == NULL) ) {
46  util::unlock();
47  return;
48  }
49 
50 #ifdef CSDBG_WITH_PLUGIN
51  /* Call all plugin enter functions in the order they were registered */
52  for (u32 i = 0, sz = iface->plugin_count(); likely(i < sz); i++)
53  try {
54  iface->get_plugin(i)->begin(this_fn, call_site);
55  }
56 
57  catch (exception &x) {
58  std::cerr << x;
59  }
60 
61  catch (std::exception &x) {
62  std::cerr << x;
63  }
64 
65  catch (...) {
66  util::header(std::cerr, "x");
67  std::cerr << "plugin " << std::dec << i << ": unidentified exception\r\n";
68  }
69 #endif
70 
71  try {
72  mem_addr_t addr = reinterpret_cast<mem_addr_t> (this_fn);
73  mem_addr_t site = reinterpret_cast<mem_addr_t> (call_site);
74  process *proc = iface->proc();
75 
76 #ifdef CSDBG_WITH_FILTER
77  mem_addr_t base = 0;
78  const i8 *path = proc->ilookup(addr, base);
79 
80  /* Call all the module filters in the order they were registered */
81  if ( likely(path != NULL) )
82  for (u32 i = 0, sz = iface->filter_count(); likely(i < sz); i++) {
83  filter *filt = iface->get_filter(i);
84  if ( likely(filt->mode()) )
85  continue;
86 
87  if ( unlikely(filt->apply(path)) ) {
88  util::unlock();
89  return;
90  }
91  }
92 #endif
93 
94  /*
95  * Lookup the process namespace to resolve the called function symbol. If it
96  * gets resolved update the simulated call stack of the current thread
97  */
98  const i8 *nm = proc->lookup(addr);
99  if ( likely(nm != NULL) ) {
100 #ifdef CSDBG_WITH_FILTER
101  /* Call all the symbol filters in the order they were registered */
102  for (u32 i = 0, sz = iface->filter_count(); likely(i < sz); i++) {
103  filter *filt = iface->get_filter(i);
104  if ( likely(!filt->mode()) )
105  continue;
106 
107  if ( unlikely(filt->apply(nm)) ) {
108  util::unlock();
109  return;
110  }
111  }
112 #endif
113 
114  proc->current_thread()->called(addr, site, nm);
115  }
116 
117  util::unlock();
118  return;
119  }
120 
121  catch (exception &x) {
122  std::cerr << x;
123  }
124 
125  catch (std::exception &x) {
126  std::cerr << x;
127  }
128 
129  util::unlock();
130  exit(EXIT_FAILURE);
131 }
char i8
8-bit signed integer
Definition: config.hpp:72
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
unsigned long long mem_addr_t
64-bit memory address
Definition: config.hpp:120
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349
#define __D_ASSERT(x)
Assertion macro.
Definition: config.hpp:268

+ Here is the call graph for this function: