CHECK_C_COMPILER_FLAG("-Werror=format-security" CC_FORMAT_SECURITY)
CHECK_CXX_COMPILER_FLAG("-Werror=format-security" CXX_FORMAT_SECURITY)
-SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -fno-strict-aliasing -fPIC -g -Wall -Woverloaded-virtual -Wnon-virtual-dtor -Wl,-as-needed -std=c++0x" )
-SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -fPIC -g -Wall -Wl,-as-needed" )
+SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -fno-strict-aliasing -fPIC -g -rdynamic -Wall -Woverloaded-virtual -Wnon-virtual-dtor -Wl,-as-needed -std=c++0x" )
+SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing -fPIC -g -rdynamic -Wall -Wl,-as-needed" )
set( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3" )
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3" )
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/base/Backtrace.cc
+ */
+#include <execinfo.h>
+#include <cxxabi.h>
+
+#include <iostream>
+#include "zypp/base/LogTools.h"
+#include "zypp/base/String.h"
+#include "zypp/base/Backtrace.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{
+ std::ostream & dumpBacktrace( std::ostream & stream_r )
+ {
+ // get void*'s for all entries on the stack
+ static const size_t arraySize = 50;
+ void *array[arraySize];
+ size_t size = ::backtrace( array, arraySize );
+
+ // print out all the frames to stderr
+ char ** messages = ::backtrace_symbols( array, size );
+ if ( messages )
+ {
+ static const size_t first = 1;
+ for ( size_t i = first; i < size; ++i )
+ {
+ char * mangled_name = 0;
+ char * offset_begin = 0;
+ char * offset_end = 0;
+
+ // find parantheses and +address offset surrounding mangled name
+ for ( char * p = messages[i]; *p; ++p )
+ {
+ if ( *p == '(' )
+ {
+ mangled_name = p;
+ }
+ else if ( *p == '+' )
+ {
+ offset_begin = p;
+ }
+ else if ( *p == ')' )
+ {
+ offset_end = p;
+ break;
+ }
+ }
+
+ if ( i > first )
+ stream_r << endl;
+
+ // if the line could be processed, attempt to demangle the symbol
+ if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin )
+ {
+ *mangled_name++ = '\0';
+ *offset_begin++ = '\0';
+ *offset_end++ = '\0';
+
+ int status;
+ char * real_name = ::abi::__cxa_demangle( mangled_name, 0, 0, &status );
+
+ // if demangling is successful, output the demangled function name
+ if ( status == 0 )
+ {
+ stream_r << "[bt]: (" << i << ") " << messages[i] << " : "
+ << real_name << "+" << offset_begin << offset_end;
+
+ }
+ // otherwise, output the mangled function name
+ else
+ {
+ stream_r << "[bt]: (" << i << ") " << messages[i] << " : "
+ << mangled_name << "+" << offset_begin << offset_end;
+ }
+ ::free( real_name );
+ }
+ else
+ {
+ // otherwise, print the whole line
+ stream_r << "[bt]: (" << i << ") " << messages[i];
+ }
+ }
+ ::free( messages );
+ }
+ return stream_r;
+ }
+
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/base/Backtrace.h
+ */
+#ifndef ZYPP_BASE_BACKTRACE_H
+#define ZYPP_BASE_BACKTRACE_H
+
+#include <iosfwd>
+#include <string>
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{
+
+ /** Dump current stack trace to a stream.
+ * Thanks to http://stackoverflow.com/questions/77005.
+ * \code
+ * #include <iostream>
+ * std::cerr << zypp::dumpBacktrace << std::endl;
+ * \endcode
+ * \code
+ * #include <zypp/base/String.h>
+ * std::string trace( str::Str() << zypp::dumpBacktrace );
+ * \endcode
+ */
+ std::ostream & dumpBacktrace( std::ostream & stream_r );
+
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_BASE_BACKTRACE_H