线程清理器报告数据竞争时如何添加断点?

How to add breakpoint when thread sanitizer reports data-race?

address sanitizers也有类似的问题,但是对于thread sanitizers,它不起作用,我试过在__sanitizer_print_stack_trace上中断,这也不起作用。

  1. 运行 GDB下的程序,在exit_exit上设置断点。在 Linux 上,还设置 catch syscall exit_group.
  2. TSAN_OPTIONS 中设置 halt_on_error=1 以请求线程清理程序 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.
  1. 利润。

P.S。命中断点时,使用GDB where命令查看报错情况。即使不设置 halt_on_error.

,在堆栈上可能存在的某种 __tsan_report_error 上设置断点也可能会起作用

我第一次在我的项目上启用 Thread Sanitizer 时,Xcode 在 Breakpoint Navigator 中为我添加了一个断点。但是当我完成测试时,我删除了它。现在我再次需要它,当我再次启用 Thread Sanitizer 时 Xcode 没有为我创建它。

请注意,我在这里使用 Xcode 11.0。

要手动 re-create 这个断点,您需要打开断点导航器。然后单击导航器 bottom-left 处的加号按钮 (+) 和 select Runtime Issue Breakpoint pop-up 菜单。这会将断点添加到导航器,并出现 window。

来自 Type drop-down 列表,select Thread Sanitizer

给你!愚蠢的是,这个选项被埋在那里。但我还发现,与主 Xcode drop-down 菜单 Debug > Breakpoints[ 相比,加号按钮菜单提供的不同类型的断点选项更多,这一点很有帮助。 =28=].