libcsdbg  1.28
C++ exception (and generic) stack trace debug library
i32 csdbg::tracer::on_dso_load ( dl_phdr_info *  dso,
size_t  sz,
void *  arg 
)
staticprotected

This is a dl_iterate_phdr (libdl) callback, called for each linked shared object. It loads the symbol table of the DSO (if it's not filtered out) to tracer::m_iface->m_proc.

Parameters
[in]dsoa dl_phdr_info struct (libdl) that describes the shared object (file path, load address e.t.c)
[in]szthe sizeof dso
[in]arga chain of POSIX extended regular expressions used to select the shared objects that will participate in the call stack simulation. The absolute path of each DSO is matched against each regexp. If NULL, all linked DSO symbol tables will be loaded. If not NULL but empty, all DSO are filtered out from instrumentation
Returns
0
Note
If an exception occurs, it's caught and handled. 0 is returned, signaling to the iterator (dl_iterate_phdr) to continue with the next DSO

Definition at line 323 of file tracer.cpp.

References csdbg::process::add_module(), csdbg::chain< T >::at(), csdbg::string::cstr(), csdbg::util::dbg_error(), csdbg::util::dbg_warn(), csdbg::string::length(), likely, m_iface, m_proc, csdbg::string::match(), csdbg::exception::msg(), csdbg::chain< T >::size(), and unlikely.

Referenced by on_lib_load().

324 {
325  try {
326  if ( unlikely(dso == NULL) )
327  throw exception("invalid argument: dso (=%p)", dso);
328 
329  /* If the DSO path is undefined */
330  string path(dso->dlpi_name);
331  if ( unlikely(path.length() == 0) )
332  throw exception("undefined DSO path");
333 
334  /* If the DSO has no segments */
335  if ( unlikely(dso->dlpi_phnum == 0) )
336  throw exception("'%s' has 0 segments", path.cstr());
337 
338  /* Check if the DSO is filtered out */
339  bool found = false;
340  if ( likely(arg != NULL) ) {
341  chain<string> *filters = static_cast<chain<string>*> (arg);
342 
343  for (u32 i = 0, sz = filters->size(); likely(i < sz); i++) {
344  string *filt = filters->at(i);
345  if ( unlikely(path.match(*filt)) ) {
346  found = true;
347  break;
348  }
349  }
350  }
351  else
352  found = true;
353 
354  if ( likely(!found) ) {
355  util::dbg_warn("filtered out '%s'", path.cstr());
356  return 0;
357  }
358 
359  /* Load the DSO symbol table */
360  mem_addr_t base = dso->dlpi_addr + dso->dlpi_phdr[0].p_vaddr;
361  m_iface->m_proc->add_module(path.cstr(), base);
362  }
363 
364  catch (exception &x) {
365  util::dbg_error("in tracer::%s(): %s", __FUNCTION__, x.msg());
366  }
367 
368  catch (std::exception &x) {
369  util::dbg_error("in tracer::%s(): %s", __FUNCTION__, x.what());
370  }
371 
372  return 0;
373 }
process * m_proc
Process handle.
Definition: tracer.hpp:45
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
static void dbg_warn(const i8 *,...)
Print a warning debug message on the standard error stream.
Definition: util.cpp:703
static void dbg_error(const i8 *,...)
Print an error debug message on the standard error stream.
Definition: util.cpp:726
virtual process & add_module(const i8 *, mem_addr_t)
Add a symbol table to the namespace. The symbol table is loaded from a non stripped objective code fi...
Definition: process.cpp:236
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
static tracer * m_iface
Interface object.
Definition: tracer.hpp:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function: