User Manual, Developers Guide and API Documentation

wns::Backtrace Class Reference

Makes a snapshot of the current stack. More...

#include <Backtrace.hpp>

Inheritance diagram for wns::Backtrace:

Inheritance graph
[legend]
Collaboration diagram for wns::Backtrace:

Collaboration graph
[legend]

List of all members.

Public Types

typedef std::vector< FunctionCallFunctionCalls

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...


Detailed Description

Author:
Marc Schinnenburg <marc@schinnenburg.com>
Usage:
            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.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

Backtrace::Backtrace (  ) 

Definition at line 45 of file Backtrace.cpp.

Backtrace::~Backtrace (  )  [virtual]

Definition at line 50 of file Backtrace.cpp.


Member Function Documentation

void Backtrace::clear (  ) 

Definition at line 78 of file Backtrace.cpp.

std::string Backtrace::doToString (  )  const [private, virtual]

Note:
This is part of an NVI. Call toString() if you want this

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.


Member Data Documentation

Definition at line 142 of file Backtrace.hpp.


The documentation for this class was generated from the following files:

Generated on Sat May 26 03:32:50 2012 for openWNS by  doxygen 1.5.5