Skip to content

Commit 48d92f1

Browse files
codablockUdjinM6
authored andcommitted
Implement optional pretty printed stacktraces (dashpay#2420)
* Add libbacktrace to depends This is currently only useful to extract symbols. It fails to gather stacktraces when compiled with MinGW, so we can only use it to get symbol information from a stack trace which we gathered outside of libbacktrace. * Add -mbig-obj to CXXFLAGS for MinGW builds * Implement stacktraces for C++ exceptions This is a hack and should only be used for debugging. It works by wrapping the C++ ABI __wrap___cxa_allocate_exception. The wrapper records a backtrace and stores it in a global map. Later the stacktrace can be retrieved with GetExceptionStacktraceStr. This commit also adds handlers to pretty print uncaught exceptions and signals. * Use GetPrettyExceptionStr for all unhandled exceptions * Use --enable-stacktraces in CI for linux32/linux64 * Register exception translators to pretty print exceptions in unit tests * Catch and print python exceptions when stopping nodes Otherwise the code at the bottom is never executed when nodes crash, leading to no output of debug.log files on Travis. * Remove now unneeded/unused TestCrash methods
1 parent 0b552be commit 48d92f1

21 files changed

+904
-81
lines changed

ci/matrix.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ elif [ "$BUILD_TARGET" = "linux32" ]; then
5656
export HOST=i686-pc-linux-gnu
5757
export PACKAGES="g++-multilib bc python3-zmq"
5858
export DEP_OPTS="NO_QT=1"
59-
export BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++"
59+
export BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports --enable-stacktraces LDFLAGS=-static-libstdc++"
6060
export USE_SHELL="/bin/dash"
6161
export PYZMQ=true
6262
export RUN_TESTS=true
6363
elif [ "$BUILD_TARGET" = "linux64" ]; then
6464
export HOST=x86_64-unknown-linux-gnu
6565
export PACKAGES="bc python3-zmq"
6666
export DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1"
67-
export BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports"
67+
export BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports --enable-stacktraces"
6868
export CPPFLAGS="-DDEBUG_LOCKORDER -DENABLE_DASH_DEBUG"
6969
export PYZMQ=true
7070
export RUN_TESTS=true

configure.ac

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ AC_ARG_ENABLE([debug],
192192
[enable_debug=$enableval],
193193
[enable_debug=no])
194194

195+
# Enable exception stacktraces
196+
AC_ARG_ENABLE([stacktraces],
197+
[AS_HELP_STRING([--enable-stacktraces],
198+
[gather and print exception stack traces (default is no)])],
199+
[enable_stacktraces=$enableval],
200+
[enable_stacktraces=no])
201+
195202
# Turn warnings into errors
196203
AC_ARG_ENABLE([werror],
197204
[AS_HELP_STRING([--enable-werror],
@@ -211,8 +218,34 @@ if test "x$enable_debug" = xyes; then
211218
if test "x$GXX" = xyes; then
212219
CXXFLAGS="$CXXFLAGS -g3 -O0"
213220
fi
221+
elif test "x$enable_stacktraces" = xyes; then
222+
# Enable debug information but don't turn off optimization
223+
# (stacktraces will be suboptimal, but better than nothing)
224+
if test "x$GCC" = xyes; then
225+
CFLAGS="$CFLAGS -g1 -fno-omit-frame-pointer"
226+
fi
227+
228+
if test "x$GXX" = xyes; then
229+
CXXFLAGS="$CXXFLAGS -g1 -fno-omit-frame-pointer"
230+
fi
214231
fi
215232

233+
AM_CONDITIONAL([ENABLE_STACKTRACES], [test x$enable_stacktraces = xyes])
234+
if test "x$enable_stacktraces" = xyes; then
235+
AC_DEFINE(ENABLE_STACKTRACES, 1, [Define this symbol if stacktraces should be enables])
236+
fi
237+
AX_CHECK_LINK_FLAG([-Wl,-wrap=__cxa_allocate_exception], [LINK_WRAP_SUPPORTED=yes],,,)
238+
AX_CHECK_COMPILE_FLAG([-rdynamic], [RDYNAMIC_SUPPORTED=yes],,,)
239+
AM_CONDITIONAL([STACKTRACE_WRAPPED_CXX_ABI],[test x$LINK_WRAP_SUPPORTED = xyes])
240+
AM_CONDITIONAL([RDYNAMIC_SUPPORTED],[test x$RDYNAMIC_SUPPORTED = xyes])
241+
242+
if test x$LINK_WRAP_SUPPORTED = "xyes"; then
243+
AC_DEFINE(STACKTRACE_WRAPPED_CXX_ABI, 1, [Define this symbol to use wrapped CXX ABIs for exception stacktraces])],
244+
fi
245+
246+
# Needed for MinGW targets when debug symbols are enabled as compiled objects get very large
247+
AX_CHECK_COMPILE_FLAG([-Wa,-mbig-obj], [CXXFLAGS="$CXXFLAGS -Wa,-mbig-obj"],,,)
248+
216249
ERROR_CXXFLAGS=
217250
if test "x$enable_werror" = "xyes"; then
218251
if test "x$CXXFLAG_WERROR" = "x"; then
@@ -1209,6 +1242,7 @@ echo " with test = $use_tests"
12091242
echo " with bench = $use_bench"
12101243
echo " with upnp = $use_upnp"
12111244
echo " debug enabled = $enable_debug"
1245+
echo " stacktraces enabled = $enable_stacktraces"
12121246
echo " werror = $enable_werror"
12131247
echo
12141248
echo " target os = $TARGET_OS"

depends/packages/backtrace.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package=backtrace
2+
$(package)_version=rust-snapshot-2018-05-22
3+
$(package)_download_path=https://github.com/rust-lang-nursery/libbacktrace/archive
4+
$(package)_file_name=$($(package)_version).tar.gz
5+
$(package)_sha256_hash=8da6daa0a582c9bbd1f2933501168b4c43664700f604f43e922e85b99e5049bc
6+
7+
define $(package)_set_vars
8+
$(package)_config_opts=--disable-shared --prefix=$(host_prefix)
9+
endef
10+
11+
define $(package)_config_cmds
12+
$($(package)_autoconf)
13+
endef
14+
15+
define $(package)_build_cmds
16+
$(MAKE)
17+
endef
18+
19+
define $(package)_stage_cmds
20+
$(MAKE) DESTDIR=$($(package)_staging_dir) install
21+
endef

depends/packages/packages.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packages:=boost openssl libevent zeromq gmp chia_bls
1+
packages:=boost openssl libevent zeromq gmp chia_bls backtrace
22
native_packages := native_ccache
33

44
qt_native_packages = native_protobuf

qa/rpc-tests/test_framework/test_framework.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ def main(self):
175175

176176
if not self.options.noshutdown:
177177
print("Stopping nodes")
178-
stop_nodes(self.nodes)
178+
try:
179+
stop_nodes(self.nodes)
180+
except BaseException as e:
181+
success = False
182+
print("Unexpected exception caught during shutdown: " + repr(e))
183+
traceback.print_tb(sys.exc_info()[2])
179184
else:
180185
print("Note: dashds were not stopped and may still be running")
181186

src/Makefile.am

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS)
1010
AM_CPPFLAGS = $(HARDENED_CPPFLAGS)
1111
EXTRA_LIBRARIES =
1212

13+
if ENABLE_STACKTRACES
14+
if STACKTRACE_WRAPPED_CXX_ABI
15+
# Wrap internal C++ ABI's so that we can attach stacktraces to exceptions
16+
LDFLAGS_WRAP_EXCEPTIONS = -Wl,-wrap,__cxa_allocate_exception -Wl,-wrap,__cxa_free_exception
17+
if TARGET_WINDOWS
18+
LDFLAGS_WRAP_EXCEPTIONS += -Wl,-wrap,_assert -Wl,-wrap,_wassert
19+
else
20+
LDFLAGS_WRAP_EXCEPTIONS += -Wl,-wrap,__assert_fail
21+
endif
22+
endif
23+
24+
if RDYNAMIC_SUPPORTED
25+
# This gives better stacktraces
26+
AM_CXXFLAGS += -rdynamic
27+
endif
28+
endif
29+
30+
if TARGET_WINDOWS
31+
BACKTRACE_LIB = -ldbghelp -lbacktrace
32+
else
33+
BACKTRACE_LIB = -lbacktrace
34+
endif
35+
1336
if EMBEDDED_UNIVALUE
1437
LIBUNIVALUE = univalue/libunivalue.la
1538

@@ -184,6 +207,7 @@ BITCOIN_CORE_H = \
184207
script/standard.h \
185208
script/ismine.h \
186209
spork.h \
210+
stacktraces.h \
187211
streams.h \
188212
support/allocators/mt_pooled_secure.h \
189213
support/allocators/pooled_secure.h \
@@ -464,6 +488,7 @@ libdash_util_a_SOURCES = \
464488
compat/strnlen.cpp \
465489
random.cpp \
466490
rpc/protocol.cpp \
491+
stacktraces.cpp \
467492
support/cleanse.cpp \
468493
sync.cpp \
469494
threadinterrupt.cpp \
@@ -492,7 +517,7 @@ nodist_libdash_util_a_SOURCES = $(srcdir)/obj/build.h
492517
dashd_SOURCES = dashd.cpp
493518
dashd_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
494519
dashd_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
495-
dashd_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
520+
dashd_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
496521

497522
if TARGET_WINDOWS
498523
dashd_SOURCES += dashd-res.rc
@@ -511,13 +536,13 @@ dashd_LDADD = \
511536
$(LIBMEMENV) \
512537
$(LIBSECP256K1)
513538

514-
dashd_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) $(BLS_LIBS)
539+
dashd_LDADD += $(BACKTRACE_LIB) $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) $(BLS_LIBS)
515540

