There is a similar question for address sanitizers, but for thread sanitizers, it doesn't work, I have tried to break on __sanitizer_print_stack_trace, which doesn't work either.
How to add breakpoint when thread sanitizer reports data-race?
2.3k views Asked by prehistoricpenguin AtThere are 2 answers
The first time I enabled Thread Sanitizer on my project, Xcode helpfully added a breakpoint for me in the Breakpoint Navigator. But I deleted it when I was done testing. Now I need it again and Xcode didn't create it for me when I enabled Thread Sanitizer again.
Note that I am using Xcode 11.0 here.
To manually re-create this breakpoint, you need to have the Breakpoint Navigator open. Then click the plus button (+) at the bottom-left of the navigator and select Runtime Issue Breakpoint from the pop-up menu. This adds the breakpoint to the navigator, and a window appears.
From the Type drop-down list, select Thread Sanitizer.
There you go! Silly that this option is buried way down there. But I also found it helpful to note that there are more options for different kinds of breakpoints available from that plus button menu than there are from the main Xcode drop-down menu Debug > Breakpoints.
exit
and_exit
. On Linux, also setcatch syscall exit_group
.halt_on_error=1
inTSAN_OPTIONS
to ask thread sanitizer to exit on first error:P.S. When the breakpoint is hit, use GDB
where
command to see how the error is reported. Setting a breakpoint on some kind of__tsan_report_error
that is likely on the stack will probably work even without settinghalt_on_error
.