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/slang/slang.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index f65681e4b..29ca2328b 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -4,8 +4,10 @@ #include "../core/slang-castable.h" #include "../core/slang-io.h" #include "../core/slang-performance-profiler.h" +#include "../core/slang-platform.h" #include "../core/slang-shared-library.h" #include "../core/slang-string-util.h" +#include "../core/slang-string.h" #include "../core/slang-type-convert-util.h" #include "../core/slang-type-text-util.h" // Artifact @@ -24,6 +26,7 @@ #include "slang-check.h" #include "slang-doc-ast.h" #include "slang-doc-markdown-writer.h" +#include "slang-ir.h" #include "slang-lookup.h" #include "slang-lower-to-ir.h" #include "slang-mangle.h" @@ -160,6 +163,21 @@ void Session::init() { SLANG_ASSERT(BaseTypeInfo::check()); +#if SLANG_ENABLE_IR_BREAK_ALLOC + // Read environment variable for IR debugging + StringBuilder irBreakEnv; + if (SLANG_SUCCEEDED(PlatformUtil::getEnvironmentVariable( + UnownedStringSlice("SLANG_DEBUG_IR_BREAK"), + irBreakEnv))) + { + String envValue = irBreakEnv.produceString(); + if (envValue.getLength()) + { + _slangIRAllocBreak = stringToInt(envValue); + _slangIRPrintStackAtBreak = true; + } + } +#endif _initCodeGenTransitionMap(); -- cgit v1.2.3