From 771195159f3007c76dd67114e2b38bff70061dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Thu, 7 Oct 2004 16:59:12 +0000 Subject: [PATCH] new method createSymtable that takes a list of arguments -> untested! --- mrw/stacktrace.cpp | 36 +++++++++++++++++++++++++++++++++++- mrw/stacktrace.hpp | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/mrw/stacktrace.cpp b/mrw/stacktrace.cpp index 456530d..047b29a 100644 --- a/mrw/stacktrace.cpp +++ b/mrw/stacktrace.cpp @@ -9,6 +9,10 @@ @license LGPL, see file COPYING $Log$ + Revision 1.5 2004/10/07 16:59:12 marc + new method createSymtable that takes a list of arguments + -> untested! + Revision 1.4 2004/10/07 09:32:45 marc correction in parameter (const&) @@ -180,7 +184,8 @@ namespace mrw { } //---------------------------------------------------------------------------- - bool StackTrace::createSymtable(const std::string& fname) throw(std::bad_exception) { + bool StackTrace::createSymtable(const std::string& fname) + throw(std::bad_exception) { if (_dic.get()) return true; AutoBfd abfd(bfd_openr((fname!="" ? fname : filename()).c_str(), 0)); long memsz(-1); @@ -204,6 +209,35 @@ namespace mrw { return true; } + //---------------------------------------------------------------------------- + bool StackTrace::createSymtable(const std::list& fnames) + throw(std::bad_exception) { + if (_dic.get()) return true; + for (std::list::const_iterator it(fnames.begin()); + it!=fnames.end(); ++it) { + AutoBfd abfd(bfd_openr(it->c_str(), 0)); + long memsz(-1); + Auto::Free m(0); + if (!abfd || bfd_check_format(abfd, bfd_archive) || + !bfd_check_format_matches(abfd, bfd_object, &(m.getClean())) || + !(bfd_get_file_flags(const_cast(static_cast(abfd))) + &HAS_SYMS) || + (memsz=bfd_get_symtab_upper_bound + (const_cast(static_cast(abfd))))<0) + return false; + std::auto_ptr syms(new asymbol*[memsz]); + if (bfd_canonicalize_symtab(const_cast(static_cast(abfd)), + syms.get())<0) + return false; + _bfd = abfd; + _syms = syms; + if (!_dic.get()) _dic = std::auto_ptr(new Translator()); + bfd_map_over_sections(_bfd, buildSectionMap, 0); + } + std::sort(_addrs.begin(), _addrs.end()); + return true; + } + //---------------------------------------------------------------------------- std::string StackTrace::filename() throw(std::bad_exception) { std::stringstream s; diff --git a/mrw/stacktrace.hpp b/mrw/stacktrace.hpp index b7896c7..116c967 100644 --- a/mrw/stacktrace.hpp +++ b/mrw/stacktrace.hpp @@ -9,6 +9,10 @@ @license LGPL, see file COPYING $Log$ + 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&) @@ -30,6 +34,7 @@ #define __MRW_STACKTRACE_HPP__ #include #include +#include #include #include #include @@ -173,7 +178,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); + static CodePos translate(void* addr) + throw(std::bad_exception); /** @brief read the symbol table from the executable file @@ -191,11 +197,40 @@ namespace mrw { (that means for the creation of a mrw::StackTrace object) a call to this method is not yet needed. + @note Call only one of both createSymtable methods! + + @note If this method is called more than once, the symbols + are created only the first time, so you don't loose too much + time. + */ + static bool createSymtable(const std::string& fname="") + throw(std::bad_exception); + + /** @brief read the symbol table from a list of an executable file and + shared libraries + + @param fnames The list of file names that must contain the + executable plus all shared libraries that should be included + in stack traces. + + @return @c true in case of success. If @c false is returned, + the symbol table was not completely read and the evaluation + cannot be done. Printing then only prints the raw addresses, + without file, line nmber information and method names. + + @note This method must be executed once before a stack trace + is printed the very first time. For storing a stack trace + (that means for the creation of a mrw::StackTrace object) a + call to this method is not yet needed. + + @note Call only one of both createSymtable methods! + @note If this method is called more than once, the symbols are created only the first time, so you don't loose too much time. */ - static bool createSymtable(const std::string& fname="") throw(std::bad_exception); + static bool createSymtable(const std::list& fnames) throw(std::bad_exception); + private: //............................................................... typedefs typedef std::map >