From 590f3d702b833f8065f4f9c282a96a899acdec90 Mon Sep 17 00:00:00 2001 From: Carl Peto Date: Mon, 15 Dec 2025 15:09:13 +0000 Subject: [PATCH] [Backtracing] Fix threads=all in SWIFT_BACKTRACE parameters. If you added threads=all to the SWIFT_BACKTRACE settings, it actually prevented all threads from being shown. This fixes that. Also, the multiple thread test should test for presence of multiple threads. rdar://166532079 --- stdlib/public/runtime/Backtrace.cpp | 4 +- test/Backtracing/CrashWithThreads.swift | 50 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/stdlib/public/runtime/Backtrace.cpp b/stdlib/public/runtime/Backtrace.cpp index 595fbddb63330..079bd3f0f9d25 100644 --- a/stdlib/public/runtime/Backtrace.cpp +++ b/stdlib/public/runtime/Backtrace.cpp @@ -1176,10 +1176,10 @@ _swift_spawnBacktracer(CrashInfo *crashInfo) backtracer_argv[16] = "preset"; break; case ThreadsToShow::All: - backtracer_argv[16] = "all"; + backtracer_argv[16] = "true"; break; case ThreadsToShow::Crashed: - backtracer_argv[16] = "crashed"; + backtracer_argv[16] = "false"; break; } diff --git a/test/Backtracing/CrashWithThreads.swift b/test/Backtracing/CrashWithThreads.swift index 8073f5758c6f7..b3db3f2ca9cb0 100644 --- a/test/Backtracing/CrashWithThreads.swift +++ b/test/Backtracing/CrashWithThreads.swift @@ -2,6 +2,7 @@ // RUN: %target-build-swift %s -Onone -g -o %t/CrashWithThreads // RUN: %target-codesign %t/CrashWithThreads // RUN: (env SWIFT_BACKTRACE=enable=yes,cache=no,swift-backtrace=%backtracer %target-run %t/CrashWithThreads 2>&1 || true) | %FileCheck -vv %s -dump-input-filter=all +// RUN: (env SWIFT_BACKTRACE=enable=yes,cache=no,swift-backtrace=%backtracer,threads=all %target-run %t/CrashWithThreads 2>&1 || true) | %FileCheck -vv %s -dump-input-filter=all --check-prefix WITHTHREADSOPT // UNSUPPORTED: use_os_stdlib // UNSUPPORTED: back_deployment_runtime @@ -80,8 +81,57 @@ while (true) { // CHECK-NEXT: 2 [ra] 0x{{[0-9a-f]+}} closure #{{[0-9]}} in spawnThread(_:) + {{[0-9]+}} in CrashWithThreads at {{.*}}/CrashWithThreads // CHECK-NEXT: 3 [ra] [thunk] 0x{{[0-9a-f]+}} @objc closure #{{[0-9]}} in spawnThread(_:) + {{[0-9]+}} in CrashWithThreads at {{.*}} +// CHECK: Thread 0{{( ".*")?}}: + +// CHECK: 0 0x{{[0-9a-f]+}} __semwait_signal + {{[0-9]+}} in libsystem_kernel.dylib +// CHECK-NEXT: 1 [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in CrashWithThreads at {{.*}}/CrashWithThreads +// CHECK-NEXT: 2 [ra] [system] 0x{{[0-9a-f]+}} start + {{[0-9]+}} in dyld + +// CHECK: Thread {{[1-9][0-9]*( ".*")?}}: + +// CHECK: 0 0x{{[0-9a-f]+}} __semwait_signal + {{[0-9]+}} in libsystem_kernel.dylib +// CHECK-NEXT: 1 [ra] 0x{{[0-9a-f]+}} closure #{{[0-9]*}} in spawnThread(_:) + {{[0-9]+}} in CrashWithThreads at {{.*}}/CrashWithThreads +// CHECK-NEXT: 2 [ra] [thunk] 0x{{[0-9a-f]+}} @objc closure #{{[0-9]*}} in spawnThread(_:) + {{[0-9]+}} in CrashWithThreads at / +// CHECK-NEXT: 3 [ra] 0x{{[0-9a-f]+}} _pthread_start + {{[0-9]+}} in libsystem_pthread.dylib + + // CHECK: Registers: // CHECK: Images ({{[0-9]+}} omitted): // CHECK: {{0x[0-9a-f]+}}–{{0x[0-9a-f]+}}{{ +}}{{([0-9a-f]+|)}}{{ +}}CrashWithThreads{{ +}}{{.*}}/CrashWithThreads + +// WITHTHREADSOPT: *** Program crashed: Bad pointer dereference at 0x{{0+}}4 *** + +// make sure there are no threads before the crashing thread (rdar://164566321) + +// we expect the first thread not to be thread 0, it should be the crashing thread instead +// WITHTHREADSOPT-NOT: Thread 0{{( ".*")?}}: + +// we expect a crash on a thread other than 0 +// WITHTHREADSOPT: Thread {{[1-9][0-9]*}} {{(".*" )?}}crashed: + +// WITHTHREADSOPT: 0 0x{{[0-9a-f]+}} reallyCrashMe() + {{[0-9]+}} in CrashWithThreads at {{.*}}/CrashWithThreads +// WITHTHREADSOPT-NEXT: 1 [ra] 0x{{[0-9a-f]+}} crashMe() + {{[0-9]+}} in CrashWithThreads at {{.*}}/CrashWithThreads +// WITHTHREADSOPT-NEXT: 2 [ra] 0x{{[0-9a-f]+}} closure #{{[0-9]}} in spawnThread(_:) + {{[0-9]+}} in CrashWithThreads at {{.*}}/CrashWithThreads +// WITHTHREADSOPT-NEXT: 3 [ra] [thunk] 0x{{[0-9a-f]+}} @objc closure #{{[0-9]}} in spawnThread(_:) + {{[0-9]+}} in CrashWithThreads at {{.*}} + +// WITHTHREADSOPT: Thread 0{{( ".*")?}}: + +// WITHTHREADSOPT: 0 0x{{[0-9a-f]+}} __semwait_signal + {{[0-9]+}} in libsystem_kernel.dylib +// WITHTHREADSOPT-NEXT: 1 [ra] 0x{{[0-9a-f]+}} main + {{[0-9]+}} in CrashWithThreads at {{.*}}/CrashWithThreads +// WITHTHREADSOPT-NEXT: 2 [ra] [system] 0x{{[0-9a-f]+}} start + {{[0-9]+}} in dyld + +// WITHTHREADSOPT: Thread {{[1-9][0-9]*( ".*")?}}: + +// WITHTHREADSOPT: 0 0x{{[0-9a-f]+}} __semwait_signal + {{[0-9]+}} in libsystem_kernel.dylib +// WITHTHREADSOPT-NEXT: 1 [ra] 0x{{[0-9a-f]+}} closure #{{[0-9]*}} in spawnThread(_:) + {{[0-9]+}} in CrashWithThreads at {{.*}}/CrashWithThreads +// WITHTHREADSOPT-NEXT: 2 [ra] [thunk] 0x{{[0-9a-f]+}} @objc closure #{{[0-9]*}} in spawnThread(_:) + {{[0-9]+}} in CrashWithThreads at / +// WITHTHREADSOPT-NEXT: 3 [ra] 0x{{[0-9a-f]+}} _pthread_start + {{[0-9]+}} in libsystem_pthread.dylib + +// WITHTHREADSOPT: Registers: + +// WITHTHREADSOPT: Images ({{[0-9]+}} omitted): + +// WITHTHREADSOPT: {{0x[0-9a-f]+}}–{{0x[0-9a-f]+}}{{ +}}{{([0-9a-f]+|)}}{{ +}}CrashWithThreads{{ +}}{{.*}}/CrashWithThreads +