【问题标题】:How can I inspect the contents of a static thread_local variable on a heap dump with windbg?如何使用 windbg 检查堆转储上的静态 thread_local 变量的内容?
【发布时间】:2020-12-16 01:03:55
【问题描述】:

给出以下源代码:

namespace EventThreadLocal {

  static thread_local std::unique_ptr<std::vector<EventInfo>> Stack;

  static const EventInfo* Top()
  {
    auto stack = Stack.get();
    if (!stack)
      return nullptr;
    if (stack->empty())
      return nullptr;

    return &(stack->back());
  }
}

如何在堆转储中检查静态 thread_local 变量 Stack 的内容?

我的理解是命令 !tls 显示线程本地存储槽,但是我怎么知道这个变量使用的适当槽索引呢?

【问题讨论】:

    标签: c++ windbg thread-local-storage


    【解决方案1】:

    您不需要知道与 static thread_local 变量关联的 TLS 插槽,调试器已经使用 x 命令解决了这个问题。请参阅下面的示例输出,xStack 解析为 WinDbg 中不同线程的不同地址。

    0:000> x test_exe!Stack
    00000296`a5437410 test_exe!Stack = empty
    0:000>~1s
    0:001> x test_exe!stack
    00000296`a543e230 test_exe!Stack = empty
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-17
      • 1970-01-01
      相关资源
      最近更新 更多