Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions paddle/platform/enforce.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ limitations under the License. */
#include "paddle/string/printf.h"
#include "paddle/string/to_string.h"

#ifdef __GNUC__
#include <cxxabi.h> // for __cxa_demangle
#endif

#ifndef PADDLE_ONLY_CPU

#include "paddle/platform/dynload/cublas.h"
Expand All @@ -42,6 +46,19 @@ limitations under the License. */
namespace paddle {
namespace platform {

namespace {
#ifdef __GNUC__
inline std::string demangle(std::string name) {
int status = -4; // some arbitrary value to eliminate the compiler warning
std::unique_ptr<char, void (*)(void*)> res{
abi::__cxa_demangle(name.c_str(), NULL, NULL, &status), std::free};
return (status == 0) ? res.get() : name;
}
#else
inline std::string demangle(std::string name) { return name; }
#endif
}

struct EnforceNotMet : public std::exception {
std::exception_ptr exp_;
std::string err_str_;
Expand All @@ -61,8 +78,8 @@ struct EnforceNotMet : public std::exception {

Dl_info info;
for (int i = 0; i < size; ++i) {
if (dladdr(call_stack[i], &info)) {
auto demangled = info.dli_sname;
if (dladdr(call_stack[i], &info) && info.dli_sname) {
Copy link
Contributor Author

@gangliao gangliao Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug is here:

dli_sname   The name of the nearest runtime symbol with value less than or equal to addr. Where possible, the symbol name shall be returned as it would appear in C source code.If no symbol with a suitable value is found, both this field and dli_saddr shall be set to NULL.

auto demangled = demangle(info.dli_sname);
auto addr_offset = static_cast<char*>(call_stack[i]) -
static_cast<char*>(info.dli_saddr);
sout << string::Sprintf("%-3d %*0p %s + %zd\n", i,
Expand Down