libcsdbg  1.28
C++ exception (and generic) stack trace debug library
modsym_t csdbg::plugin::resolve ( const i8 nm,
const i8 scope = NULL 
) const
virtual

Resolve a module symbol.

Parameters
[in]nmthe symbol name
[in]scopethe full scope of the symbol (namespace and/or class)
Returns
the symbol address
Exceptions
std::bad_alloc
csdbg::exception
Note
The modsym_t type is a pointer to a function that takes two void* arguments and returns void. All module entry points should conform to this signature in order to be callable from a plugin object. If scope is NULL, the C ABI is used to resolve the symbol

Definition at line 225 of file plugin.cpp.

References csdbg::string::append(), csdbg::chain< T >::at(), csdbg::string::cstr(), csdbg::string::length(), likely, m_handle, m_path, csdbg::chain< T >::size(), csdbg::string::split(), and unlikely.

Referenced by plugin().

226 {
227  if ( unlikely(m_handle == NULL) )
228  throw exception("no selected module, this is an inline plugin");
229 
230  if ( unlikely(nm == NULL) )
231  throw exception("invalid argument: nm (=%p)", nm);
232 
233  string *mangled = NULL;
234  if ( likely(scope == NULL) )
235  mangled = new string(nm);
236 
237  /* Mangle the symbol (g++ ABI mangling, Itanium IA64 compatible) */
238  else {
239  string tmp(scope);
240  chain<string> *parts = NULL;
241 
242  try {
243  mangled = new string("_ZN");
244  parts = tmp.split("::");
245 
246  for (u32 i = 0, sz = parts->size(); likely(i < sz); i++) {
247  string *token = parts->at(i);
248  mangled->append("%d%s", token->length(), token->cstr());
249  }
250 
251  mangled->append("%d%s", strlen(nm), nm);
252  mangled->append("EPvS%d_", parts->size() - 1);
253 
254  delete parts;
255  parts = NULL;
256  }
257 
258  catch (...) {
259  delete parts;
260  delete mangled;
261  throw;
262  }
263  }
264 
265  /* Resolve the symbol address */
266  dlerror();
267  void *sym = dlsym(m_handle, mangled->cstr());
268  modsym_t retval = reinterpret_cast<modsym_t> (sym);
269 
270  i8 *err = dlerror();
271  if ( unlikely(err != NULL) ) {
272  exception x(
273  "failed to resolve symbol %s in object '%s' (%s)",
274  mangled->cstr(),
275  m_path,
276  err
277  );
278 
279  delete mangled;
280  throw x;
281  }
282 
283  delete mangled;
284  return retval;
285 }
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
i8 * m_path
Module file path.
Definition: plugin.hpp:52
void(* modsym_t)(void *, void *)
Plugin callback.
Definition: config.hpp:152
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: