[Lldb-commits] [lldb] [lldb][Windows] Support TLS variables with PDB (PR #229894)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 8 03:31:44 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;
+ llvm::Expected<addr_t> tls_array =
+ process->ReadPointerFromMemory(tls_array_addr);
+ if (!tls_array || *tls_array == LLDB_INVALID_ADDRESS) {
+ LLDB_LOG_ERROR(log, tls_array.takeError(),
+ "failed to read TLS array from {1:x16}: {0}",
+ tls_array_addr);
+ return LLDB_INVALID_ADDRESS;
+ }
+
+ Symtab *symtab = module->GetSymtab();
+ if (!symtab) {
+ LLDB_LOG(log, "missing symtab for {0}", object_name);
+ return LLDB_INVALID_ADDRESS;
+ }
+ Symbol *tls_index_sym = symtab->FindFirstSymbolWithNameAndType(
----------------
charles-zablit wrote:
Instead of looking up `_tls_index` by name in the symtab, could we read the module's TLS directory (`IMAGE_DIRECTORY_ENTRY_TLS`) and use `AddressOfIndex`? Every image that uses TLS has one, so it works without public symbols or an embedded COFF symbol table.
That would also remove the need for `-Wl,/debug:symtab` in the test. We could do this in `ObjectFilePECOFF`.
https://github.com/llvm/llvm-project/pull/229894
More information about the lldb-commits
mailing list