It's multithreaded now, thanks to a boost mutex

master
Marc Wäckerlin 20 years ago
parent 4b332eb798
commit bfcbda2ead
  1. 17
      mrw/stacktrace.cpp
  2. 23
      mrw/stacktrace.hpp

@ -9,6 +9,9 @@
@license LGPL, see file <a href="license.html">COPYING</a>
$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<bfd_vma>(addr));
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)
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::Translator::key_type, std::string>
mrw::StackTrace::_addrs;
std::map<std::string, mrw::StackTrace::AutoBfd> mrw::StackTrace::_bfd;
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>
$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 <sys/mman.h>
#include <bfd.h>
#ifdef __REENTRANT
#warning "mrw::StackTrace is not thread safe yet!"
#warning "It should work, but is at least untested..."
#ifdef _REENTRANT
#include <boost/thread/recursive_mutex.hpp>
#endif
namespace mrw {
@ -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<Translator::key_type, std::string> _addrs;
static std::map<std::string, AutoBfd> _bfd;
static std::map<std::string, mrw::AutoPtr<asymbol*> > _syms;
#ifdef _REENTRANT
static boost::recursive_mutex _mutex;
#endif
//................................................................ methods
static BinFiles filename() throw(std::bad_exception);
static void buildSectionMap(bfd*, asection*, void*)

Loading…
Cancel
Save