Skip to content

Commit

Permalink
Merge pull request #1355 from yingcong-wu/yc/demangle-kernelname
Browse files Browse the repository at this point in the history
[DeviceSanitizerLayer] Demangle the kernel name in error reporting
  • Loading branch information
pbalcer authored Feb 20, 2024
2 parents 3fd11f1 + 7490bc7 commit 4814e71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/loader/layers/sanitizer/asan_interceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ void SanitizerInterceptor::postLaunchKernel(ur_kernel_handle_t Kernel,
const char *Func = AH->Func[0] ? AH->Func : "<unknown func>";
auto KernelName = getKernelName(Kernel);

// Try to demangle the kernel name
KernelName = DemangleName(KernelName);

context.logger.always("\n====ERROR: DeviceSanitizer: {} on {}",
DeviceSanitizerFormat(AH->ErrorType),
DeviceSanitizerFormat(AH->MemoryType));
Expand Down
3 changes: 3 additions & 0 deletions source/loader/layers/sanitizer/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <cassert>
#include <cstdint>
#include <string>

namespace ur_sanitizer_layer {

Expand Down Expand Up @@ -107,4 +108,6 @@ bool DestroyShadowMem();

void *GetMemFunctionPointer(const char *);

std::string DemangleName(const std::string &name);

} // namespace ur_sanitizer_layer
13 changes: 13 additions & 0 deletions source/loader/layers/sanitizer/linux/san_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include "ur_sanitizer_layer.hpp"

#include <asm/param.h>
#include <cxxabi.h>
#include <dlfcn.h>
#include <gnu/lib-names.h>
#include <string>
#include <sys/mman.h>

extern "C" __attribute__((weak)) void __asan_init(void);
Expand Down Expand Up @@ -84,4 +86,15 @@ void *GetMemFunctionPointer(const char *FuncName) {
return ptr;
}

std::string DemangleName(const std::string &name) {
std::string result = name;
char *demangled =
abi::__cxa_demangle(name.c_str(), nullptr, nullptr, nullptr);
if (demangled) {
result = demangled;
free(demangled);
}
return result;
}

} // namespace ur_sanitizer_layer

0 comments on commit 4814e71

Please sign in to comment.