![]() |
User Manual, Developers Guide and API Documentation |
![]() |
#include <Backtrace.hpp>


Public Types | |
| typedef std::vector< FunctionCall > | FunctionCalls |
Public Member Functions | |
| Backtrace () | |
| Creates an empty object, use snapshot(), to get a snapshot of the stack. | |
| void | clear () |
| Discard snapshot. | |
| FunctionCalls | getFunctionCalls () const |
| Returns a list with function calls. | |
| void | snapshot () |
| Make a snapshot of the stack, discarding any old snapshot. | |
| virtual | ~Backtrace () |
| Destructor. | |
Private Types | |
| typedef std::list< std::string > | Lines |
Private Member Functions | |
| virtual std::string | doToString () const |
| Retuns a human readable String with demangled symbols. | |
Private Attributes | |
| Lines | backtrace_ |
| Holds the backtrace. | |
Classes | |
| class | FunctionCall |
| Keeps the information an element of the backtrace (for one function call). More... | |
Backtrace backtrace;
// make a snapshot of the current stack
backtrace.snapshot();
// backtrace can be used in streams
std::stringstream tmpStream;
tmpStream << backtrace;
// retrive a vector with all function calls
Backtrace::FunctionCalls functionCalls = backtrace.getFunctionCalls();
#ifdef __GLIBC__
// this works only with glibc
// at least this function and the snapshot function must be on the stack
ASSERT(functionCalls.size() >= static_cast<size_t>(2));
// copy the first element
Backtrace::FunctionCall functionCall = functionCalls.at(0);
// the elements in the vector (Backtrace::FunctionCall) provide the
// following methods
std::string tmpString = "";
tmpString = functionCall.getOrigin();
tmpString = functionCall.getOffset();
tmpString = functionCall.getReturnAddress();
// most interesting is probably the method getName() which returns
// the name of the function at the respective position on the stack
ASSERT_MESSAGE( functionCall.getName(), functionCall.getName() == "wns::Backtrace::snapshot()");
ASSERT_MESSAGE( functionCall.getOrigin(), functionCall.getOrigin() != "unknown");
ASSERT_MESSAGE( functionCall.getOffset(), functionCall.getOffset() != "unknown");
ASSERT_MESSAGE( functionCall.getReturnAddress(), functionCall.getReturnAddress() != "unknown");
#else
// no backtrace available
ASSERT(functionCalls.size() == static_cast<size_t>(0));
#endif // __GLIBC__
Definition at line 44 of file Backtrace.hpp.
| typedef std::vector<FunctionCall> wns::Backtrace::FunctionCalls |
Definition at line 99 of file Backtrace.hpp.
typedef std::list<std::string> wns::Backtrace::Lines [private] |
Definition at line 47 of file Backtrace.hpp.
| Backtrace::Backtrace | ( | ) |
Definition at line 45 of file Backtrace.cpp.
| Backtrace::~Backtrace | ( | ) | [virtual] |
Definition at line 50 of file Backtrace.cpp.
| void Backtrace::clear | ( | ) |
Definition at line 78 of file Backtrace.cpp.
| std::string Backtrace::doToString | ( | ) | const [private, virtual] |
Implements wns::IOutputStreamable.
Definition at line 99 of file Backtrace.cpp.
| wns::Backtrace::FunctionCalls Backtrace::getFunctionCalls | ( | ) | const |
Definition at line 84 of file Backtrace.cpp.
| void Backtrace::snapshot | ( | ) |
Definition at line 56 of file Backtrace.cpp.
Lines wns::Backtrace::backtrace_ [private] |
Definition at line 142 of file Backtrace.hpp.
1.5.5