516541
# dash-cli binary #
517542
dash_cli_SOURCES = dash-cli.cpp
518543
dash_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS)
519544
dash_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
520-
dash_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
545+
dash_cli_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
521546

522547
if TARGET_WINDOWS
523548
dash_cli_SOURCES += dash-cli-res.rc
@@ -528,14 +553,14 @@ dash_cli_LDADD = \
528553
$(LIBUNIVALUE) \
529554
$(LIBBITCOIN_UTIL) \
530555
$(LIBBITCOIN_CRYPTO)
531-
dash_cli_LDADD += $(BOOST_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(EVENT_LIBS) $(BLS_LIBS)
556+
dash_cli_LDADD += $(BACKTRACE_LIB) $(BOOST_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(EVENT_LIBS) $(BLS_LIBS)
532557
#
533558

534559
# dash-tx binary #
535560
dash_tx_SOURCES = dash-tx.cpp
536561
dash_tx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
537562
dash_tx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
538-
dash_tx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
563+
dash_tx_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
539564

540565
if TARGET_WINDOWS
541566
dash_tx_SOURCES += dash-tx-res.rc
@@ -549,7 +574,7 @@ dash_tx_LDADD = \
549574
$(LIBBITCOIN_CRYPTO) \
550575
$(LIBSECP256K1)
551576

552-
dash_tx_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS) $(BLS_LIBS)
577+
dash_tx_LDADD += $(BACKTRACE_LIB) $(BOOST_LIBS) $(CRYPTO_LIBS) $(BLS_LIBS)
553578
#
554579

555580
# dashconsensus library #

src/Makefile.bench.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ bench_bench_dash_SOURCES += bench/coin_selection.cpp
5555
bench_bench_dash_LDADD += $(LIBBITCOIN_WALLET) $(LIBBITCOIN_CRYPTO)
5656
endif
5757

58-
bench_bench_dash_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS)
59-
bench_bench_dash_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
58+
bench_bench_dash_LDADD += $(BACKTRACE_LIB) $(BOOST_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS)
59+
bench_bench_dash_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
6060

