From d4136c93448bfdd8561af331ea6eebcec14719e3 Mon Sep 17 00:00:00 2001 From: Simon Kallweit <64953474+skallweitNV@users.noreply.github.com> Date: Fri, 6 Dec 2024 00:46:56 +0100 Subject: Add API for getting last internal error message (#5772) * Add API for getting last internal error message * format code (#5773) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * make message thread_local --------- Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- include/slang.h | 8 ++++++++ source/core/slang-signal.cpp | 9 +++++++++ source/core/slang-signal.h | 2 ++ source/slang/slang-api.cpp | 6 ++++++ 4 files changed, 25 insertions(+) diff --git a/include/slang.h b/include/slang.h index ee9fb7650..2dfee6b28 100644 --- a/include/slang.h +++ b/include/slang.h @@ -4415,6 +4415,10 @@ SLANG_API ISlangBlob* slang_getEmbeddedCoreModule(); */ SLANG_EXTERN_C SLANG_API void slang_shutdown(); +/* Return the last signaled internal error message. + */ +SLANG_EXTERN_C SLANG_API const char* slang_getLastInternalErrorMessage(); + namespace slang { inline SlangResult createGlobalSession(slang::IGlobalSession** outGlobalSession) @@ -4425,6 +4429,10 @@ inline void shutdown() { slang_shutdown(); } +inline const char* getLastInternalErrorMessage() +{ + return slang_getLastInternalErrorMessage(); +} } // namespace slang #endif // C++ helpers diff --git a/source/core/slang-signal.cpp b/source/core/slang-signal.cpp index 4ae75eb0e..8a7690351 100644 --- a/source/core/slang-signal.cpp +++ b/source/core/slang-signal.cpp @@ -6,6 +6,8 @@ namespace Slang { +thread_local String g_lastSignalMessage; + static const char* _getSignalTypeAsText(SignalType type) { switch (type) @@ -54,6 +56,8 @@ String _getMessage(SignalType type, char const* message) printf("%s\n", _getMessage(type, message).getBuffer()); } + g_lastSignalMessage = _getMessage(type, message); + #if SLANG_HAS_EXCEPTIONS switch (type) { @@ -75,4 +79,9 @@ String _getMessage(SignalType type, char const* message) #endif } +const char* getLastSignalMessage() +{ + return g_lastSignalMessage.getBuffer(); +} + } // namespace Slang diff --git a/source/core/slang-signal.h b/source/core/slang-signal.h index 356ae42f6..b71b27581 100644 --- a/source/core/slang-signal.h +++ b/source/core/slang-signal.h @@ -35,6 +35,8 @@ enum class SignalType ::Slang::handleSignal(::Slang::SignalType::AbortCompilation, msg) +const char* getLastSignalMessage(); + } // namespace Slang #endif diff --git a/source/slang/slang-api.cpp b/source/slang/slang-api.cpp index 18d2a5083..e510fc9a2 100644 --- a/source/slang/slang-api.cpp +++ b/source/slang/slang-api.cpp @@ -3,6 +3,7 @@ #include "../core/slang-performance-profiler.h" #include "../core/slang-rtti-info.h" #include "../core/slang-shared-library.h" +#include "../core/slang-signal.h" #include "../slang-record-replay/record/slang-global-session.h" #include "../slang-record-replay/util/record-utility.h" #include "slang-capability.h" @@ -173,6 +174,11 @@ SLANG_API SlangResult slang_createGlobalSessionWithoutCoreModule( return SLANG_OK; } +SLANG_API const char* slang_getLastInternalErrorMessage() +{ + return Slang::getLastSignalMessage(); +} + SLANG_API void spDestroySession(SlangSession* inSession) { if (!inSession) -- cgit v1.2.3