libcsdbg  1.28
C++ exception (and generic) stack trace debug library
csdbg::plugin::plugin ( const i8 path,
const i8 scope = NULL 
)
explicit

Object constructor.

Parameters
[in]paththe path of the module file
[in]scopethe full scope of the callbacks (namespace and/or class)
Exceptions
std::bad_alloc
csdbg::exception
Note
If scope is NULL, the C ABI is used to resolve the symbols

Definition at line 44 of file plugin.cpp.

References csdbg::util::dbg_info(), likely, m_begin, m_end, m_handle, m_path, resolve(), and unlikely.

Referenced by clone().

45  :
46 m_begin(NULL),
47 m_end(NULL),
48 m_path(NULL),
49 m_handle(NULL)
50 {
51  if ( unlikely(path == NULL) )
52  throw exception("invalid argument: path (=%p)", path);
53 
54  m_path = new i8[strlen(path) + 1];
55  strcpy(m_path, path);
56 
57  /* Check if the module is already loaded */
58  u32 flags = RTLD_LOCAL | RTLD_LAZY;
59  m_handle = dlopen(m_path, flags | RTLD_NOLOAD);
60 
61  /* If the module is not yet loaded, load it explicitly */
62  if ( likely(m_handle == NULL) ) {
63  dlerror();
64  m_handle = dlopen(m_path, flags);
65  if ( unlikely(m_handle == NULL) )
66  throw exception("failed to load plugin '%s' (%s)", m_path, dlerror());
67 
68  util::dbg_info("plugin '%s' loaded/linked", m_path);
69  }
70 #if CSDBG_DBG_LEVEL & CSDBG_DBGL_INFO
71  else
72  util::dbg_info("plugin '%s' linked", m_path);
73 #endif
74 
75  /* Resolve the instrumentation functions */
76  m_begin = resolve("mod_enter", scope);
77  m_end = resolve("mod_exit", scope);
78 }
79 
80 catch (...) {
81  destroy();
82 }
modsym_t m_end
Instrumentation ending callback.
Definition: plugin.hpp:50
virtual const i8 * path() const
Get the module file path.
Definition: plugin.cpp:156
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
virtual plugin & destroy()
Object deconstruction.
Definition: plugin.cpp:18
modsym_t m_begin
Instrumentation starting callback.
Definition: plugin.hpp:48
i8 * m_path
Module file path.
Definition: plugin.hpp:52
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
virtual modsym_t resolve(const i8 *, const i8 *=NULL) const
Resolve a module symbol.
Definition: plugin.cpp:225
void * m_handle
DSO handle (as provided by dlopen)
Definition: plugin.hpp:54
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349
static void dbg_info(const i8 *,...)
Print an informational debug message on the standard error stream.
Definition: util.cpp:680

+ Here is the call graph for this function:

+ Here is the caller graph for this function: