Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --disable-exception-backtrace configure option #256

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,13 @@ EXTRA_DIST = \
generate_commit_hash.sh \
commit_hash.h

AM_CXXFLAGS = -Wall -Werror $(PTHREAD_CFLAGS) $(libev_CFLAGS) $(SQLITE3_CFLAGS) $(CURL_CFLAGS) $(CLBOSS_CXXFLAGS) $(LIBUNWIND_CFLAGS)
LDADD = libclboss.la $(PTHREAD_LIBS) $(libev_LIBS) $(SQLITE3_LIBS) $(CURL_LIBS) $(LIBUNWIND_LIBS)
AM_CXXFLAGS = -Wall -Werror $(PTHREAD_CFLAGS) $(libev_CFLAGS) $(SQLITE3_CFLAGS) $(CURL_CFLAGS) $(CLBOSS_CXXFLAGS)
LDADD = libclboss.la $(PTHREAD_LIBS) $(libev_LIBS) $(SQLITE3_LIBS) $(CURL_LIBS)

if ENABLE_EXCEPTION_BACKTRACE
AM_CXXFLAGS += -DENABLE_EXCEPTION_BACKTRACE $(LIBUNWIND_CFLAGS)
LDADD += $(LIBUNWIND_LIBS)
endif

ACLOCAL_AMFLAGS = -I m4

Expand Down
37 changes: 33 additions & 4 deletions Util/BacktraceException.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
#ifndef UTIL_BACKTRACE_EXCEPTION_HPP
#define UTIL_BACKTRACE_EXCEPTION_HPP

#ifdef HAVE_CONFIG_H
# include"config.h"
#endif

#if !ENABLE_EXCEPTION_BACKTRACE // If not enabled or undefined

#include <utility>

namespace Util {

/** class Util::BacktraceException<E>
*
* @brief A do-nothing wrapper when backtraces are disabled.
*/

template <typename T>
class BacktraceException : public T {
public:
template <typename... Args>
BacktraceException(Args&&... args)
: T(std::forward<Args>(args)...) {}

const char* what() const noexcept override {
return T::what();
}
};

} // namespace Util

#else // ENABLE_EXCEPTION_BACKTRACE in force

#include <array>
#include <execinfo.h>
#include <iomanip>
Expand All @@ -11,10 +42,6 @@
#include <string>
#include <vector>

#ifdef HAVE_CONFIG_H
# include"config.h"
#endif

extern std::string g_argv0;

#define UNW_LOCAL_ONLY
Expand Down Expand Up @@ -150,4 +177,6 @@ class BacktraceException : public T {

} // namespace Util

#endif // ENABLE_EXCEPTION_BACKTRACE

#endif /* UTIL_BACKTRACE_EXCEPTION_HPP */
20 changes: 20 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ LT_INIT([disable-shared])

m4_pattern_forbid([^PKG_])

# Enable exception backtrace option
AC_ARG_ENABLE([exception-backtrace],
[AS_HELP_STRING([--disable-exception-backtrace],
[Disable exception backtrace in exceptions (enabled by default)])],
[case "${enable_exception_backtrace}" in
yes|no) ;;
*) AC_MSG_ERROR([invalid value for --enable-exception-backtrace: ${enable_exception_backtrace}]) ;;
esac],
[enable_exception_backtrace=yes]) # Default to "yes"

AM_CONDITIONAL([ENABLE_EXCEPTION_BACKTRACE], [test "x$enable_exception_backtrace" = "xyes"])
AC_SUBST([ENABLE_EXCEPTION_BACKTRACE], [$enable_exception_backtrace])

# Define a macro in config.h
if test "x$enable_exception_backtrace" = "xyes"; then
AC_DEFINE([ENABLE_EXCEPTION_BACKTRACE], [1], [Define if exception backtraces are enabled])
else
AC_DEFINE([ENABLE_EXCEPTION_BACKTRACE], [0], [Define if exception backtraces are enabled])
fi

# Checks for programs.
# If CXXFLAGS is unset, remove the -g
# that AC_PROG_CXX adds to it.
Expand Down
Loading