首页 > 解决方案 > Address Sanitizer:查找导致崩溃的线程

问题描述

我正在编写一个崩溃的多线程程序。从下面的 AddressSanitizer 输出中可以看到,AddressSanitizer 将线程 ID 打印为T16777215与输出不匹配pthread_self()或不匹配的线程 ID gettid()。知道是什么T16777215吗?

==6363== ERROR: AddressSanitizer: heap-use-after-free on address 0x600800021c98 
at pc 0x7f79415f2b95 bp 0x7f79465d66e0 sp 0x7f79465d5e88 
WRITE of size 8 at 0x600800021c98 thread T16777215

#0 0x7f79415f2b94 (/usr/lib64/libasan.so.0.0.0+0xeb94)

谢谢您的帮助

标签: address-sanitizer

解决方案


Asan 的线程 id 就是线程的序列号:

u32 ThreadRegistry::CreateThread(uptr user_id, bool detached, u32 parent_tid,
                                 void *arg) {
  ...
  } else if (n_contexts_ < max_threads_) {
    // Allocate new thread context and tid.
    tid = n_contexts_++;

(完整代码见这里)。


推荐阅读