未验证 提交 4841474e 编写于 作者: C Chen Weihang 提交者: GitHub

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

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