[Lldb-commits] [lldb] [lldb][Windows] Support TLS variables with PDB (PR #229894)

via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 8 11:51:32 PDT 2026


================
@@ -247,3 +247,96 @@ DynamicLoaderWindowsDYLD::GetStepThroughTrampolinePlan(Thread &thread,
   return ThreadPlanSP(new ThreadPlanStepInstruction(
       thread, false, false, eVoteNoOpinion, eVoteNoOpinion));
 }
+
+lldb::addr_t
+DynamicLoaderWindowsDYLD::GetThreadLocalData(const lldb::ModuleSP module,
+                                             lldb::ThreadSP thread,
+                                             lldb::addr_t tls_file_addr) {
+  Log *log = GetLog(LLDBLog::DynamicLoader);
+  std::string object_name;
+  if (log) {
+    ObjectFile *obj = module->GetObjectFile();
+    if (obj)
+      object_name = obj->GetObjectName();
+  }
+
+  StructuredData::ObjectSP extended_info = thread->GetExtendedInfo();
+  if (!extended_info) {
+    LLDB_LOG(log, "missing extended info of thread");
+    return LLDB_INVALID_ADDRESS;
+  }
+  StructuredData::Dictionary *dict = extended_info->GetAsDictionary();
+  if (!dict) {
+    LLDB_LOG(log, "extended info of thread is not a dictionary");
+    return LLDB_INVALID_ADDRESS;
+  }
+  addr_t teb_base = 0;
+  if (!dict->GetValueForKeyAsInteger("teb_address", teb_base) || !teb_base ||
+      teb_base == LLDB_INVALID_ADDRESS) {
+    LLDB_LOG(log, "missing 'teb_address' in extended thread info");
+    return LLDB_INVALID_ADDRESS;
+  }
+
+  ProcessSP process = thread->GetProcess();
+  if (!process) {
+    LLDB_LOG(log, "missing process");
+    return LLDB_INVALID_ADDRESS;
+  }
+  uint32_t addr_byte_size = process->GetAddressByteSize();
+  addr_t tls_array_addr = teb_base + 11 * addr_byte_size;
----------------
Nerixyz wrote:

Our WOW64 support isn't that great (e.g. https://github.com/llvm/llvm-project/issues/58065), especially for the in-process plugin. I think for lldb-server it's a bit better, but I'd rather do this separately.

For the TEB address, we should do that in the `HostThread` and add 0x2000 to it. We don't need the host TEB anyway. Actually, I found that we can also get the host TEB from the create thread event: https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-create_thread_debug_info `lpThreadLocalBase` holds the address. We'd only need to fetch it when attaching.

https://github.com/llvm/llvm-project/pull/229894


More information about the lldb-commits mailing list