diff --git a/bootstrap/cmake_modules/CMakeLists.txt b/bootstrap/cmake_modules/CMakeLists.txt index 777fe6f9..cb316971 100644 --- a/bootstrap/cmake_modules/CMakeLists.txt +++ b/bootstrap/cmake_modules/CMakeLists.txt @@ -5,6 +5,7 @@ FindLEFDEF.cmake FindBootstrap.cmake FindLibexecinfo.cmake + FindLibbfd.cmake FindQwt.cmake GetGitRevisionDescription.cmake GetGitRevisionDescription.cmake.in diff --git a/bootstrap/cmake_modules/FindLibbfd.cmake b/bootstrap/cmake_modules/FindLibbfd.cmake new file mode 100644 index 00000000..7b7b5e89 --- /dev/null +++ b/bootstrap/cmake_modules/FindLibbfd.cmake @@ -0,0 +1,84 @@ +# - Try to find libbfd +# Once done this will define +# +# LIBBFD_FOUND - system has libbfd +# LIBBFD_INCLUDE_DIRS - the libbfd include directory +# LIBBFD_LIBRARIES - Link these to use libbfd +# LIBBFD_DEFINITIONS - Compiler switches required for using libbfd +# +# Based on: +# +# Copyright (c) 2008 Bernhard Walle +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + if(LIBBFD_LIBRARIES AND LIBBFD_INCLUDE_DIRS) + set(LIBBFD_FIND_QUIETLY TRUE) + endif() + + execute_process(COMMAND "ld" "--version" + RESULT_VARIABLE RETURN_CODE + OUTPUT_VARIABLE LD_MESSAGE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(REGEX REPLACE "GNU ld version ([^ ]+) .*" "\\1" BINUTILS_VERSION ${LD_MESSAGE} ) + message("-- Using system specific BFD library: " ${BINUTILS_VERSION}) + + find_path(LIBBFD_INCLUDE_DIRS NAMES bfd.h + dis-asm.h + PATHS /usr/include + /usr/local/include + /opt/local/include + /opt/include + ENV CPATH) + +# Ugly, yes ugly... + find_library(LIBBFD_BFD_LIBRARY NAMES bfd-${BINUTILS_VERSION} + PATHS /usr/lib + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + /usr/include + /opt/local/lib + /opt/usr/lib64 + ENV LIBRARY_PATH + ENV LD_LIBRARY_PATH) + +#find_library (LIBBFD_IBERTY_LIBRARY NAMES iberty +# PATHS /usr/lib +# /usr/lib64 +# /usr/local/lib +# /usr/local/lib64 +# /usr/include +# /opt/local/lib +# /opt/usr/lib64 +# ENV LIBRARY_PATH +# ENV LD_LIBRARY_PATH) + +#find_library (LIBBFD_OPCODES_LIBRARY NAMES opcodes +# PATHS /usr/lib +# /usr/lib64 +# /usr/local/lib +# /usr/local/lib64 +# /usr/include +# /opt/local/lib +# /opt/usr/lib64 +# ENV LIBRARY_PATH +# ENV LD_LIBRARY_PATH) + + include(FindPackageHandleStandardArgs) + + find_package_handle_standard_args(LIBBFD DEFAULT_MSG + LIBBFD_BFD_LIBRARY +# LIBBFD_IBERTY_LIBRARY +# LIBBFD_OPCODES_LIBRARY + LIBBFD_INCLUDE_DIRS) + + if(LIBBFD_FOUND) + add_definitions(-DHAVE_LIBBFD) + endif() + + set(LIBBFD_LIBRARIES "${LIBBFD_BFD_LIBRARY}") + mark_as_advanced(LIBBFD_INCLUDE_DIRS LIBBFD_LIBRARIES LIBBFD_BFD_LIBRARY) diff --git a/crlcore/CMakeLists.txt b/crlcore/CMakeLists.txt index 75ae2747..071b5cf2 100644 --- a/crlcore/CMakeLists.txt +++ b/crlcore/CMakeLists.txt @@ -30,6 +30,7 @@ find_package(VLSISAPD REQUIRED) find_package(HURRICANE REQUIRED) find_package(Libexecinfo REQUIRED) + find_package(Libbfd) add_subdirectory(src) add_subdirectory(python) diff --git a/crlcore/src/cyclop/CMakeLists.txt b/crlcore/src/cyclop/CMakeLists.txt index 5b6f0b3e..a8352187 100644 --- a/crlcore/src/cyclop/CMakeLists.txt +++ b/crlcore/src/cyclop/CMakeLists.txt @@ -43,6 +43,7 @@ endif() -lutil ${LIBXML2_LIBRARIES} ${LIBEXECINFO_LIBRARIES} + ${LIBBFD_LIBRARIES} ) install ( TARGETS cyclop DESTINATION bin ) diff --git a/crlcore/src/x2y/CMakeLists.txt b/crlcore/src/x2y/CMakeLists.txt index 7a54160c..7f48b108 100644 --- a/crlcore/src/x2y/CMakeLists.txt +++ b/crlcore/src/x2y/CMakeLists.txt @@ -14,5 +14,6 @@ target_link_libraries ( cx2y crlcore ${UTILITIES_LIBRARY} ${LIBEXECINFO_LIBRARIES} + ${LIBBFD_LIBRARIES} ) install ( TARGETS cx2y DESTINATION bin ) diff --git a/hurricane/CMakeLists.txt b/hurricane/CMakeLists.txt index bafa6a4a..565a0fd7 100644 --- a/hurricane/CMakeLists.txt +++ b/hurricane/CMakeLists.txt @@ -14,7 +14,7 @@ set_cmake_policies() set_lib_link_mode() - setup_boost(regex) + setup_boost(program_options regex) setup_qt() find_package(LibXml2 REQUIRED) @@ -25,6 +25,7 @@ find_package(PythonSitePackages REQUIRED) find_package(VLSISAPD REQUIRED) find_package(Libexecinfo REQUIRED) + find_package(Libbfd) add_subdirectory(src) add_subdirectory(cmake_modules) diff --git a/hurricane/src/hurricane/Backtrace.cpp b/hurricane/src/hurricane/Backtrace.cpp index 2849cecd..77a0bd61 100644 --- a/hurricane/src/hurricane/Backtrace.cpp +++ b/hurricane/src/hurricane/Backtrace.cpp @@ -1,4 +1,3 @@ - // -*- C++ -*- // // Copyright (c) BULL S.A. 2000-2016, All Rights Reserved @@ -28,17 +27,380 @@ // | =============================================================== | // | C++ Module : "./Backtrace.cpp" | // +-----------------------------------------------------------------+ +// +// The BFD part of this file is based on the work of Don Hatch (hatch@plunk.org) +// http://www.plunk.org/~hatch/goodies/backtracefilt.C +// +// Here's the basic idea... consider a sample trace +// generated from backtrace() and backtrace_symbols(): +// +// ./libp2lite.so [0xf5c4b4] +// ./libp2lite.so(malloc+0x1a6) [0xf5de78] +// /usr/lib/perl5/libperl.so(Perl_safesysmalloc+0x37) [0x33a2c97] +// /usr/lib/perl5/libperl.so(Perl_gv_init+0x8b) [0x335ce8a] +// /usr/lib/perl5/libperl.so(Perl_gv_fetchpv+0x412) [0x335daeb] +// /usr/lib/perl5/libperl.so(Perl_newXS+0x3e) [0x3381c53] +// /usr/lib/perl5/libperl.so(Perl_boot_core_PerlIO+0x5d) [0x341edef] +// /usr/lib/perl5/libperl.so [0x3358d6e] +// /usr/lib/perl5/libperl.so(perl_parse+0x424) [0x335b862] +// perl(main+0xc2) [0x804927a] +// /lib/tls/libc.so.6(__libc_start_main+0xd3) [0x8b4e23] +// perl [0x8049131] +// +// If we run addr2line on the first address: +// % addr2line -e ./libp2lite.so 0xf5c4b4 +// ??:0 +// It's clueless because 0xf5c4b4 is a dynamically relocated runtime address +// but addr2line expects a static address. :-( +// +// However, look at the next line: it says that at runtime, +// malloc+0x1a6 == 0xf5de78. +// If we compare this to the static address of malloc+0x1a6 in the file, +// this will tell us the relocation offset, which will enable us +// to go back and adjust the first address appropriately. +// We can find the static address of malloc in libp2lite.so +// either by running something like "nm libp2lite.so | grep malloc", +// or: +// % objdump -d --prefix-addresses libp2lite.so | grep "" +// 00010e78 add $0x10,%esp +// So the address malloc+0x1a6 got relocated from 0x00010e78 +// in the file to 0xf5de78 at runtime. +// +// Therefore the amount that this text segment got shifted by +// during dynamic loading was 0xf5de78-0x00010e78 = 0xf4d000. +// Knowing that, we can now go back to the first dynamic address 0xf5c4b4 +// and figure out its static address: 0xf5c4b4 - 0xf4d000 = 0xf4b4. +// +// Feeding *that* into addr2line: +// % addr2line -e ./libp2lite.so 0xf4b4 +// /home/hatch/share/wrk/p2lite/p2lite.C:335 +// Yippee!!! +// Similarly, we can find the dynamic relocation offsets for perl +// and libperl.so, allowing us to get info for each line of the stack trace. #if (defined __linux__ || defined __FreeBSD__ || defined __APPLE__) #include +#ifdef HAVE_LIBBFD +#include +#endif #endif #include #include +#include #include +#include +namespace boptions = boost::program_options; #include "hurricane/Backtrace.h" +namespace { + + using namespace std; + using Hurricane::demangle; + + + std::string environmentMapper ( std::string environmentName ) + { + if (environmentName == "HOME") return "home"; + return ""; + } + + + string getHome () + { + boptions::options_description options ( "Environment Variables" ); + options.add_options()( "home", boptions::value(), "User's home directory." ); + + boptions::variables_map arguments; + boptions::store ( boptions::parse_environment(options,environmentMapper), arguments ); + boptions::notify ( arguments ); + + return arguments["home"].as(); + } + + +#ifdef HAVE_LIBBFD + + class Bfd { + public: + // Sub-class Request. + class Request { + public: + inline Request ( string dsoPath, string symbol, int64_t symbolOffset, int64_t relocatedAddress ); + inline string dsoPath () const; + inline string symbol () const; + inline int64_t offsetFromSymbol () const; + inline int64_t relocatedAddress () const; + inline string fileName () const; + inline string funcName () const; + inline unsigned int lineno () const; + inline string& fileName (); + inline string& funcName (); + inline unsigned int& lineno (); + private: + string _dsoPath; + string _symbol; + int64_t _offsetFromSymbol; + int64_t _relocatedAddress; + string _filename; + string _funcname; + unsigned int _lineno; + }; + + public: + static Bfd* open ( string dsoPath ); + void close (); + inline bool isRelocated () const; + inline bfd* abfd () const; + inline string dsoPath () const; + inline int64_t relocation () const; + bool lookup ( Request& ); + ~Bfd (); + private: + Bfd ( string dsoPath ); + Bfd ( const Bfd& ) = delete; + Bfd& operator= ( const Bfd& ) = delete; + void _clear (); + void _slurpSymtab (); + bool _computeRelocation ( Request& ); + private: + string _dsoPath; + int64_t _relocationOffset; + bfd* _abfd; + asection* _textSection; + asymbol** _symbolTable; + int _nSymbols; + unsigned int _symbolSize; + asymbol* _scratchSymbol; + bool _useMini; + bool _useDynamic; + bool _isLoaded; + bool _isRelocated; + }; + + + inline Bfd::Request::Request ( string dsoPath, string symbol, int64_t offsetFromSymbol, int64_t relocatedAddress ) + : _dsoPath (dsoPath) + , _symbol (symbol) + , _offsetFromSymbol(offsetFromSymbol) + , _relocatedAddress(relocatedAddress) + , _filename () + , _funcname () + , _lineno () + { } + + inline string Bfd::Request::dsoPath () const { return _dsoPath; }; + inline string Bfd::Request::symbol () const { return _symbol; }; + inline int64_t Bfd::Request::offsetFromSymbol () const { return _offsetFromSymbol; }; + inline int64_t Bfd::Request::relocatedAddress () const { return _relocatedAddress; }; + inline string Bfd::Request::fileName () const { return _filename; }; + inline string Bfd::Request::funcName () const { return _funcname; }; + inline unsigned int Bfd::Request::lineno () const { return _lineno; }; + inline string& Bfd::Request::fileName () { return _filename; }; + inline string& Bfd::Request::funcName () { return _funcname; }; + inline unsigned int& Bfd::Request::lineno () { return _lineno; }; + + + inline bool Bfd::isRelocated () const { return _isRelocated; } + + + Bfd::Bfd ( string dsoPath ) + : _dsoPath (dsoPath) + , _relocationOffset(-1) + , _abfd (NULL) + , _textSection (NULL) + , _symbolTable (NULL) + , _nSymbols (0) + , _symbolSize (0) + , _scratchSymbol (NULL) + , _useMini (true) + , _useDynamic (false) + , _isLoaded (false) + , _isRelocated (false) + { } + + + Bfd::~Bfd () + { + _clear(); + } + + + void Bfd::_clear () + { + //if (_scratchSymbol) { free( _scratchSymbol ); _scratchSymbol = NULL; } + if (_symbolTable) { free( _symbolTable ); _symbolTable = NULL; } + if (_abfd) { bfd_close( _abfd ); _abfd = NULL; } + } + + + void Bfd::_slurpSymtab () + { + if (_isLoaded or not _abfd) return; + _isLoaded = true; + + if (not (bfd_get_file_flags(_abfd) & HAS_SYMS)) return; + + if (_useMini) { + _nSymbols = bfd_read_minisymbols( _abfd, _useDynamic, (void**)&_symbolTable, &_symbolSize ); + if (_nSymbols == 0) { + _useDynamic = true; + _nSymbols = bfd_read_minisymbols( _abfd, _useDynamic, (void**)&_symbolTable, &_symbolSize ); + } + if (_nSymbols < 0) return; + } else { + long symtabSize = bfd_get_symtab_upper_bound( _abfd ); + if (symtabSize < 0) return; + if (symtabSize > 0) { + _symbolTable = (asymbol**)malloc( symtabSize ); + _nSymbols = bfd_canonicalize_symtab( _abfd, _symbolTable ); + + if (_nSymbols == 0) { + free( _symbolTable ); + _symbolTable = NULL; + return; + } + } + + } + } + + + Bfd* Bfd::open ( string dsoPath ) + { + Bfd* obfd = new Bfd ( dsoPath ); + + obfd->_abfd = bfd_openr( dsoPath.c_str(), NULL ); + + if (not obfd->_abfd) return obfd; + if (not bfd_check_format(obfd->_abfd,bfd_object)) { obfd->_clear(); return obfd; } + + obfd->_textSection = bfd_get_section_by_name( obfd->_abfd, ".text" ); + if (not obfd->_textSection) { obfd->_clear(); return obfd; } + + obfd->_slurpSymtab(); + + if (not (bfd_get_section_flags(obfd->_abfd, obfd->_textSection) & SEC_ALLOC)) { obfd->_clear(); return obfd; } + + obfd->_scratchSymbol = bfd_make_empty_symbol( obfd->_abfd ); + if (not obfd->_scratchSymbol) { obfd->_clear(); return obfd; } + + return obfd; + } + + + bool Bfd::_computeRelocation ( Bfd::Request& request ) + { + if (not _abfd) return false; + + int index = 0; + bfd_byte* entry = (bfd_byte*)_symbolTable; + bfd_byte* end = entry + _nSymbols*_symbolSize; + + for ( ; entry < end ; entry += _symbolSize, ++index ) { + asymbol* dsoSymbol = bfd_minisymbol_to_symbol( _abfd, _useDynamic, entry, _scratchSymbol ); + if (not dsoSymbol) continue; + + symbol_info info; + bfd_get_symbol_info( _abfd, dsoSymbol, &info ); + if ((info.type == 'T') or (info.type == 'W')) { + if (string(info.name) == request.symbol()) { + _isRelocated = true; + _relocationOffset = request.relocatedAddress() - request.offsetFromSymbol() - (int64_t)info.value; + return true; + } + } + } + + return false; + } + + + bool Bfd::lookup ( Bfd::Request& request ) + { + if (not _isRelocated and not _computeRelocation(request)) return false; + + int64_t dsoAddress = request.relocatedAddress() - _relocationOffset; + bfd_vma textSectionVma = bfd_get_section_vma( _abfd, _textSection ); + bfd_size_type textSectionSize = bfd_section_size ( _abfd, _textSection ); + const char* fileName = NULL; + const char* funcName = NULL; + + if ( (dsoAddress < (int64_t) textSectionVma) + or (dsoAddress > (int64_t)(textSectionVma+textSectionSize) ) ) { + return false; + } + + bool found = bfd_find_nearest_line( _abfd + , _textSection + , _symbolTable + , dsoAddress - textSectionVma + , &fileName + , &funcName + , &request.lineno() ); + + if (found) { + if (fileName) request.fileName() = fileName; + if (funcName) request.funcName() = funcName; + } + return found; + } + + + class Bfds { + public: + Bfds (); + ~Bfds (); + Bfd* find ( string dsoPath ); + bool lookup ( Bfd::Request& ); + private: + Bfds ( const Bfds& ) = delete; + Bfds& operator= ( const Bfds& ) = delete; + private: + map _bfds; + }; + + + Bfds::Bfds () + : _bfds() + { } + + + Bfds::~Bfds () + { + for ( auto ielement : _bfds ) delete ielement.second; + } + + + Bfd* Bfds::find ( string dsoPath ) + { + auto ibfd = _bfds.find( dsoPath ); + if (ibfd != _bfds.end()) return ibfd->second; + + Bfd* obfd = Bfd::open( dsoPath ); + if (not obfd) return NULL; + + _bfds.insert( make_pair(dsoPath,obfd) ); + + return obfd; + } + + + bool Bfds::lookup ( Bfd::Request& request ) + { + Bfd* obfd = find( request.dsoPath() ); + if (not obfd) return false; + + return obfd->lookup( request ); + } + +#endif + + +} // Anonymous namespace. + + namespace Hurricane { using std::string; @@ -70,28 +432,46 @@ namespace Hurricane { void* rawStack [ _stackSize ]; size_t depth = backtrace ( rawStack, _stackSize ); char** symbols = backtrace_symbols ( rawStack, depth ); +#ifdef HAVE_LIBBFD + Bfds bfds; +#endif #endif #if (defined __linux__ || defined __FreeBSD__) - boost::regex re ( "([^/]+)\\(([^+]+)\\+" ); + boost::regex re ( "(?[^(]+)\\((?[^+]+)\\+(?[^)]+)\\) \\[(?.+)]" ); boost::cmatch match; + string homeDir = getHome(); for ( size_t i=0 ; i )"; - _stack.push_back ( reformated ); + if (boost::regex_search(symbols[i],match,re)) { + int64_t symbolOffset = std::stol( match["symoff" ], 0, 16 ); + int64_t rlocAddress = std::stol( match["rlocAddr"], 0, 16 ); + ostringstream debugline; + +#ifdef HAVE_LIBBFD + Bfd::Request request ( match["dsoPath"], match["symbol"], symbolOffset, rlocAddress ); + + if (bfds.lookup(request) and not request.fileName().empty()) { + string fileName = request.fileName(); + if (not request.fileName().compare( 0, homeDir.size(), homeDir )) + fileName = "~" + request.fileName().substr( homeDir.size() ); + + debugline << "" << demangle(request.funcName()) << "  " + << fileName << ":" << request.lineno(); + } else { +#endif + string demangled = demangle( match["symbol"] ); + if (demangled.empty()) demangled = match["symbol"]; + + debugline << "" << demangled << ""; +#ifdef HAVE_LIBBFD } +#endif + _stack.push_back( debugline.str() ); } else { - _stack.push_back ( symbols[i] ); + _stack.push_back( symbols[i] ); } } -#else # ifdef __APPLE__ boost::regex re ( "(\\d+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+\\+\\s+(\\d+)" ); boost::cmatch match; @@ -100,19 +480,19 @@ namespace Hurricane { if ( boost::regex_search(symbols[i],match,re) ) { string function ( match[4].first, match[4].second ); string demangled ( demangle(function.c_str()) ); - if ( demangled.empty() ) - _stack.push_back ( (demangled.empty()) ? function : demangled ); + if (demangled.empty()) + _stack.push_back( (demangled.empty()) ? function : demangled ); else { string reformated ( match[1].first, match[1].second ); reformated += " " + demangled + ""; - _stack.push_back ( reformated ); + _stack.push_back( reformated ); } } else { - _stack.push_back ( symbols[i] ); + _stack.push_back( symbols[i] ); } } # else - _stack.push_back ( "Backtrace only supported under FreeBSD, Linux and OSX." ); + _stack.push_back( "Backtrace only supported under FreeBSD, Linux and OSX." ); # endif #endif } diff --git a/hurricane/src/hurricane/CMakeLists.txt b/hurricane/src/hurricane/CMakeLists.txt index e66a1acc..c9a827f0 100644 --- a/hurricane/src/hurricane/CMakeLists.txt +++ b/hurricane/src/hurricane/CMakeLists.txt @@ -183,7 +183,7 @@ ) add_library ( hurricane ${cpps} ) - target_link_libraries ( hurricane ${Boost_LIBRARIES} ${BZIP2_LIBRARIES} ) + target_link_libraries ( hurricane ${Boost_LIBRARIES} ${BZIP2_LIBRARIES} ${LIBBFD_LIBRARIES} ) set_target_properties ( hurricane PROPERTIES VERSION 1.0 SOVERSION 1 ) install ( TARGETS hurricane DESTINATION lib${LIB_SUFFIX} ) install ( FILES ${includes} DESTINATION include/coriolis2/hurricane ) diff --git a/hurricane/src/hurricane/TextTranslator.cpp b/hurricane/src/hurricane/TextTranslator.cpp index 701f35a3..9feed6f7 100644 --- a/hurricane/src/hurricane/TextTranslator.cpp +++ b/hurricane/src/hurricane/TextTranslator.cpp @@ -1,30 +1,21 @@ - // -*- C++ -*- // // This file is part of the Coriolis Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2016, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | +// +-----------------------------------------------------------------+ // | H U R R I C A N E | // | V L S I B a c k e n d D a t a - B a s e | // | | // | Author : Jean-Paul CHAPUT | -// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | E-mail : Jean-Paul.Chaput@lip6.fr | // | =============================================================== | // | C++ Module : "./TextTranslator.cpp" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// +-----------------------------------------------------------------+ -#include -#include "hurricane/TextTranslator.h" +#include +#include "hurricane/TextTranslator.h" namespace Hurricane { @@ -84,6 +75,7 @@ namespace Hurricane { _toTextTranslator.addTranslation ( "" , "" ); _toTextTranslator.addTranslation ( "<" , "<" ); _toTextTranslator.addTranslation ( ">" , ">" ); + _toTextTranslator.addTranslation ( " " , " " ); } return _toTextTranslator; diff --git a/hurricane/src/hurricane/hurricane/Backtrace.h b/hurricane/src/hurricane/hurricane/Backtrace.h index 506e985b..48045240 100644 --- a/hurricane/src/hurricane/hurricane/Backtrace.h +++ b/hurricane/src/hurricane/hurricane/Backtrace.h @@ -1,4 +1,3 @@ - // -*- C++ -*- // // Copyright (c) BULL S.A. 2000-2016, All Rights Reserved @@ -19,12 +18,7 @@ // License along with Hurricane. If not, see // . // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | +// +-----------------------------------------------------------------+ // | H U R R I C A N E | // | V L S I B a c k e n d D a t a - B a s e | // | | @@ -32,16 +26,13 @@ // | E-mail : Jean-Paul.Chaput@lip6.fr | // | =============================================================== | // | C++ Header : "./hurricane/Backtrace.h" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// +-----------------------------------------------------------------+ -#ifndef __HURRICANE_BACKTRACE__ -#define __HURRICANE_BACKTRACE__ +#ifndef HURRICANE_BACKTRACE_H +#define HURRICANE_BACKTRACE_H -#include +#include #include "hurricane/Commons.h" #include "hurricane/TextTranslator.h" @@ -71,7 +62,6 @@ namespace Hurricane { inline std::string Backtrace::_getString () const { return ""; } -} // End of Hurricane namespace. +} // Hurricane namespace. - -#endif +#endif // HURRICANE_BACKTRACE_H diff --git a/hurricane/src/hurricane/hurricane/Commons.h b/hurricane/src/hurricane/hurricane/Commons.h index 2f021890..73eaf8a7 100644 --- a/hurricane/src/hurricane/hurricane/Commons.h +++ b/hurricane/src/hurricane/hurricane/Commons.h @@ -93,6 +93,7 @@ namespace Hurricane { inline Type abs ( const Type& value ) { return (value<0) ? -value : value; } string demangle ( const char* symbol ); + inline string demangle ( string symbol ) { return demangle(symbol.c_str()); } inline string demangle ( const type_info& info ) { return demangle(info.name()); } template diff --git a/hurricane/src/hurricane/hurricane/TextTranslator.h b/hurricane/src/hurricane/hurricane/TextTranslator.h index 11adee94..d6674bcf 100644 --- a/hurricane/src/hurricane/hurricane/TextTranslator.h +++ b/hurricane/src/hurricane/hurricane/TextTranslator.h @@ -1,33 +1,24 @@ - // -*- C++ -*- // // This file is part of the Coriolis Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2016, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | +// +-----------------------------------------------------------------+ // | H U R R I C A N E | // | V L S I B a c k e n d D a t a - B a s e | // | | // | Author : Jean-Paul CHAPUT | -// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | E-mail : Jean-Paul.Chaput@lip6.fr | // | =============================================================== | -// | C++ Header : "./TextTranslator.h" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// | C++ Header : "./hurricane/TextTranslator.h" | +// +-----------------------------------------------------------------+ -#ifndef __HURRICANE_TEXT_TRANSLATOR__ -#define __HURRICANE_TEXT_TRANSLATOR__ +#ifndef HURRICANE_TEXT_TRANSLATOR_H +#define HURRICANE_TEXT_TRANSLATOR_H -#include -#include +#include +#include namespace Hurricane { @@ -68,7 +59,7 @@ namespace Hurricane { } -} // End of Hurricane namespace. +} // Hurricane namespace. -#endif // __HURRICANE_TEXT_TRANSLATOR__ +#endif // HURRICANE_TEXT_TRANSLATOR_H diff --git a/hurricane/src/viewer/ExceptionWidget.cpp b/hurricane/src/viewer/ExceptionWidget.cpp index a29d70b7..8b3417f6 100644 --- a/hurricane/src/viewer/ExceptionWidget.cpp +++ b/hurricane/src/viewer/ExceptionWidget.cpp @@ -31,6 +31,7 @@ #include "hurricane/Bug.h" #include "hurricane/Error.h" #include "hurricane/Exception.h" +#include "hurricane/TextTranslator.h" #include "hurricane/viewer/Graphics.h" #include "hurricane/viewer/ExceptionWidget.h" @@ -56,12 +57,17 @@ namespace Hurricane { { ExceptionWidget* ew = new ExceptionWidget(); - ew->setMessage ( what ); - if ( not where.isEmpty() ) - ew->setTrace ( where ); + ew->setMessage( what ); + if (not where.isEmpty()) + ew->setTrace( where ); - if ( ew->exec() == QDialog::Rejected ) - kill ( getpid(), SIGSEGV ); + if (ew->exec() == QDialog::Rejected) { + cerr << "\n[BUG] A C++ exception was catched:\n" << endl; + cerr << TextTranslator::toTextTranslator().translate( what.toStdString() ) << endl; + cerr << "\n[Backtrace]" << endl; + cerr << TextTranslator::toTextTranslator().translate( where.toStdString() ) << endl; + kill( getpid(), SIGSEGV ); + } } @@ -106,7 +112,7 @@ namespace Hurricane { setWindowTitle( tr("") ); setToolTip ( tr("Ben mon cochon, t'es dans le bouillon") ); - _header->setMinimumWidth ( Graphics::isHighDpi() ? 400 : 200 ); + _header->setMinimumWidth ( Graphics::isHighDpi() ? 1500 : 400 ); _header->setTextFormat ( Qt::RichText ); _header->setText ( "[ERROR]" ); @@ -116,7 +122,7 @@ namespace Hurricane { _trace->setTextInteractionFlags ( Qt::TextBrowserInteraction ); _trace->setAcceptRichText ( true ); _trace->setHtml ( "No program trace sets yet." ); - _trace->setMinimumSize ( QSize( Graphics::isHighDpi() ? 1800 : 800, 500) ); + _trace->setMinimumSize ( Graphics::isHighDpi() ? QSize(2500,1000) : QSize(800,500) ); _trace->setLineWrapMode ( QTextEdit::NoWrap ); //_trace->setSizePolicy ( QSizePolicy::Ignored, QSizePolicy::Ignored ); _trace->hide (); diff --git a/unicorn/CMakeLists.txt b/unicorn/CMakeLists.txt index 16ededd9..5ae9230c 100644 --- a/unicorn/CMakeLists.txt +++ b/unicorn/CMakeLists.txt @@ -15,6 +15,7 @@ setup_boost(program_options python regex) setup_qt() + find_package(Libbfd) find_package(LibXml2 REQUIRED) find_package(PythonLibs REQUIRED) find_package(PythonSitePackages REQUIRED) diff --git a/unicorn/src/CMakeLists.txt b/unicorn/src/CMakeLists.txt index 506fee88..a2884517 100644 --- a/unicorn/src/CMakeLists.txt +++ b/unicorn/src/CMakeLists.txt @@ -69,6 +69,7 @@ ${PYTHON_LIBRARIES} -lutil ${LIBXML2_LIBRARIES} + ${LIBBFD_LIBRARIES} ) add_library( unicorn ${cpps} ${mocCpps} ${pyCpps} )