Skip to content

Commit dca3056

Browse files
author
Harlan Haskins
authored
Merge pull request #28284 from tapthaker/SR-11765-pretty-stack-trace
[FrontEnd] Pretty stack trace indicating running user code
2 parents 6d46eb1 + 15eea66 commit dca3056

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,12 @@ static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation,
13371337
ProcessCmdLine(opts.ImmediateArgv.begin(), opts.ImmediateArgv.end());
13381338
Instance.setSILModule(std::move(SM));
13391339

1340+
1341+
PrettyStackTraceStringAction trace(
1342+
"running user code",
1343+
MSF.is<SourceFile *>() ? MSF.get<SourceFile *>()->getFilename()
1344+
: MSF.get<ModuleDecl *>()->getModuleFilename());
1345+
13401346
ReturnValue =
13411347
RunImmediately(Instance, CmdLine, IRGenOpts, Invocation.getSILOptions());
13421348
return Instance.getASTContext().hadError();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
// RUN: echo %s > %t.filelist.txt
3+
// RUN: not --crash %target-swift-frontend -interpret -filelist %t.filelist.txt 2>&1 | %FileCheck %s
4+
5+
// CHECK: Stack dump:
6+
// CHECK-NEXT: Program arguments:
7+
// CHECK-NEXT: Swift version
8+
// CHECK-NEXT: Contents of {{.*}}.filelist.txt:
9+
// CHECK-NEXT: ---
10+
// CHECK-NEXT: crash-in-user-code.swift
11+
// CHECK-NEXT: ---
12+
// CHECK-NEXT: While running user code "{{.*}}crash-in-user-code.swift"
13+
14+
let x: Int? = nil
15+
x!

0 commit comments

Comments
 (0)