diff --git a/mrw/stacktrace.cpp b/mrw/stacktrace.cpp index de156b6..24f1979 100644 --- a/mrw/stacktrace.cpp +++ b/mrw/stacktrace.cpp @@ -9,6 +9,9 @@ @license LGPL, see file COPYING $Log$ + Revision 1.14 2005/03/11 23:22:58 marc + It's multithreaded now, thanks to a boost mutex + Revision 1.13 2005/02/28 07:28:37 marc typo @@ -90,7 +93,7 @@ extern "C" { - in file file: /usr/include/demangle.h - of package: binutils-2.15.90.0.1.1-31 - An idiot unfortunately abused the C++ keyword @c typename as + Someone unfortunately abused the C++ keyword @c typename as variable name to @c cplus_demangle_fill_builtin_type, so I have to work around it. */ @@ -199,6 +202,9 @@ const mrw::StackTrace& mrw::StackTrace::print(std::ostream& os) const //---------------------------------------------------------------------------- mrw::StackTrace::CodePos mrw::StackTrace::translate(void* addr) throw(std::bad_exception) { +#ifdef _REENTRANT + boost::recursive_mutex::scoped_lock lock(_mutex); +#endif assert(sizeof(bfd_vma)>=sizeof(void*)); bfd_vma vma_addr(reinterpret_cast(addr)); std::map::iterator @@ -224,6 +230,9 @@ mrw::StackTrace::CodePos mrw::StackTrace::translate(void* addr) //---------------------------------------------------------------------------- bool mrw::StackTrace::createSymtable(const std::string& fname, void* offs) throw(std::bad_exception) { +#ifdef _REENTRANT + boost::recursive_mutex::scoped_lock lock(_mutex); +#endif if (_dic.find(fname)!=_dic.end()) return true; // already loaded try { static DynamicLibrary lib("libbfd"); @@ -267,6 +276,9 @@ bool mrw::StackTrace::createSymtable(const std::string& fname, void* offs) //---------------------------------------------------------------------------- bool mrw::StackTrace::createSymtable(const mrw::StackTrace::BinFiles& files) throw(std::bad_exception) { +#ifdef _REENTRANT + boost::recursive_mutex::scoped_lock lock(_mutex); +#endif bool success(true); for (BinFiles::const_iterator it(files.begin()); it!=files.end(); ++it) { @@ -353,3 +365,6 @@ std::map mrw::StackTrace::_addrs; std::map mrw::StackTrace::_bfd; std::map > mrw::StackTrace::_syms; +#ifdef _REENTRANT +boost::recursive_mutex mrw::StackTrace::_mutex; +#endif diff --git a/mrw/stacktrace.hpp b/mrw/stacktrace.hpp index 719b908..15083d7 100644 --- a/mrw/stacktrace.hpp +++ b/mrw/stacktrace.hpp @@ -9,6 +9,9 @@ @license LGPL, see file COPYING $Log$ + 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! @@ -62,9 +65,8 @@ #include #include -#ifdef __REENTRANT -#warning "mrw::StackTrace is not thread safe yet!" -#warning "It should work, but is at least untested..." +#ifdef _REENTRANT +#include #endif namespace mrw { @@ -119,7 +121,7 @@ namespace mrw { names, sorce file names and line numbers are evaluated. @note Method StackTrace::createSymtable must be called exactely - once, before evaluating the first stack trace.Best place is the + once, before evaluating the first stack trace. Best place is the first line of the @c main function. @note Debug information is required for compiling. You nee the @@ -169,8 +171,8 @@ namespace mrw { CXXFLAGS="-g -fno-inline" ./configure && make clean check @endcode - @todo Add support for alternative symbol evaluation using @c - backtrace_symbols. + @todo Should I add support for alternative symbol evaluation using @c + backtrace_symbols? I think rather not...? */ class StackTrace { public: @@ -202,8 +204,8 @@ namespace mrw { /// evaluate the stack trace and print it to a stream const StackTrace& print(std::ostream& os) const throw(std::bad_exception); /// evaluates and returns all information from a raw address - static CodePos translate(void* addr) - throw(std::bad_exception); + /** @classmutex _mutex */ + static CodePos translate(void* addr) throw(std::bad_exception); /** @brief read the symbol table from the executable file or a shared library @@ -239,6 +241,8 @@ namespace mrw { @note If this method is called more than once for the same file, the symbols are created only the first time, so you don't loose too much time. + + @classmutex _mutex */ static bool createSymtable(const std::string& fname="", void* offs=0) throw(std::bad_exception); @@ -266,6 +270,8 @@ namespace mrw { @note This method calls the other one for all files in parameter @c files. + + @classmutex _mutex */ static bool createSymtable(const BinFiles& files) throw(std::bad_exception); @@ -282,6 +288,9 @@ namespace mrw { static std::map _addrs; static std::map _bfd; static std::map > _syms; +#ifdef _REENTRANT + static boost::recursive_mutex _mutex; +#endif //................................................................ methods static BinFiles filename() throw(std::bad_exception); static void buildSectionMap(bfd*, asection*, void*)