6161
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_TEST_FILES)
6262

src/Makefile.qt.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,9 @@ if ENABLE_ZMQ
643643
qt_dash_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
644644
endif
645645
qt_dash_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
646-
$(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
646+
$(BACKTRACE_LIB) $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
647647
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS)
648-
qt_dash_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
648+
qt_dash_qt_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
649649
qt_dash_qt_LIBTOOLFLAGS = --tag CXX
650650

651651
#locale/foo.ts -> locale/foo.qm

src/Makefile.qttest.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ if ENABLE_ZMQ
4949
qt_test_test_dash_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
5050
endif
5151
qt_test_test_dash_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) \
52-
$(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
52+
$(LIBMEMENV) $(BACKTRACE_LIB) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
5353
$(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \
5454
$(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS)
55-
qt_test_test_dash_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
55+
qt_test_test_dash_qt_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
5656
qt_test_test_dash_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
5757

5858
CLEAN_BITCOIN_QT_TEST = $(TEST_QT_MOC_CPP) qt/test/*.gcda qt/test/*.gcno

src/Makefile.test.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ endif
152152
test_test_dash_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
153153
test_test_dash_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS)
154154
test_test_dash_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
155-
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS)
155+
$(BACKTRACE_LIB) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS)
156156
test_test_dash_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
157157
if ENABLE_WALLET
158158
test_test_dash_LDADD += $(LIBBITCOIN_WALLET)
159159
endif
160160

161161
test_test_dash_LDADD += $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BLS_LIBS)
162-
test_test_dash_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
162+
test_test_dash_LDFLAGS = $(LDFLAGS_WRAP_EXCEPTIONS) $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
163163

164164
if ENABLE_ZMQ
165165
test_test_dash_LDADD += $(ZMQ_LIBS)

src/bench/bench_dash.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "bench.h"
66

77
#include "key.h"
8+
#include "stacktraces.h"
89
#include "validation.h"
910
#include "util.h"
1011

@@ -16,6 +17,9 @@ void CleanupBLSDkgTests();
1617
int
1718
main(int argc, char** argv)
1819
{
20+
RegisterPrettySignalHandlers();
21+
RegisterPrettyTerminateHander();
22+
1923
ECC_Start();
2024
ECCVerifyHandle verifyHandle;
2125

src/dash-cli.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clientversion.h"
1313
#include "rpc/client.h"
1414
#include "rpc/protocol.h"
15+
#include "stacktraces.h"
1516
#include "util.h"
1617
#include "utilstrencodings.h"
1718

@@ -350,7 +351,7 @@ int CommandLineRPC(int argc, char *argv[])
350351
nRet = EXIT_FAILURE;
351352
}
352353
catch (...) {
353-
PrintExceptionContinue(NULL, "CommandLineRPC()");
354+
PrintExceptionContinue(std::current_exception(), "CommandLineRPC()");
354355
throw;
355356
}
356357

@@ -362,6 +363,9 @@ int CommandLineRPC(int argc, char *argv[])
362363

363364
int main(int argc, char* argv[])
364365
{
366+
RegisterPrettyTerminateHander();
367+
RegisterPrettySignalHandlers();
368+
365369
SetupEnvironment();
366370
if (!SetupNetworking()) {
367371
fprintf(stderr, "Error: Initializing networking failed\n");
@@ -372,23 +376,16 @@ int main(int argc, char* argv[])
372376
int ret = AppInitRPC(argc, argv);
373377
if (ret != CONTINUE_EXECUTION)
374378
return ret;
375-
}
376-
catch (const std::exception& e) {
377-
PrintExceptionContinue(&e, "AppInitRPC()");
378-
return EXIT_FAILURE;
379379
} catch (...) {
380-
PrintExceptionContinue(NULL, "AppInitRPC()");
380+
PrintExceptionContinue(std::current_exception(), "AppInitRPC()");
381381
return EXIT_FAILURE;
382382
}
383383

384384
int ret = EXIT_FAILURE;
385385
try {
386386
ret = CommandLineRPC(argc, argv);
387-
}
388-
catch (const std::exception& e) {
389-
PrintExceptionContinue(&e, "CommandLineRPC()");
390387
} catch (...) {
391-
PrintExceptionContinue(NULL, "CommandLineRPC()");
388+
PrintExceptionContinue(std::current_exception(), "CommandLineRPC()");
392389
}
393390
return ret;
394391
}

src/dash-tx.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <boost/algorithm/string.hpp>
2727
#include <boost/assign/list_of.hpp>
2828

29+
#include "stacktraces.h"
30+
2931
static bool fCreateBlank;
3032
static std::map<std::string,UniValue> registers;
3133
static const int CONTINUE_EXECUTION=-1;
@@ -772,7 +774,7 @@ static int CommandLineRawTx(int argc, char* argv[])
772774
nRet = EXIT_FAILURE;
773775
}
774776
catch (...) {
775-
PrintExceptionContinue(NULL, "CommandLineRawTx()");
777+
PrintExceptionContinue(std::current_exception(), "CommandLineRawTx()");
776778
throw;
777779
}
778780

@@ -784,6 +786,9 @@ static int CommandLineRawTx(int argc, char* argv[])
784786

785787
int main(int argc, char* argv[])
786788
{
789+
RegisterPrettyTerminateHander();
790+
RegisterPrettySignalHandlers();
791+
787792
SetupEnvironment();
788793

789794
try {
@@ -792,21 +797,15 @@ int main(int argc, char* argv[])
792797
return ret;
793798
}
794799
catch (const std::exception& e) {
795-
PrintExceptionContinue(&e, "AppInitRawTx()");
796-
return EXIT_FAILURE;
797-
} catch (...) {
798-
PrintExceptionContinue(NULL, "AppInitRawTx()");
800+
PrintExceptionContinue(std::current_exception(), "AppInitRawTx()");
799801
return EXIT_FAILURE;
800802
}
801803

802804
int ret = EXIT_FAILURE;
803805
try {
804806
ret = CommandLineRawTx(argc, argv);
805-
}
806-
catch (const std::exception& e) {
807-
PrintExceptionContinue(&e, "CommandLineRawTx()");
808807
} catch (...) {
809-
PrintExceptionContinue(NULL, "CommandLineRawTx()");
808+
PrintExceptionContinue(std::current_exception(), "CommandLineRawTx()");
810809
}
811810
return ret;
812811
}

0 commit comments

Comments
 (0)