diff --git a/Boss/Main.cpp b/Boss/Main.cpp index ff9bf8f7e..0067f56ed 100644 --- a/Boss/Main.cpp +++ b/Boss/Main.cpp @@ -20,6 +20,8 @@ # include "config.h" #endif +std::string g_argv0; + namespace Boss { class Main::Impl { @@ -62,6 +64,7 @@ class Main::Impl { { assert(argv.size() >= 1); argv0 = argv[0]; + g_argv0 = argv[0]; if (argv.size() >= 2) { auto argv1 = argv[1]; if (argv1 == "--version" || argv1 == "-V") diff --git a/Util/BacktraceException.hpp b/Util/BacktraceException.hpp index 313efb834..6989df147 100644 --- a/Util/BacktraceException.hpp +++ b/Util/BacktraceException.hpp @@ -6,8 +6,15 @@ #include #include #include -#include +#include #include +#include + +#ifdef HAVE_CONFIG_H +# include"config.h" +#endif + +extern std::string g_argv0; namespace Util { @@ -74,13 +81,29 @@ class BacktraceException : public T { return oss.str(); } + std::string progname() const { + // This variable is set by the CLBOSS mainline. + if (!g_argv0.empty()) { + return g_argv0; + } + + // When libclboss is linked with the unit tests the + // g_argv0 variable is not set and we need to use + // built-in versions +#ifdef HAVE_GETPROGNAME + return getprogname(); +#else + return program_invocation_name; +#endif + } + // Unfortunately there is no simple way to get a high quality // backtrace using in-process libraries. Instead for now we // popen an addr2line process and use it's output. std::string addr2line(void* addr) const { char cmd[512]; snprintf(cmd, sizeof(cmd), - "addr2line -C -f -p -e %s %p", program_invocation_name, addr); + "addr2line -C -f -p -e %s %p", progname().c_str(), addr); std::array buffer; std::string result; diff --git a/configure.ac b/configure.ac index 87d11ab04..f9538a09b 100644 --- a/configure.ac +++ b/configure.ac @@ -100,6 +100,21 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[ AC_MSG_RESULT([no]) ]) +# Check for getprogname() +AC_MSG_CHECKING([for getprogname]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include +]], [[ + const char* p = getprogname(); + (void)p; // avoid warning about set but unused variable +]])], [ #then + AC_DEFINE([HAVE_GETPROGNAME], [1], + [Define to 1 if you have a getprogname function.]) + AC_MSG_RESULT([yes]) +], [ #else + AC_MSG_RESULT([no]) +]) + AC_CONFIG_FILES([Makefile external/bitcoin-ripemd160/Makefile external/bitcoin-sha256/Makefile