[PATCH] D29103: [tsan] Properly describe GCD worker threads in reports
Kuba (Brecka) Mracek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 24 16:46:55 PST 2017
kubamracek created this revision.
kubamracek added a project: Sanitizers.
When dealing with GCD worker threads, TSan currently prints weird things like "created by thread T-1" and "[failed to restore the stack]" in reports:
==================
WARNING: ThreadSanitizer: data race (pid=18771)
Write of size 8 at 0x00010ac221a0 by thread T3:
...
Previous write of size 8 at 0x00010ac221a0 by thread T1:
...
Location is global 'global' at 0x00010ac221a0 (workerthreads.mm.tmp+0x0001000021a0)
Thread T3 (tid=5981759, running) created by thread T-1
[failed to restore the stack]
Thread T1 (tid=5981757, running) created by thread T-1
[failed to restore the stack]
SUMMARY: ThreadSanitizer: data race workerthreads.mm:23 in __main_block_invoke_2
==================
This patch tries to avoid that and instead print:
==================
WARNING: ThreadSanitizer: data race (pid=18843)
Write of size 8 at 0x0001044431a0 by thread T3:
...
Previous write of size 8 at 0x0001044431a0 by thread T1:
...
Location is global 'global' at 0x0001044431a0 (workerthreads.mm.tmp+0x0001000021a0)
Thread T3 (tid=5989400, running) is a GCD worker thread
Thread T1 (tid=5989398, running) is a GCD worker thread
SUMMARY: ThreadSanitizer: data race workerthreads.mm:23 in __main_block_invoke_2
==================
Repository:
rL LLVM
https://reviews.llvm.org/D29103
Files:
lib/tsan/rtl/tsan_report.cc
lib/tsan/rtl/tsan_report.h
test/tsan/Darwin/workerthreads.mm
Index: test/tsan/Darwin/workerthreads.mm
===================================================================
--- test/tsan/Darwin/workerthreads.mm
+++ test/tsan/Darwin/workerthreads.mm
@@ -0,0 +1,43 @@
+// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %deflake %run %t 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+
+#import "../test.h"
+
+long global;
+
+int main() {
+ fprintf(stderr, "Hello world.\n");
+ print_address("addr=", 1, &global);
+ barrier_init(&barrier, 2);
+
+ global = 42;
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ global = 43;
+ barrier_wait(&barrier);
+ });
+
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ barrier_wait(&barrier);
+ global = 44;
+
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ CFRunLoopStop(CFRunLoopGetCurrent());
+ });
+ });
+
+ CFRunLoopRun();
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 8
+// CHECK: Previous write of size 8
+// CHECK: Location is global
+// CHECK: Thread {{.*}} is a GCD worker thread
+// CHECK-NOT: failed to restore the stack
+// CHECK: Thread {{.*}} is a GCD worker thread
+// CHECK-NOT: failed to restore the stack
+// CHECK: Done.
Index: lib/tsan/rtl/tsan_report.h
===================================================================
--- lib/tsan/rtl/tsan_report.h
+++ lib/tsan/rtl/tsan_report.h
@@ -90,7 +90,7 @@
uptr os_id;
bool running;
char *name;
- int parent_tid;
+ u32 parent_tid;
ReportStack *stack;
};
Index: lib/tsan/rtl/tsan_report.cc
===================================================================
--- lib/tsan/rtl/tsan_report.cc
+++ lib/tsan/rtl/tsan_report.cc
@@ -235,9 +235,15 @@
if (rt->name && rt->name[0] != '\0')
Printf(" '%s'", rt->name);
char thrbuf[kThreadBufSize];
- Printf(" (tid=%zu, %s) created by %s",
- rt->os_id, rt->running ? "running" : "finished",
- thread_name(thrbuf, rt->parent_tid));
+ const char *thread_status = rt->running ? "running" : "finished";
+ if (rt->parent_tid == kInvalidTid) {
+ Printf(" (tid=%zu, %s) is a GCD worker thread\n", rt->os_id, thread_status);
+ Printf("\n");
+ Printf("%s", d.EndThreadDescription());
+ return;
+ }
+ Printf(" (tid=%zu, %s) created by %s", rt->os_id, thread_status,
+ thread_name(thrbuf, rt->parent_tid));
if (rt->stack)
Printf(" at:");
Printf("\n");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29103.85655.patch
Type: text/x-patch
Size: 2492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170125/ee0cd831/attachment.bin>
More information about the llvm-commits
mailing list