libcsdbg  1.28
C++ exception (and generic) stack trace debug library
tracer & csdbg::tracer::trace ( string dst)
virtual

Create an exception stack trace using the simulated call stack of the current thread. The trace is appended to a string and the simulated stack is unwinded.

Parameters
[in]dstthe destination string
Returns
*this
Exceptions
std::bad_alloc
csdbg::exception
Attention
The simulated call stack is unwinded even if the method fails, in any way to produce a trace

Definition at line 658 of file tracer.cpp.

References csdbg::symbol::addr(), addr2line(), csdbg::string::append(), csdbg::thread::backtrace(), csdbg::process::current_thread(), csdbg::thread::handle(), csdbg::process::ilookup(), csdbg::thread::lag(), likely, csdbg::util::lock(), m_proc, csdbg::symbol::name(), csdbg::thread::name(), csdbg::call::site(), csdbg::util::unlock(), csdbg::thread::unwind(), and unwind().

Referenced by dump(), and csdbg::operator<<().

659 {
660  /* If an exception occurs, unwind, unlock and rethrow it */
661  try {
662  util::lock();
663  thread *thr = m_proc->current_thread();
664 
665  const i8 *nm = thr->name();
666  if ( likely(nm == NULL) )
667  nm = "anonymous";
668  dst.append("at %s thread (0x%lx) {\r\n", nm, thr->handle());
669 
670  /* For each function call */
671  for (i32 i = thr->lag(); likely(i >= 0); i--) {
672  const call *cur = thr->backtrace(i);
673  dst.append(" at %s", cur->name());
674 
675  /* Append addr2line debug information */
676  u32 prev = i + 1;
677  if ( likely (prev < thr->call_depth()) ) {
678  const call *caller = thr->backtrace(prev);
679  mem_addr_t base = 0;
680 
681  const i8 *path = m_proc->ilookup(caller->addr(), base);
682  addr2line(dst, path, cur->site() - base);
683  }
684 
685  dst.append("\r\n");
686  }
687 
688  dst.append("}\r\n");
689  thr->unwind();
690  util::unlock();
691  return *this;
692  }
693 
694  catch (...) {
695  unwind();
696  util::unlock();
697  throw;
698  }
699 }
virtual string & append(const string &)
Append a string.
Definition: string.cpp:404
char i8
8-bit signed integer
Definition: config.hpp:72
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 lock()
Lock the global access mutex.
Definition: util.cpp:397
static void unlock()
Unlock the global access mutex.
Definition: util.cpp:406
virtual tracer & unwind()
Unwind the simulated call stack of the current thread.
Definition: tracer.cpp:778
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
static string & addr2line(string &, const i8 *, mem_addr_t)
Given an address in an objective code file, extract from the gdb-related debug information, the equivalent source code file name and line and append it to a string buffer.
Definition: tracer.cpp:398
int i32
32-bit signed integer
Definition: config.hpp:82
virtual const i8 * ilookup(mem_addr_t, mem_addr_t &) const
Inverse lookup. Find the module (executable or DSO library) that defines a symbol and return its path...
Definition: process.cpp:300
unsigned long long mem_addr_t
64-bit memory address
Definition: config.hpp:120
virtual thread * current_thread()
Get the currently executing thread.
Definition: process.cpp:339

+ Here is the call graph for this function:

+ Here is the caller graph for this function: