From 23439b1688875968ea1de51c7e84061da7535768 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Wed, 4 Nov 2020 21:11:46 +0800 Subject: [PATCH] show cpp stack when catch signal (#28415) --- paddle/fluid/platform/init.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/platform/init.cc b/paddle/fluid/platform/init.cc index ba4520b1388..a594044e9bc 100644 --- a/paddle/fluid/platform/init.cc +++ b/paddle/fluid/platform/init.cc @@ -287,7 +287,7 @@ void SignalHandle(const char *data, int size) { // NOTE2: we only deal with the time info ane signal info, // the stack trace will generated by paddle self if (StartsWith(data, "*** Aborted at")) { - *signal_msg_dunmer_ptr << " [TimeInfo: " << std::string(data, size - 1) + *signal_msg_dunmer_ptr << "\n [TimeInfo: " << std::string(data, size - 1) << "]\n"; } else if (StartsWith(data, "***")) { std::string signal_info(data, size - 1); @@ -295,14 +295,19 @@ void SignalHandle(const char *data, int size) { size_t start_pos = signal_info.rfind(useless_substr); signal_info.replace(start_pos, useless_substr.length(), ""); *signal_msg_dunmer_ptr << " [SignalInfo: " << signal_info << "]\n"; - // NOTE3: Here does not throw an exception, + + // NOTE3: Final singal error message print. + // Here does not throw an exception, // otherwise it will casue "terminate called recursively" - auto exp = platform::EnforceNotMet( - platform::errors::Fatal( - "A serious error (%s) is detected by the operating system.", - ParseSignalErrorString(signal_info)), - __FILE__, __LINE__); - std::cout << exp.what() << (*signal_msg_dunmer_ptr).str() << std::endl; + std::ostringstream sout; + sout << platform::GetCurrentTraceBackString(); + sout << "\n----------------------\nError Message " + "Summary:\n----------------------\n"; + sout << platform::errors::Fatal( + "`%s` is detected by the operating system.", + ParseSignalErrorString(signal_info)) + .to_string(); + std::cout << sout.str() << (*signal_msg_dunmer_ptr).str() << std::endl; } } catch (...) { // Since the program has already triggered a system error, -- GitLab