未验证 提交 1d1552d1 编写于 作者: C Chen Weihang 提交者: GitHub

Make formatted ENFORCE stack adapt to more situations (#20826)

* Make formatted ENFORCE stack adapt to more situations and polish details, test=develop

* restore template message position, test=develop
上级 378fc4fb
...@@ -46,19 +46,15 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs, ...@@ -46,19 +46,15 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs,
} }
} }
// Step 2. Insert python traceback into err_str_ // Step 2. Insert python traceback into err_str_
std::size_t found = exception->err_str_.rfind("PaddleCheckError:"); std::size_t found = exception->err_str_.rfind(
"\n----------------------\nError Message "
"Summary:\n----------------------\n");
if (found != std::string::npos) { if (found != std::string::npos) {
exception->err_str_.insert(found, sout_py_trace.str()); exception->err_str_.insert(found, sout_py_trace.str());
exception->err_str_.insert(found + sout_py_trace.str().length(),
"\n----------------------\nError Message "
"Summary:\n----------------------\n");
} else { } else {
exception->err_str_.append(sout_py_trace.str()); exception->err_str_.append(sout_py_trace.str());
} }
// Step 3. Construct final call stack // Step 3. Construct final call stack & append error op name
sout << "\n\n--------------------------------------------\n";
sout << "C++ Call Stacks (More useful to developers):";
sout << "\n--------------------------------------------\n";
sout << exception->err_str_; sout << exception->err_str_;
if (callstack) { if (callstack) {
sout << " [operator < " << type << " > error]"; sout << " [operator < " << type << " > error]";
......
...@@ -74,6 +74,9 @@ inline std::string GetTraceBackString(StrType&& what, const char* file, ...@@ -74,6 +74,9 @@ inline std::string GetTraceBackString(StrType&& what, const char* file,
static constexpr int TRACE_STACK_LIMIT = 100; static constexpr int TRACE_STACK_LIMIT = 100;
std::ostringstream sout; std::ostringstream sout;
sout << "\n\n--------------------------------------------\n";
sout << "C++ Call Stacks (More useful to developers):";
sout << "\n--------------------------------------------\n";
#if !defined(_WIN32) #if !defined(_WIN32)
void* call_stack[TRACE_STACK_LIMIT]; void* call_stack[TRACE_STACK_LIMIT];
auto size = backtrace(call_stack, TRACE_STACK_LIMIT); auto size = backtrace(call_stack, TRACE_STACK_LIMIT);
...@@ -102,8 +105,10 @@ inline std::string GetTraceBackString(StrType&& what, const char* file, ...@@ -102,8 +105,10 @@ inline std::string GetTraceBackString(StrType&& what, const char* file,
} }
free(symbols); free(symbols);
#else #else
sout << "Windows not support stack backtrace yet."; sout << "Windows not support stack backtrace yet.\n";
#endif #endif
sout << "\n----------------------\nError Message "
"Summary:\n----------------------\n";
sout << string::Sprintf("PaddleCheckError: %s at [%s:%d]", sout << string::Sprintf("PaddleCheckError: %s at [%s:%d]",
std::forward<StrType>(what), file, line) std::forward<StrType>(what), file, line)
<< std::endl; << std::endl;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册