How can I inspect the contents of a static thread_local variable on a heap dump with windbg?

Viewed 232

Given the following source code:

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());
  }
}

How can I inspect the contents of the static thread_local variable Stack on a heap dump?

My understanding is that the command !tls displays the thread local storage slots, but how can I know the appropriate slot index used by this variable?

1 Answers

You don't need know the TLS slot associated the the static thread_local variable, the debugger already resolves that with x command. See below sample output that x resolves Stack to different addresses for different threads in 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
Related