Commit 8d3a0163 authored by Erwan Croze's avatar Erwan Croze 👋🏻

Merge branch 'dev_exception_android'

parents 0e6ef1b8 a3bc63a6
Pipeline #237 failed with stage
in 0 seconds
......@@ -31,3 +31,4 @@
#cmakedefine HAVE_LIBRT 1
#cmakedefine BCTBX_STATIC
#cmakedefine HAVE_EXECINFO
......@@ -32,13 +32,11 @@ set(HEADER_FILES
parser.h
regex.h
charconv.h
exception.hh
)
if(ENABLE_TESTS_COMPONENT)
list(APPEND HEADER_FILES tester.h)
endif()
if(HAVE_EXECINFO)
list(APPEND HEADER_FILES exception.hh)
endif()
set(BCTOOLBOX_HEADER_FILES )
foreach(HEADER_FILE ${HEADER_FILES})
......
......@@ -35,6 +35,7 @@ set(BCTOOLBOX_CXX_SOURCE_FILES
conversion/charconv.cc
crypto/ecc.cc
utils/regex.cc
utils/exception.cc
)
set(BCTOOLBOX_OBJC_SOURCE_FILES)
......@@ -52,10 +53,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND STRICT_OPTIONS_CXX "-x c++")
endif()
if(HAVE_EXECINFO)
list(APPEND BCTOOLBOX_CXX_SOURCE_FILES utils/exception.cc)
endif()
if(MBEDTLS_FOUND)
list(APPEND BCTOOLBOX_C_SOURCE_FILES crypto/mbedtls.c)
endif()
......
......@@ -16,16 +16,24 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bctoolbox/exception.hh"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_EXECINFO
#include <execinfo.h>
#endif
#include <unistd.h>
#include "bctoolbox/logging.h"
#include "dlfcn.h"
#include <dlfcn.h>
#include <cxxabi.h>
#include <exception>
#include <iomanip>
#include <libgen.h>
#include "bctoolbox/exception.hh"
#include "bctoolbox/logging.h"
using namespace std;
static void uncaught_handler() {
......@@ -42,13 +50,19 @@ static void uncaught_handler() {
BctbxException::BctbxException(const char *message) : mOffset(1), mSize(0) {
#ifdef HAVE_EXECINFO
mSize = backtrace(mArray, sizeof(mArray) / sizeof(void *));
#else
mSize = 0;
#endif
if (message)
mOs << message;
#ifdef HAVE_EXECINFO
#if __clang
if (get_terminate() != uncaught_handler)
#endif
set_terminate(uncaught_handler); // invoke in case of uncautch exception for this thread
#endif
}
BctbxException::BctbxException(const BctbxException &other) : mOffset(other.mOffset), mSize(other.mSize) {
......@@ -62,7 +76,11 @@ BctbxException::BctbxException(const string &msg) : BctbxException(msg.c_str())
}
#else
BctbxException::BctbxException(const string &message) : mOffset(2) {
#ifdef HAVE_EXECINFO
mSize = backtrace(mArray, sizeof(mArray) / sizeof(void *));
#else
mSize = 0;
#endif
*this << message;
set_terminate(uncaught_handler); // invoke in case of uncautch exception for this thread
}
......@@ -78,17 +96,28 @@ BctbxException::BctbxException() : BctbxException("") {
}
#else
BctbxException::BctbxException() : mOffset(2) {
#ifdef HAVE_EXECINFO
mSize = backtrace(mArray, sizeof(mArray) / sizeof(void *));
#else
mSize = 0;
#endif
*this << "";
#ifdef HAVE_EXECINFO
set_terminate(uncaught_handler); // invoke in case of uncautch exception for this thread
#endif
}
#endif
void BctbxException::printStackTrace() const {
#ifdef HAVE_EXECINFO
backtrace_symbols_fd(mArray + mOffset, mSize - mOffset, STDERR_FILENO);
#else
std::cout << "stack trace not available on this platform";
#endif
}
void BctbxException::printStackTrace(std::ostream &os) const {
#ifdef HAVE_EXECINFO
char **bt = backtrace_symbols(mArray, mSize);
int position=0;
for (unsigned int i = mOffset; i < mSize; ++i) {
......@@ -112,6 +141,9 @@ void BctbxException::printStackTrace(std::ostream &os) const {
os << std::endl;
}
free(bt);
#else
os << "stack trace not available on this platform";
#endif
}
const std::string &BctbxException::str() const {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment