diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -446,9 +446,7 @@ /// one value in the offsets field. llvm::Optional GetQOffsets(); - bool GetQGetTLSAddr(lldb::tid_t tid, lldb::addr_t offset, lldb::addr_t lms); - - lldb::addr_t GetQGetTLSAddr(lldb::tid_t tid); + lldb::addr_t GetQGetTLSAddr(lldb::tid_t tid, lldb::addr_t offset, lldb::addr_t lms); bool GetModuleInfo(const FileSpec &module_file_spec, const ArchSpec &arch_spec, ModuleSpec &module_spec); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -3759,14 +3759,7 @@ return std::nullopt; } -std::unordered_map tid_to_tp; -lldb::addr_t GDBRemoteCommunicationClient::GetQGetTLSAddr(lldb::tid_t tid) { - if (tid_to_tp.count(tid)) - return tid_to_tp[tid]; - return -1; -} - -bool GDBRemoteCommunicationClient::GetQGetTLSAddr(lldb::tid_t tid, lldb::addr_t offset, lldb::addr_t lm) { +lldb::addr_t GDBRemoteCommunicationClient::GetQGetTLSAddr(lldb::tid_t tid, lldb::addr_t offset, lldb::addr_t lm) { StreamString packet; packet.PutCString("qGetTLSAddr:"); packet.PutHex64(tid, lldb::eByteOrderBig); @@ -3777,18 +3770,15 @@ StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse(packet.GetString(), response) != PacketResult::Success) - return false; + return LLDB_INVALID_ADDRESS; if (response.IsErrorResponse()) - return false; + return LLDB_INVALID_ADDRESS; if (response.IsUnsupportedResponse()) - return false; - llvm::StringRef ref = response.GetStringRef(); - uint64_t addr=-1; - ref.consumeInteger(16, addr); - Log *log(GetLog(GDBRLog::Process | GDBRLog::Packets)); - LLDB_LOG(log, "here is tls addrkamlesh:%s",ref.str().c_str()); - tid_to_tp[tid] = addr;// std::stoull(ref.str()); - return true; + return LLDB_INVALID_ADDRESS; + llvm::StringRef ref = response.GetStringRef(); + uint64_t addr = LLDB_INVALID_ADDRESS; + ref.consumeInteger(16, addr); + return addr; } bool GDBRemoteCommunicationClient::GetModuleInfo( diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -2121,14 +2121,16 @@ return SendErrorResponse(8); llvm::SmallVector argv; s.split(argv, ','); - lldb::tid_t tid = StringExtractor(argv[0]).GetU64(0, 16); - NativeThreadProtocol* ntp= m_current_process->GetThreadByID(tid); + lldb::tid_t tid = StringExtractor(argv[0]).GetU64(LLDB_INVALID_ADDRESS, 16); + lldb::addr_t offset = StringExtractor(argv[1]).GetU64(LLDB_INVALID_ADDRESS, 16); + lldb::addr_t lm = StringExtractor(argv[2]).GetU64(LLDB_INVALID_ADDRESS, 16); + NativeThreadProtocol *ntp = m_current_process->GetThreadByID(tid); NativeRegisterContext ®_ctx = ntp->GetRegisterContext(); lldb::addr_t tls_addr = LLDB_INVALID_ADDRESS; StreamGDBRemote response; if(!reg_ctx.ReadThreadPointer(tls_addr).Fail()) { response.PutHex64(tls_addr, lldb::eByteOrderBig); - return SendPacketNoLock(response.GetString()); + return SendPacketNoLock(response.GetString()); } else return SendErrorResponse(8); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp @@ -89,7 +89,8 @@ GDBRemoteCommunicationClient &gdb_comm( ((ProcessGDBRemote *)process)->GetGDBRemote()); uint64_t tid = thread->GetProtocolID(); - return gdb_comm.GetQGetTLSAddr(tid); + // Return thread pointer here, offset and link_map will be filled by GetThreadLocalData in DYLD + return gdb_comm.GetQGetTLSAddr(tid, LLDB_INVALID_ADDRESS /* offset */, LLDB_INVALID_ADDRESS /* lm */); } bool GDBRemoteRegisterContext::ReadRegister(const RegisterInfo *reg_info, diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1497,10 +1497,6 @@ num_thread_ids = m_thread_ids.size(); } - for(auto& tid: m_thread_ids) { - (void)m_gdb_comm.GetQGetTLSAddr(tid, 0, 0); - } - ThreadList old_thread_list_copy(old_thread_list); if (num_thread_ids > 0) { for (size_t i = 0; i < num_thread_ids; ++i) { diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp --- a/lldb/source/Target/Thread.cpp +++ b/lldb/source/Target/Thread.cpp @@ -1647,7 +1647,6 @@ void Thread::SettingsTerminate() {} lldb::addr_t Thread::GetThreadPointer() { - auto tid = this->GetProtocolID(); RegisterContext *reg_ctx = this->GetRegisterContext().get(); auto tp = reg_ctx->GetThreadPointer(); return tp;