Skip to content

Commit

Permalink
kram-profile - fix demangle crash on Win clang-cli symbols
Browse files Browse the repository at this point in the history
No idea why every platform but Microsoft can't use the same mangled names.  Really clang should demangle these on a per-platform basis so the tools don't have to.  Note that CBA has a Microsoft demangle that could correct this, but would need try both on failure.
  • Loading branch information
alecazam committed Mar 21, 2024
1 parent cccf986 commit 8f893c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 8 additions & 2 deletions kram-profile/Source/KramZipHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <mutex>
#endif

extern "C" const char* _Nonnull demangleSymbolName(const char* _Nonnull symbolName_) {
extern "C" const char* _Nullable demangleSymbolName(const char* _Nonnull symbolName_) {
using namespace NAMESPACE_STL;

// serialize to multiple threads
Expand Down Expand Up @@ -53,7 +53,13 @@ extern "C" const char* _Nonnull demangleSymbolName(const char* _Nonnull symbolNa
}
else {
// This will do repeated demangle though. Maybe should add to table?
result = symbolName_;
// Swift fails when returning back the string it marshalled back to stuff back
// into String(cstring: ...). Ugh. So return empty string.
// status = -2 on most of the mangled Win clang-cli symbols. Nice one
// Microsoft.
//result = symbolName_;

result = nullptr;
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion kram-profile/Source/KramZipHelperW.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ typedef struct ZipEntryW {
@end

// This is only needed for OptFunction and backend names
const char* _Nonnull demangleSymbolName(const char* _Nonnull symbolName_);
const char* _Nullable demangleSymbolName(const char* _Nonnull symbolName_);

16 changes: 10 additions & 6 deletions kram-profile/kram-profile/kram_profileApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1346,9 +1346,11 @@ func updateBuildTimingTask(_ file: File) throws {
let event = events[i]
if event.name == "OptFunction" {
let detail = event.args!["detail"]!.value as! String
let symbolName = String(cString: demangleSymbolName(detail))

events[i].args!["detail"] = AnyCodable(symbolName)
if let demangledName = demangleSymbolName(detail) {
let symbolName = String(cString: demangledName)

events[i].args!["detail"] = AnyCodable(symbolName)
}
}
}

Expand Down Expand Up @@ -1692,9 +1694,11 @@ func loadFileJS(_ file: File) -> String? {
let event = catapultProfile.traceEvents![i]
if event.name == "OptFunction" {
let detail = event.args!["detail"]!.value as! String
let symbolName = String(cString: demangleSymbolName(detail))

catapultProfile.traceEvents![i].args!["detail"] = AnyCodable(symbolName)
if let demangledName = demangleSymbolName(detail) {
let symbolName = String(cString: demangledName)

catapultProfile.traceEvents![i].args!["detail"] = AnyCodable(symbolName)
}
}
}

Expand Down

0 comments on commit 8f893c0

Please sign in to comment.