问题
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 don't work either.
回答1:
- Run the program under GDB, set breakpoints on
exit
and_exit
. On Linux, also setcatch syscall exit_group
. - set
halt_on_error=1
inTSAN_OPTIONS
to ask thread sanitizer to exit on first error:
(gdb) set env TSAN_OPTIONS=halt_on_error=1
(gdb) run
... error should be reported and one of the breakpoints should fire.
- Profit.
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 setting halt_on_error
.
来源:https://stackoverflow.com/questions/63964739/how-to-add-breakpoint-when-thread-sanitizer-repoorts-data-race