|
|
@ -8,54 +8,6 @@ |
|
|
|
@copy © Marc Wäckerlin |
|
|
|
@copy © Marc Wäckerlin |
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a> |
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a> |
|
|
|
|
|
|
|
|
|
|
|
$Log$ |
|
|
|
|
|
|
|
Revision 1.15 2005/04/07 20:51:30 marc |
|
|
|
|
|
|
|
docu: new doxygen, new grouping |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.14 2005/03/11 23:22:58 marc |
|
|
|
|
|
|
|
It's multithreaded now, thanks to a boost mutex |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.13 2005/02/18 15:48:56 marc |
|
|
|
|
|
|
|
Dynamic loading of libbfd, no more dependency on specific libbfd version! |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.12 2005/01/28 12:13:11 marc |
|
|
|
|
|
|
|
interference between group name StackTrace and class name StackTrace |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.11 2005/01/28 12:13:11 marc |
|
|
|
|
|
|
|
interference between group name StackTrace and class name StackTrace |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.10 2004/11/25 18:30:20 marc |
|
|
|
|
|
|
|
bug fixed (put solution in the documentation) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.9 2004/10/13 10:47:15 marc |
|
|
|
|
|
|
|
no more need for ldd in StackTrace, read from /proc/self/maps |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.8 2004/10/11 16:49:32 marc |
|
|
|
|
|
|
|
Better comment for new shared library feature |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.7 2004/10/11 15:58:51 marc |
|
|
|
|
|
|
|
First version with working support for shared libraries! |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.6 2004/10/07 16:59:12 marc |
|
|
|
|
|
|
|
new method createSymtable that takes a list of arguments |
|
|
|
|
|
|
|
-> untested! |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.5 2004/10/07 09:32:45 marc |
|
|
|
|
|
|
|
correction in parameter (const&) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Revision 1.4 2004/08/28 16:21:25 marc |
|
|
|
|
|
|
|
mrw-c++-0.92 (mrw) |
|
|
|
|
|
|
|
- new file: version.cpp |
|
|
|
|
|
|
|
- new file header for all sources |
|
|
|
|
|
|
|
- work around warning in mrw::auto<T> |
|
|
|
|
|
|
|
- possibility to compile without log4cxx |
|
|
|
|
|
|
|
- work around bugs in demangle.h and libiberty.h |
|
|
|
|
|
|
|
- corrections in documentation |
|
|
|
|
|
|
|
- added simple tracing mechanism |
|
|
|
|
|
|
|
- more warnings |
|
|
|
|
|
|
|
- small corrections in Auto<>::Free and a new test for it |
|
|
|
|
|
|
|
- possibility to compile without stack trace |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#ifndef __MRW_STACKTRACE_HPP__ |
|
|
|
#ifndef __MRW_STACKTRACE_HPP__ |
|
|
|
#define __MRW_STACKTRACE_HPP__ |
|
|
|
#define __MRW_STACKTRACE_HPP__ |
|
|
@ -68,7 +20,10 @@ |
|
|
|
#include <sys/mman.h> |
|
|
|
#include <sys/mman.h> |
|
|
|
#include <bfd.h> |
|
|
|
#include <bfd.h> |
|
|
|
|
|
|
|
|
|
|
|
#ifdef _REENTRANT |
|
|
|
#if (__GNUC__==3 && __GNUC_MINOR__<4 || __GNUC__<3) && _REENTRANT && !_MT |
|
|
|
|
|
|
|
#define _MT |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef _MT |
|
|
|
#include <boost/thread/recursive_mutex.hpp> |
|
|
|
#include <boost/thread/recursive_mutex.hpp> |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
@ -117,7 +72,7 @@ namespace mrw { |
|
|
|
//@{
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief store and print a stack trace of the actual position in code
|
|
|
|
/** @brief store and print a stack trace of the actual position in code
|
|
|
|
@pre #include <mrw/stacktrace.hpp> |
|
|
|
@pre \#include <mrw/stacktrace.hpp> |
|
|
|
|
|
|
|
|
|
|
|
In the constructor, a stack trace is stored, but not yet |
|
|
|
In the constructor, a stack trace is stored, but not yet |
|
|
|
evaluated. Therefore storing a stack trace is relatively |
|
|
|
evaluated. Therefore storing a stack trace is relatively |
|
|
@ -181,6 +136,7 @@ namespace mrw { |
|
|
|
backtrace_symbols? I think rather not...? |
|
|
|
backtrace_symbols? I think rather not...? |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class StackTrace { |
|
|
|
class StackTrace { |
|
|
|
|
|
|
|
friend class StackTraceTest; |
|
|
|
public: |
|
|
|
public: |
|
|
|
//............................................................... typedefs
|
|
|
|
//............................................................... typedefs
|
|
|
|
/// container for the adresses
|
|
|
|
/// container for the adresses
|
|
|
@ -189,14 +145,14 @@ namespace mrw { |
|
|
|
typedef std::list< std::pair<std::string, void*> > BinFiles; |
|
|
|
typedef std::list< std::pair<std::string, void*> > BinFiles; |
|
|
|
/// structure to store all evaluated information
|
|
|
|
/// structure to store all evaluated information
|
|
|
|
struct CodePos { |
|
|
|
struct CodePos { |
|
|
|
CodePos(void* a, std::string fn, std::string fi, unsigned int l) |
|
|
|
CodePos(void const*const a, const std::string& fu, |
|
|
|
throw(std::bad_exception): |
|
|
|
const std::string& fi, unsigned int l): |
|
|
|
address(a), function(fn), file(fi), line(l) { |
|
|
|
address(a), function(fu), file(fi), line(l) { |
|
|
|
} |
|
|
|
} |
|
|
|
void* address; ///< the address pointer
|
|
|
|
void const*const address; ///< the address pointer
|
|
|
|
std::string function; ///< function/method name
|
|
|
|
std::string function; ///< function/method name
|
|
|
|
std::string file; ///< code file name
|
|
|
|
std::string file; ///< code file name
|
|
|
|
unsigned int line; ///< code line number
|
|
|
|
unsigned int line; ///< code line number
|
|
|
|
}; |
|
|
|
}; |
|
|
|
//................................................................ methods
|
|
|
|
//................................................................ methods
|
|
|
|
/// the constructor stores the actual stack trace
|
|
|
|
/// the constructor stores the actual stack trace
|
|
|
@ -252,6 +208,17 @@ namespace mrw { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static bool createSymtable(const std::string& fname="", void* offs=0) |
|
|
|
static bool createSymtable(const std::string& fname="", void* offs=0) |
|
|
|
throw(std::bad_exception); |
|
|
|
throw(std::bad_exception); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief get the error text if @ref createSymtable returns false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In case @ref createSymtable is not successful, you can use |
|
|
|
|
|
|
|
this method to retrieve the error text of the exception that |
|
|
|
|
|
|
|
was caught in @ref createSymtable. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@return error text */ |
|
|
|
|
|
|
|
static const std::string& error() throw() { |
|
|
|
|
|
|
|
return _error; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** @brief read the symbol table from a list of an executable file and
|
|
|
|
/** @brief read the symbol table from a list of an executable file and
|
|
|
|
shared libraries |
|
|
|
shared libraries |
|
|
@ -288,15 +255,19 @@ namespace mrw { |
|
|
|
static int bfdClose(bfd*) throw(); |
|
|
|
static int bfdClose(bfd*) throw(); |
|
|
|
typedef mrw::AutoResource<bfd*, int(*)(bfd*), StackTrace::bfdClose, int> |
|
|
|
typedef mrw::AutoResource<bfd*, int(*)(bfd*), StackTrace::bfdClose, int> |
|
|
|
AutoBfd; |
|
|
|
AutoBfd; |
|
|
|
|
|
|
|
friend class mrw::AutoResource |
|
|
|
|
|
|
|
<bfd*, int(*)(bfd*), StackTrace::bfdClose, int>; |
|
|
|
//.............................................................. variables
|
|
|
|
//.............................................................. variables
|
|
|
|
AddressTrace _trace; |
|
|
|
AddressTrace _trace; |
|
|
|
static std::map<std::string, Translator> _dic; |
|
|
|
static std::map<std::string, Translator> _dic; |
|
|
|
static std::map<Translator::key_type, std::string> _addrs; |
|
|
|
static std::map<Translator::key_type, std::string> _addrs; |
|
|
|
static std::map<std::string, AutoBfd> _bfd; |
|
|
|
static std::map<std::string, AutoBfd> _bfd; |
|
|
|
static std::map<std::string, mrw::AutoPtr<asymbol*> > _syms; |
|
|
|
static std::map<std::string, mrw::AutoPtr<asymbol*> > _syms; |
|
|
|
#ifdef _REENTRANT |
|
|
|
#ifdef _MT |
|
|
|
static boost::recursive_mutex _mutex; |
|
|
|
static boost::recursive_mutex _mutex; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
static std::string _error; |
|
|
|
|
|
|
|
|
|
|
|
//................................................................ methods
|
|
|
|
//................................................................ methods
|
|
|
|
static BinFiles filename() throw(std::bad_exception); |
|
|
|
static BinFiles filename() throw(std::bad_exception); |
|
|
|
static void buildSectionMap(bfd*, asection*, void*) |
|
|
|
static void buildSectionMap(bfd*, asection*, void*) |
|
|
|