It's multithreaded now, thanks to a boost mutex
This commit is contained in:
		@@ -9,6 +9,9 @@
 | 
				
			|||||||
    @license LGPL, see file <a href="license.html">COPYING</a>
 | 
					    @license LGPL, see file <a href="license.html">COPYING</a>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $Log$
 | 
					    $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
 | 
					    Revision 1.13  2005/02/28 07:28:37  marc
 | 
				
			||||||
    typo
 | 
					    typo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -90,7 +93,7 @@ extern "C" {
 | 
				
			|||||||
       - in file file: /usr/include/demangle.h
 | 
					       - in file file: /usr/include/demangle.h
 | 
				
			||||||
       - of package:   binutils-2.15.90.0.1.1-31
 | 
					       - 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
 | 
					      variable name to @c cplus_demangle_fill_builtin_type, so I have
 | 
				
			||||||
      to work around it.
 | 
					      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)
 | 
					mrw::StackTrace::CodePos mrw::StackTrace::translate(void* addr)
 | 
				
			||||||
  throw(std::bad_exception) {
 | 
					  throw(std::bad_exception) {
 | 
				
			||||||
 | 
					#ifdef _REENTRANT
 | 
				
			||||||
 | 
					  boost::recursive_mutex::scoped_lock lock(_mutex);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
  assert(sizeof(bfd_vma)>=sizeof(void*));
 | 
					  assert(sizeof(bfd_vma)>=sizeof(void*));
 | 
				
			||||||
  bfd_vma vma_addr(reinterpret_cast<bfd_vma>(addr));
 | 
					  bfd_vma vma_addr(reinterpret_cast<bfd_vma>(addr));
 | 
				
			||||||
  std::map<Translator::key_type, std::string>::iterator
 | 
					  std::map<Translator::key_type, std::string>::iterator
 | 
				
			||||||
@@ -224,6 +230,9 @@ mrw::StackTrace::CodePos mrw::StackTrace::translate(void* addr)
 | 
				
			|||||||
//----------------------------------------------------------------------------
 | 
					//----------------------------------------------------------------------------
 | 
				
			||||||
bool mrw::StackTrace::createSymtable(const std::string& fname, void* offs)
 | 
					bool mrw::StackTrace::createSymtable(const std::string& fname, void* offs)
 | 
				
			||||||
    throw(std::bad_exception) {
 | 
					    throw(std::bad_exception) {
 | 
				
			||||||
 | 
					#ifdef _REENTRANT
 | 
				
			||||||
 | 
					  boost::recursive_mutex::scoped_lock lock(_mutex);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
  if (_dic.find(fname)!=_dic.end()) return true; // already loaded
 | 
					  if (_dic.find(fname)!=_dic.end()) return true; // already loaded
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    static DynamicLibrary lib("libbfd");
 | 
					    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)
 | 
					bool mrw::StackTrace::createSymtable(const mrw::StackTrace::BinFiles& files)
 | 
				
			||||||
  throw(std::bad_exception) {
 | 
					  throw(std::bad_exception) {
 | 
				
			||||||
 | 
					#ifdef _REENTRANT
 | 
				
			||||||
 | 
					  boost::recursive_mutex::scoped_lock lock(_mutex);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
  bool success(true);
 | 
					  bool success(true);
 | 
				
			||||||
  for (BinFiles::const_iterator it(files.begin());
 | 
					  for (BinFiles::const_iterator it(files.begin());
 | 
				
			||||||
       it!=files.end(); ++it) {
 | 
					       it!=files.end(); ++it) {
 | 
				
			||||||
@@ -353,3 +365,6 @@ std::map<mrw::StackTrace::Translator::key_type, std::string>
 | 
				
			|||||||
  mrw::StackTrace::_addrs;
 | 
					  mrw::StackTrace::_addrs;
 | 
				
			||||||
std::map<std::string, mrw::StackTrace::AutoBfd> mrw::StackTrace::_bfd;
 | 
					std::map<std::string, mrw::StackTrace::AutoBfd> mrw::StackTrace::_bfd;
 | 
				
			||||||
std::map<std::string, mrw::AutoPtr<asymbol*> > mrw::StackTrace::_syms;
 | 
					std::map<std::string, mrw::AutoPtr<asymbol*> > mrw::StackTrace::_syms;
 | 
				
			||||||
 | 
					#ifdef _REENTRANT
 | 
				
			||||||
 | 
					boost::recursive_mutex mrw::StackTrace::_mutex;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,9 @@
 | 
				
			|||||||
    @license LGPL, see file <a href="license.html">COPYING</a>
 | 
					    @license LGPL, see file <a href="license.html">COPYING</a>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $Log$
 | 
					    $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
 | 
					    Revision 1.13  2005/02/18 15:48:56  marc
 | 
				
			||||||
    Dynamic loading of libbfd, no more dependency on specific libbfd version!
 | 
					    Dynamic loading of libbfd, no more dependency on specific libbfd version!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -62,9 +65,8 @@
 | 
				
			|||||||
#include <sys/mman.h>
 | 
					#include <sys/mman.h>
 | 
				
			||||||
#include <bfd.h>
 | 
					#include <bfd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __REENTRANT
 | 
					#ifdef _REENTRANT
 | 
				
			||||||
#warning "mrw::StackTrace is not thread safe yet!"
 | 
					#include <boost/thread/recursive_mutex.hpp>
 | 
				
			||||||
#warning "It should work, but is at least untested..."
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace mrw {
 | 
					namespace mrw {
 | 
				
			||||||
@@ -119,7 +121,7 @@ namespace mrw {
 | 
				
			|||||||
      names, sorce file names and line numbers are evaluated.
 | 
					      names, sorce file names and line numbers are evaluated.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      @note Method StackTrace::createSymtable must be called exactely
 | 
					      @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.
 | 
					      first line of the @c main function.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      @note Debug information is required for compiling. You nee the
 | 
					      @note Debug information is required for compiling. You nee the
 | 
				
			||||||
@@ -169,8 +171,8 @@ namespace mrw {
 | 
				
			|||||||
        CXXFLAGS="-g -fno-inline" ./configure && make clean check
 | 
					        CXXFLAGS="-g -fno-inline" ./configure && make clean check
 | 
				
			||||||
      @endcode
 | 
					      @endcode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      @todo Add support for alternative symbol evaluation using @c
 | 
					      @todo Should I add support for alternative symbol evaluation using @c
 | 
				
			||||||
      backtrace_symbols.
 | 
					      backtrace_symbols? I think rather not...?
 | 
				
			||||||
  */
 | 
					  */
 | 
				
			||||||
  class StackTrace {
 | 
					  class StackTrace {
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
@@ -202,8 +204,8 @@ namespace mrw {
 | 
				
			|||||||
      /// evaluate the stack trace and print it to a stream
 | 
					      /// evaluate the stack trace and print it to a stream
 | 
				
			||||||
      const StackTrace& print(std::ostream& os) const throw(std::bad_exception);
 | 
					      const StackTrace& print(std::ostream& os) const throw(std::bad_exception);
 | 
				
			||||||
      /// evaluates and returns all information from a raw address
 | 
					      /// evaluates and returns all information from a raw address
 | 
				
			||||||
      static CodePos translate(void* addr)
 | 
					      /** @classmutex _mutex */
 | 
				
			||||||
        throw(std::bad_exception);
 | 
					      static CodePos translate(void* addr) throw(std::bad_exception);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
      /** @brief read the symbol table from the executable file or a
 | 
					      /** @brief read the symbol table from the executable file or a
 | 
				
			||||||
          shared library
 | 
					          shared library
 | 
				
			||||||
@@ -239,6 +241,8 @@ namespace mrw {
 | 
				
			|||||||
          @note If this method is called more than once for the same
 | 
					          @note If this method is called more than once for the same
 | 
				
			||||||
          file, the symbols are created only the first time, so you
 | 
					          file, the symbols are created only the first time, so you
 | 
				
			||||||
          don't loose too much time.
 | 
					          don't loose too much time.
 | 
				
			||||||
 | 
					          
 | 
				
			||||||
 | 
					          @classmutex _mutex
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
      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);
 | 
				
			||||||
@@ -266,6 +270,8 @@ namespace mrw {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
          @note This method calls the other one for all files in
 | 
					          @note This method calls the other one for all files in
 | 
				
			||||||
          parameter @c files.
 | 
					          parameter @c files.
 | 
				
			||||||
 | 
					          
 | 
				
			||||||
 | 
					          @classmutex _mutex
 | 
				
			||||||
      */
 | 
					      */
 | 
				
			||||||
      static bool createSymtable(const BinFiles& files)
 | 
					      static bool createSymtable(const BinFiles& files)
 | 
				
			||||||
        throw(std::bad_exception);
 | 
					        throw(std::bad_exception);
 | 
				
			||||||
@@ -282,6 +288,9 @@ namespace mrw {
 | 
				
			|||||||
      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
 | 
				
			||||||
 | 
					      static boost::recursive_mutex _mutex;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
      //................................................................ 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*)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user