Skip to content

Commit f448788

Browse files
authored
Add PrettyStackTraceSwiftVersion, and use it in the swiftc executable (#24235)
As pointed out on a recent JIRA, crash traces don't mention what version of Swift you were running. Usually that can be gleaned from the path, but not always.
1 parent b707e7a commit f448788

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

include/swift/Basic/PrettyStackTrace.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class PrettyStackTraceFileContents : public llvm::PrettyStackTraceEntry {
4444
void print(llvm::raw_ostream &OS) const override;
4545
};
4646

47+
/// A PrettyStackTraceEntry to print the version of the compiler.
48+
class PrettyStackTraceSwiftVersion : public llvm::PrettyStackTraceEntry {
49+
public:
50+
void print(llvm::raw_ostream &OS) const override;
51+
};
52+
4753
} // end namespace swift
4854

4955
#endif // SWIFT_BASIC_PRETTYSTACKTRACE_H

lib/Basic/PrettyStackTrace.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "swift/Basic/PrettyStackTrace.h"
1919
#include "swift/Basic/QuotedString.h"
20+
#include "swift/Basic/Version.h"
2021
#include "llvm/Support/MemoryBuffer.h"
2122
#include "llvm/Support/raw_ostream.h"
2223

@@ -33,3 +34,7 @@ void PrettyStackTraceFileContents::print(llvm::raw_ostream &out) const {
3334
out << '\n';
3435
out << "---\n";
3536
}
37+
38+
void PrettyStackTraceSwiftVersion::print(llvm::raw_ostream &out) const {
39+
out << version::getSwiftFullVersion() << '\n';
40+
}

test/Frontend/crash.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Check that we see the contents of the input file list in the crash log.
55
// CHECK-LABEL: Stack dump
66
// CHECK-NEXT: Program arguments: {{.*swift(c?)(.EXE)?}} -frontend
7+
// CHECK-NEXT: Swift version
78
// CHECK-NEXT: Contents of {{.*}}.filelist.txt:
89
// CHECK-NEXT: ---
910
// CHECK-NEXT: test{{[\\/]}}Frontend{{[\\/]}}crash.swift{{$}}

tools/driver/driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "swift/AST/DiagnosticEngine.h"
1818
#include "swift/Basic/LLVMInitialize.h"
19+
#include "swift/Basic/PrettyStackTrace.h"
1920
#include "swift/Basic/Program.h"
2021
#include "swift/Basic/TaskQueue.h"
2122
#include "swift/Basic/SourceManager.h"
@@ -224,6 +225,8 @@ int main(int argc_, const char **argv_) {
224225
PROGRAM_START(ThrowawayExpandedArgc, ThrowawayExpandedArgv);
225226
ArrayRef<const char *> argv(ExpandedArgs);
226227

228+
PrettyStackTraceSwiftVersion versionStackTrace;
229+
227230
// Check if this invocation should execute a subcommand.
228231
StringRef ExecName = llvm::sys::path::stem(argv[0]);
229232
SmallString<256> SubcommandName;

0 commit comments

Comments
 (0)