From 8d5c98e8c057a653376f0a4dca96138fe5042bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 13 Oct 2004 10:47:15 +0000 Subject: [PATCH] no more need for ldd in StackTrace, read from /proc/self/maps --- mrw/stacktrace.cpp | 42 +++++++++++++++---------------- mrw/stacktrace.hpp | 61 ++++++++++++++++++++++++++++++++-------------- 2 files changed, 62 insertions(+), 41 deletions(-) diff --git a/mrw/stacktrace.cpp b/mrw/stacktrace.cpp index 15fb4a9..a5a6ae9 100644 --- a/mrw/stacktrace.cpp +++ b/mrw/stacktrace.cpp @@ -9,6 +9,9 @@ @license LGPL, see file COPYING $Log$ + Revision 1.7 2004/10/13 10:47:15 marc + no more need for ldd in StackTrace, read from /proc/self/maps + Revision 1.6 2004/10/11 15:58:51 marc First version with working support for shared libraries! @@ -45,6 +48,7 @@ #include #include #include +#include #include #include #if defined(__solaris__) @@ -237,10 +241,10 @@ bool mrw::StackTrace::createSymtable(const mrw::StackTrace::BinFiles& files) mrw::StackTrace::BinFiles mrw::StackTrace::filename() throw(std::bad_exception) { mrw::StackTrace::BinFiles res; - std::string s; - s<<"/proc/"< "); - if (pos>address; - if (file.size()) res<>range>>perm>>x1>>x2>>size>>lib; + range.resize(range.find_first_not_of("0123456789abcdefABCDEF")); + void* addr(0); + range>>addr; + if (lib.size() && addr>0) res<COPYING $Log$ + 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 @@ -90,7 +93,6 @@ namespace mrw { - either a GNU glibc bases system (LINUX), or the GNU gcc compiler - a system with ELF binaries (LINUX, Solaris, ...) - debug information, compile option @c -g - - it must be linked with @c -libery and @c -lbfd */ //@{ @@ -108,10 +110,8 @@ namespace mrw { once, before evaluating the first stack trace.Best place is the first line of the @c main function. - @note This class requires libbfd an libiberty. Debug information - is required for compiling. You nee the compile option @c -g, or - even better @c -ggdb3. To link, you need @c -lmrw, @c -lbfd and - @c -liberty. + @note Debug information is required for compiling. You nee the + compile option @c -g, or even better @c -ggdb3. @note The stack trace is known to work perfectly on Linux and Solaris both with GNU gcc compiler. But it should work with the @@ -145,17 +145,43 @@ namespace mrw { Unfortunately it is not possible to extract the source file name and line number information if the executable was not compiled - with debug option @c -g. But what's worse, it is not possible to - ger symbolic information from libraries linked to the - executable. Perhaps it could be possible, if I'd add a - possibility to read and evaluate these libraries, but that's for - a future release. (Now, 10/08/2004, I am working on it) - - @todo Add support to read debugging information from libraries - that are linked to the executable. (soon) + with debug option @c -g. @todo Add support for alternative symbol evaluation using @c backtrace_symbols. + + @bug File and line is wrong where the exception is thrown. On + Address [0x4007830b] file and line is wrong, the file should be + /privat/home/marc/pro/mrw-c++/mrw/exception.cpp. File and line + are always wrong at the line where the exception is + instanciated. Why?!? (Could it be, because there is a string + created inline? The trace always shows basic_string.h.) + @code +UNEXPECTED EXCEPTION: ---------------------------- +---------- Reason: +mrw::Exec: command execution failed + failed command was: "/bin/false" + error was: "execution failed" +---------- Stack: +1[0x8049b71] ../sysdeps/i386/elf/start.S:105 _start +[0x4022f92b] ????:0 __libc_start_main +[0x8049c96] /usr/include/g++/bits/basic_string.h:249 main +[0x40054668] ????:0 CppUnit::TextUi::TestRunner::run(std::string, bool, bool, bool) +[0x40054747] ????:0 CppUnit::TextUi::TestRunner::runTestByName(std::string, bool) +[0x400543ec] ????:0 CppUnit::TextUi::TestRunner::runTest(CppUnit::Test*, bool) +[0x4005525b] ????:0 CppUnit::TestSuite::run(CppUnit::TestResult*) +[0x4005525b] ????:0 CppUnit::TestSuite::run(CppUnit::TestResult*) +[0x4005525b] ????:0 CppUnit::TestSuite::run(CppUnit::TestResult*) +[0x4004aa06] ????:0 CppUnit::TestCase::run(CppUnit::TestResult*) +[0x804b164] /usr/include/cppunit/TestCaller.h:166 CppUnit::TestCaller::runTest() +[0x804b299] /usr/include/g++/bits/stl_alloc.h:652 ExecTest::unexpectedExc() +[0x40078bda] /privat/home/marc/pro/mrw-c++/mrw/exec.cpp:77 mrw::Cmd::execute(bool) const +[0x4007830b] /usr/include/g++/bits/basic_string.h:249 mrw::Exec::execute(bool) +[0x40077941] /privat/home/marc/pro/mrw-c++/mrw/exec.cpp:38 mrw::ExecutionFailedExc::ExecutionFailedExc(std::string const&, std::string const&) +[0x400769d4] /privat/home/marc/pro/mrw-c++/mrw/exception.cpp:41 mrw::exception::exception() +[0x4007cbc5] /privat/home/marc/pro/mrw-c++/mrw/stacktrace.cpp:118 mrw::StackTrace::StackTrace() +------------------------------------------------- + @endcode */ class StackTrace { public: @@ -193,11 +219,10 @@ namespace mrw { /** @brief read the symbol table from the executable file or a shared library - On Solaris and Linux, the name of the executable is - automatically detected through the @c /dev/proc file - system. Only on Linux the shared libraries are detected - through a call to @c ldd. So you may leave the parameter - empty on these systems. + On Solaris and Linux, the executable is automatically + detected through the @c /proc file system. Only on Linux the + shared libraries are detected through @c /proc/self/maps. So + you may leave the parameter empty on these systems. @param fname The file name of the executable or a shared library. On Linux and Solaris, this can be evaluated