未验证 提交 572adccd 编写于 作者: C Chen Weihang 提交者: GitHub

Remove incorrect signal error stack trace (#34842)

* remove unmatched signal error stack

* fix error writing for cond
上级 dc62a227
...@@ -270,12 +270,14 @@ inline std::string SimplifyDemangleStr(std::string str) { ...@@ -270,12 +270,14 @@ inline std::string SimplifyDemangleStr(std::string str) {
return str; return str;
} }
inline std::string GetCurrentTraceBackString() { inline std::string GetCurrentTraceBackString(bool for_signal = false) {
std::ostringstream sout; std::ostringstream sout;
sout << "\n\n--------------------------------------\n"; if (!for_signal) {
sout << "C++ Traceback (most recent call last):"; sout << "\n\n--------------------------------------\n";
sout << "\n--------------------------------------\n"; sout << "C++ Traceback (most recent call last):";
sout << "\n--------------------------------------\n";
}
#if !defined(_WIN32) && !defined(PADDLE_WITH_MUSL) #if !defined(_WIN32) && !defined(PADDLE_WITH_MUSL)
static constexpr int TRACE_STACK_LIMIT = 100; static constexpr int TRACE_STACK_LIMIT = 100;
...@@ -284,7 +286,12 @@ inline std::string GetCurrentTraceBackString() { ...@@ -284,7 +286,12 @@ inline std::string GetCurrentTraceBackString() {
auto symbols = backtrace_symbols(call_stack, size); auto symbols = backtrace_symbols(call_stack, size);
Dl_info info; Dl_info info;
int idx = 0; int idx = 0;
for (int i = size - 1; i >= 0; --i) { // `for_signal` used to remove the stack trace introduced by
// obtaining the error stack trace when the signal error occurred,
// that is not related to the signal error self, remove it to
// avoid misleading users and developers
int end_idx = for_signal ? 2 : 0;
for (int i = size - 1; i >= end_idx; --i) {
if (dladdr(call_stack[i], &info) && info.dli_sname) { if (dladdr(call_stack[i], &info) && info.dli_sname) {
auto demangled = demangle(info.dli_sname); auto demangled = demangle(info.dli_sname);
std::string path(info.dli_fname); std::string path(info.dli_fname);
......
...@@ -294,7 +294,17 @@ void SignalHandle(const char *data, int size) { ...@@ -294,7 +294,17 @@ void SignalHandle(const char *data, int size) {
// Here does not throw an exception, // Here does not throw an exception,
// otherwise it will casue "terminate called recursively" // otherwise it will casue "terminate called recursively"
std::ostringstream sout; std::ostringstream sout;
sout << platform::GetCurrentTraceBackString(); sout << "\n\n--------------------------------------\n";
sout << "C++ Traceback (most recent call last):";
sout << "\n--------------------------------------\n";
auto traceback = platform::GetCurrentTraceBackString(/*for_signal=*/true);
if (traceback.empty()) {
sout
<< "No stack trace in paddle, may be caused by external reasons.\n";
} else {
sout << traceback;
}
sout << "\n----------------------\nError Message " sout << "\n----------------------\nError Message "
"Summary:\n----------------------\n"; "Summary:\n----------------------\n";
sout << platform::errors::Fatal( sout << platform::errors::Fatal(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册