From 368ddbb7b99dfb939d20f53c35d05b2b4758bd64 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 21 Jul 2025 09:30:24 -0700 Subject: Add utility to trace creation of problematic IRInsts to assist LLM in debugging (#7820) * Initial plan * Add SLANG_DEBUG_IR_BREAK environment variable support Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Apply code formatting to SLANG_DEBUG_IR_BREAK implementation Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Improve stack trace debugging with -rdynamic flag and backtrace_symbols Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Address PR feedback: use PlatformUtil::getEnvironmentVariable, remove -rdynamic flag, and delete fallback branch Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Address PR feedback: simplify env var parsing, move backtrace to PlatformUtil, use #if for SLANG_LINUX_FAMILY Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Address PR feedback: remove unneeded include, make backtrace() more generic by removing uid parameter Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix and clone source tracking. * Add python script to dump traces. * Update instructions. * Batch calls to addr2line * Cleanup claude instructions. * update claude action. * Remove duplicated build instructions from claude.yml workflow Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * fix build error. * Fix build errors --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> Co-authored-by: Yong He Co-authored-by: Gangzheng Tong --- source/core/slang-platform.cpp | 26 ++++++++++++++++++++++++++ source/core/slang-platform.h | 4 ++++ 2 files changed, 30 insertions(+) (limited to 'source/core') diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp index 2c2bdd25e..aab1f3044 100644 --- a/source/core/slang-platform.cpp +++ b/source/core/slang-platform.cpp @@ -15,6 +15,11 @@ #include #endif + +#if SLANG_LINUX_FAMILY +#include +#endif + namespace Slang { // SharedLibrary @@ -331,4 +336,25 @@ static const PlatformFlags s_familyFlags[int(PlatformFamily::CountOf)] = { #endif } +/* static */ void PlatformUtil::backtrace() +{ +#if SLANG_LINUX_FAMILY + // Print stack trace for debugging assistance + void* stackTrace[64]; + int stackDepth = ::backtrace(stackTrace, 64); + char** symbols = ::backtrace_symbols(stackTrace, stackDepth); + if (symbols) + { + for (int i = 0; i < stackDepth; ++i) + { + fprintf(stdout, "%s\n", symbols[i]); + } + free(symbols); + } + fprintf(stdout, "\n"); +#else + fprintf(stdout, "Stack trace not available on this platform.\n"); +#endif +} + } // namespace Slang diff --git a/source/core/slang-platform.h b/source/core/slang-platform.h index 0b97aca6d..04559cbcf 100644 --- a/source/core/slang-platform.h +++ b/source/core/slang-platform.h @@ -150,6 +150,10 @@ struct PlatformUtil /// @param text Text to be displayed in 'debugger output' /// @return SLANG_E_NOT_AVAILABLE if not on this platform, and potentially other errors static SlangResult outputDebugMessage(const char* text); + + /// Print a stack trace to stderr for debugging purposes. + /// Only available on Linux family platforms. + static void backtrace(); }; #ifndef _MSC_VER -- cgit v1.2.3