From 1b55459da63e53b5dabef481f9d3f8b3bff21933 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Fri, 6 Jun 2025 10:29:08 -0700 Subject: [PATCH] Add filenames to stack traces (#5623) To make it easier to identify crashing files when testing multiple. ``` (elided) 3. Check::Context filename: duplicate_name_same_line.carbon NodeStack: (elided) ``` --- toolchain/check/context.cpp | 3 +++ toolchain/driver/compile_subcommand.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/toolchain/check/context.cpp b/toolchain/check/context.cpp index 7bd093af4185..9d067589db2c 100644 --- a/toolchain/check/context.cpp +++ b/toolchain/check/context.cpp @@ -81,6 +81,9 @@ auto Context::PrintForStackDump(llvm::raw_ostream& output) const -> void { // spaces then add a couple to indent past the Context label. constexpr int Indent = 10; + output.indent(Indent); + output << "filename: " << tokens().source().filename() << "\n"; + node_stack_.PrintForStackDump(Indent, output); inst_block_stack_.PrintForStackDump(Indent, output); pattern_block_stack_.PrintForStackDump(Indent, output); diff --git a/toolchain/driver/compile_subcommand.cpp b/toolchain/driver/compile_subcommand.cpp index af5b14459f05..8e9a1427323e 100644 --- a/toolchain/driver/compile_subcommand.cpp +++ b/toolchain/driver/compile_subcommand.cpp @@ -845,6 +845,9 @@ auto CompilationUnit::GetParseTreeAndSubtrees() auto CompilationUnit::LogCall(llvm::StringLiteral logging_label, llvm::StringLiteral timing_label, llvm::function_refvoid> fn) -> void { + PrettyStackTraceFunction trace_file([&](llvm::raw_ostream& out) { + out << "filename: " << input_filename_ << "\n"; + }); CARBON_VLOG("*** {0}: {1} ***\n", logging_label, input_filename_); Timings::ScopedTiming timing(timings_ ? &*timings_ : nullptr, timing_label); fn();