diff --git a/kram-profile/Source/KramZipHelper.cpp b/kram-profile/Source/KramZipHelper.cpp index 42c175e..f653ef2 100644 --- a/kram-profile/Source/KramZipHelper.cpp +++ b/kram-profile/Source/KramZipHelper.cpp @@ -25,7 +25,7 @@ #include #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 @@ -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; diff --git a/kram-profile/Source/KramZipHelperW.h b/kram-profile/Source/KramZipHelperW.h index bb5659b..304ad78 100644 --- a/kram-profile/Source/KramZipHelperW.h +++ b/kram-profile/Source/KramZipHelperW.h @@ -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_); diff --git a/kram-profile/kram-profile/kram_profileApp.swift b/kram-profile/kram-profile/kram_profileApp.swift index c15487d..815f168 100644 --- a/kram-profile/kram-profile/kram_profileApp.swift +++ b/kram-profile/kram-profile/kram_profileApp.swift @@ -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) + } } } @@ -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) + } } }