15ffd83dbSDimitry Andric //===-- ThreadGDBRemote.cpp -----------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "ThreadGDBRemote.h"
100b57cec5SDimitry Andric 
110b57cec5SDimitry Andric #include "lldb/Breakpoint/Watchpoint.h"
120b57cec5SDimitry Andric #include "lldb/Target/Platform.h"
130b57cec5SDimitry Andric #include "lldb/Target/Process.h"
140b57cec5SDimitry Andric #include "lldb/Target/RegisterContext.h"
150b57cec5SDimitry Andric #include "lldb/Target/StopInfo.h"
160b57cec5SDimitry Andric #include "lldb/Target/SystemRuntime.h"
170b57cec5SDimitry Andric #include "lldb/Target/Target.h"
180b57cec5SDimitry Andric #include "lldb/Target/UnixSignals.h"
190b57cec5SDimitry Andric #include "lldb/Target/Unwind.h"
200b57cec5SDimitry Andric #include "lldb/Utility/DataExtractor.h"
210b57cec5SDimitry Andric #include "lldb/Utility/State.h"
220b57cec5SDimitry Andric #include "lldb/Utility/StreamString.h"
230b57cec5SDimitry Andric #include "lldb/Utility/StringExtractorGDBRemote.h"
240b57cec5SDimitry Andric 
250b57cec5SDimitry Andric #include "ProcessGDBRemote.h"
260b57cec5SDimitry Andric #include "ProcessGDBRemoteLog.h"
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric #include <memory>
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric using namespace lldb;
310b57cec5SDimitry Andric using namespace lldb_private;
320b57cec5SDimitry Andric using namespace lldb_private::process_gdb_remote;
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric // Thread Registers
350b57cec5SDimitry Andric 
ThreadGDBRemote(Process & process,lldb::tid_t tid)360b57cec5SDimitry Andric ThreadGDBRemote::ThreadGDBRemote(Process &process, lldb::tid_t tid)
370b57cec5SDimitry Andric     : Thread(process, tid), m_thread_name(), m_dispatch_queue_name(),
380b57cec5SDimitry Andric       m_thread_dispatch_qaddr(LLDB_INVALID_ADDRESS),
390b57cec5SDimitry Andric       m_dispatch_queue_t(LLDB_INVALID_ADDRESS), m_queue_kind(eQueueKindUnknown),
400b57cec5SDimitry Andric       m_queue_serial_number(LLDB_INVALID_QUEUE_ID),
410b57cec5SDimitry Andric       m_associated_with_libdispatch_queue(eLazyBoolCalculate) {
4204eeddc0SDimitry Andric   Log *log = GetLog(GDBRLog::Thread);
430b57cec5SDimitry Andric   LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this, process.GetID(),
440b57cec5SDimitry Andric            GetID());
45e8d8bef9SDimitry Andric   // At this point we can clone reg_info for architectures supporting
46e8d8bef9SDimitry Andric   // run-time update to register sizes and offsets..
47e8d8bef9SDimitry Andric   auto &gdb_process = static_cast<ProcessGDBRemote &>(process);
48e8d8bef9SDimitry Andric   if (!gdb_process.m_register_info_sp->IsReconfigurable())
49e8d8bef9SDimitry Andric     m_reg_info_sp = gdb_process.m_register_info_sp;
50e8d8bef9SDimitry Andric   else
51e8d8bef9SDimitry Andric     m_reg_info_sp = std::make_shared<GDBRemoteDynamicRegisterInfo>(
52e8d8bef9SDimitry Andric         *gdb_process.m_register_info_sp);
530b57cec5SDimitry Andric }
540b57cec5SDimitry Andric 
~ThreadGDBRemote()550b57cec5SDimitry Andric ThreadGDBRemote::~ThreadGDBRemote() {
560b57cec5SDimitry Andric   ProcessSP process_sp(GetProcess());
5704eeddc0SDimitry Andric   Log *log = GetLog(GDBRLog::Thread);
580b57cec5SDimitry Andric   LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this,
590b57cec5SDimitry Andric            process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID, GetID());
600b57cec5SDimitry Andric   DestroyThread();
610b57cec5SDimitry Andric }
620b57cec5SDimitry Andric 
GetName()630b57cec5SDimitry Andric const char *ThreadGDBRemote::GetName() {
640b57cec5SDimitry Andric   if (m_thread_name.empty())
650b57cec5SDimitry Andric     return nullptr;
660b57cec5SDimitry Andric   return m_thread_name.c_str();
670b57cec5SDimitry Andric }
680b57cec5SDimitry Andric 
ClearQueueInfo()690b57cec5SDimitry Andric void ThreadGDBRemote::ClearQueueInfo() {
700b57cec5SDimitry Andric   m_dispatch_queue_name.clear();
710b57cec5SDimitry Andric   m_queue_kind = eQueueKindUnknown;
720b57cec5SDimitry Andric   m_queue_serial_number = 0;
730b57cec5SDimitry Andric   m_dispatch_queue_t = LLDB_INVALID_ADDRESS;
740b57cec5SDimitry Andric   m_associated_with_libdispatch_queue = eLazyBoolCalculate;
750b57cec5SDimitry Andric }
760b57cec5SDimitry Andric 
SetQueueInfo(std::string && queue_name,QueueKind queue_kind,uint64_t queue_serial,addr_t dispatch_queue_t,LazyBool associated_with_libdispatch_queue)770b57cec5SDimitry Andric void ThreadGDBRemote::SetQueueInfo(std::string &&queue_name,
780b57cec5SDimitry Andric                                    QueueKind queue_kind, uint64_t queue_serial,
790b57cec5SDimitry Andric                                    addr_t dispatch_queue_t,
800b57cec5SDimitry Andric                                    LazyBool associated_with_libdispatch_queue) {
810b57cec5SDimitry Andric   m_dispatch_queue_name = queue_name;
820b57cec5SDimitry Andric   m_queue_kind = queue_kind;
830b57cec5SDimitry Andric   m_queue_serial_number = queue_serial;
840b57cec5SDimitry Andric   m_dispatch_queue_t = dispatch_queue_t;
850b57cec5SDimitry Andric   m_associated_with_libdispatch_queue = associated_with_libdispatch_queue;
860b57cec5SDimitry Andric }
870b57cec5SDimitry Andric 
GetQueueName()880b57cec5SDimitry Andric const char *ThreadGDBRemote::GetQueueName() {
890b57cec5SDimitry Andric   // If our cached queue info is valid, then someone called
900b57cec5SDimitry Andric   // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
910b57cec5SDimitry Andric   // from the stop reply packet. In this case we trust that the info is valid
920b57cec5SDimitry Andric   // in m_dispatch_queue_name without refetching it
930b57cec5SDimitry Andric   if (CachedQueueInfoIsValid()) {
940b57cec5SDimitry Andric     if (m_dispatch_queue_name.empty())
950b57cec5SDimitry Andric       return nullptr;
960b57cec5SDimitry Andric     else
970b57cec5SDimitry Andric       return m_dispatch_queue_name.c_str();
980b57cec5SDimitry Andric   }
990b57cec5SDimitry Andric   // Always re-fetch the dispatch queue name since it can change
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   if (m_associated_with_libdispatch_queue == eLazyBoolNo)
1020b57cec5SDimitry Andric     return nullptr;
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric   if (m_thread_dispatch_qaddr != 0 &&
1050b57cec5SDimitry Andric       m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) {
1060b57cec5SDimitry Andric     ProcessSP process_sp(GetProcess());
1070b57cec5SDimitry Andric     if (process_sp) {
1080b57cec5SDimitry Andric       SystemRuntime *runtime = process_sp->GetSystemRuntime();
1090b57cec5SDimitry Andric       if (runtime)
1100b57cec5SDimitry Andric         m_dispatch_queue_name =
1110b57cec5SDimitry Andric             runtime->GetQueueNameFromThreadQAddress(m_thread_dispatch_qaddr);
1120b57cec5SDimitry Andric       else
1130b57cec5SDimitry Andric         m_dispatch_queue_name.clear();
1140b57cec5SDimitry Andric 
1150b57cec5SDimitry Andric       if (!m_dispatch_queue_name.empty())
1160b57cec5SDimitry Andric         return m_dispatch_queue_name.c_str();
1170b57cec5SDimitry Andric     }
1180b57cec5SDimitry Andric   }
1190b57cec5SDimitry Andric   return nullptr;
1200b57cec5SDimitry Andric }
1210b57cec5SDimitry Andric 
GetQueueKind()1220b57cec5SDimitry Andric QueueKind ThreadGDBRemote::GetQueueKind() {
1230b57cec5SDimitry Andric   // If our cached queue info is valid, then someone called
1240b57cec5SDimitry Andric   // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
1250b57cec5SDimitry Andric   // from the stop reply packet. In this case we trust that the info is valid
1260b57cec5SDimitry Andric   // in m_dispatch_queue_name without refetching it
1270b57cec5SDimitry Andric   if (CachedQueueInfoIsValid()) {
1280b57cec5SDimitry Andric     return m_queue_kind;
1290b57cec5SDimitry Andric   }
1300b57cec5SDimitry Andric 
1310b57cec5SDimitry Andric   if (m_associated_with_libdispatch_queue == eLazyBoolNo)
1320b57cec5SDimitry Andric     return eQueueKindUnknown;
1330b57cec5SDimitry Andric 
1340b57cec5SDimitry Andric   if (m_thread_dispatch_qaddr != 0 &&
1350b57cec5SDimitry Andric       m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) {
1360b57cec5SDimitry Andric     ProcessSP process_sp(GetProcess());
1370b57cec5SDimitry Andric     if (process_sp) {
1380b57cec5SDimitry Andric       SystemRuntime *runtime = process_sp->GetSystemRuntime();
1390b57cec5SDimitry Andric       if (runtime)
1400b57cec5SDimitry Andric         m_queue_kind = runtime->GetQueueKind(m_thread_dispatch_qaddr);
1410b57cec5SDimitry Andric       return m_queue_kind;
1420b57cec5SDimitry Andric     }
1430b57cec5SDimitry Andric   }
1440b57cec5SDimitry Andric   return eQueueKindUnknown;
1450b57cec5SDimitry Andric }
1460b57cec5SDimitry Andric 
GetQueueID()1470b57cec5SDimitry Andric queue_id_t ThreadGDBRemote::GetQueueID() {
1480b57cec5SDimitry Andric   // If our cached queue info is valid, then someone called
1490b57cec5SDimitry Andric   // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
1500b57cec5SDimitry Andric   // from the stop reply packet. In this case we trust that the info is valid
1510b57cec5SDimitry Andric   // in m_dispatch_queue_name without refetching it
1520b57cec5SDimitry Andric   if (CachedQueueInfoIsValid())
1530b57cec5SDimitry Andric     return m_queue_serial_number;
1540b57cec5SDimitry Andric 
1550b57cec5SDimitry Andric   if (m_associated_with_libdispatch_queue == eLazyBoolNo)
1560b57cec5SDimitry Andric     return LLDB_INVALID_QUEUE_ID;
1570b57cec5SDimitry Andric 
1580b57cec5SDimitry Andric   if (m_thread_dispatch_qaddr != 0 &&
1590b57cec5SDimitry Andric       m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) {
1600b57cec5SDimitry Andric     ProcessSP process_sp(GetProcess());
1610b57cec5SDimitry Andric     if (process_sp) {
1620b57cec5SDimitry Andric       SystemRuntime *runtime = process_sp->GetSystemRuntime();
1630b57cec5SDimitry Andric       if (runtime) {
1640b57cec5SDimitry Andric         return runtime->GetQueueIDFromThreadQAddress(m_thread_dispatch_qaddr);
1650b57cec5SDimitry Andric       }
1660b57cec5SDimitry Andric     }
1670b57cec5SDimitry Andric   }
1680b57cec5SDimitry Andric   return LLDB_INVALID_QUEUE_ID;
1690b57cec5SDimitry Andric }
1700b57cec5SDimitry Andric 
GetQueue()1710b57cec5SDimitry Andric QueueSP ThreadGDBRemote::GetQueue() {
1720b57cec5SDimitry Andric   queue_id_t queue_id = GetQueueID();
1730b57cec5SDimitry Andric   QueueSP queue;
1740b57cec5SDimitry Andric   if (queue_id != LLDB_INVALID_QUEUE_ID) {
1750b57cec5SDimitry Andric     ProcessSP process_sp(GetProcess());
1760b57cec5SDimitry Andric     if (process_sp) {
1770b57cec5SDimitry Andric       queue = process_sp->GetQueueList().FindQueueByID(queue_id);
1780b57cec5SDimitry Andric     }
1790b57cec5SDimitry Andric   }
1800b57cec5SDimitry Andric   return queue;
1810b57cec5SDimitry Andric }
1820b57cec5SDimitry Andric 
GetQueueLibdispatchQueueAddress()1830b57cec5SDimitry Andric addr_t ThreadGDBRemote::GetQueueLibdispatchQueueAddress() {
1840b57cec5SDimitry Andric   if (m_dispatch_queue_t == LLDB_INVALID_ADDRESS) {
1850b57cec5SDimitry Andric     if (m_thread_dispatch_qaddr != 0 &&
1860b57cec5SDimitry Andric         m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) {
1870b57cec5SDimitry Andric       ProcessSP process_sp(GetProcess());
1880b57cec5SDimitry Andric       if (process_sp) {
1890b57cec5SDimitry Andric         SystemRuntime *runtime = process_sp->GetSystemRuntime();
1900b57cec5SDimitry Andric         if (runtime) {
1910b57cec5SDimitry Andric           m_dispatch_queue_t =
1920b57cec5SDimitry Andric               runtime->GetLibdispatchQueueAddressFromThreadQAddress(
1930b57cec5SDimitry Andric                   m_thread_dispatch_qaddr);
1940b57cec5SDimitry Andric         }
1950b57cec5SDimitry Andric       }
1960b57cec5SDimitry Andric     }
1970b57cec5SDimitry Andric   }
1980b57cec5SDimitry Andric   return m_dispatch_queue_t;
1990b57cec5SDimitry Andric }
2000b57cec5SDimitry Andric 
SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t)2010b57cec5SDimitry Andric void ThreadGDBRemote::SetQueueLibdispatchQueueAddress(
2020b57cec5SDimitry Andric     lldb::addr_t dispatch_queue_t) {
2030b57cec5SDimitry Andric   m_dispatch_queue_t = dispatch_queue_t;
2040b57cec5SDimitry Andric }
2050b57cec5SDimitry Andric 
ThreadHasQueueInformation() const2060b57cec5SDimitry Andric bool ThreadGDBRemote::ThreadHasQueueInformation() const {
2070b57cec5SDimitry Andric   return m_thread_dispatch_qaddr != 0 &&
2080b57cec5SDimitry Andric          m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS &&
2090b57cec5SDimitry Andric          m_dispatch_queue_t != LLDB_INVALID_ADDRESS &&
2100b57cec5SDimitry Andric          m_queue_kind != eQueueKindUnknown && m_queue_serial_number != 0;
2110b57cec5SDimitry Andric }
2120b57cec5SDimitry Andric 
GetAssociatedWithLibdispatchQueue()2130b57cec5SDimitry Andric LazyBool ThreadGDBRemote::GetAssociatedWithLibdispatchQueue() {
2140b57cec5SDimitry Andric   return m_associated_with_libdispatch_queue;
2150b57cec5SDimitry Andric }
2160b57cec5SDimitry Andric 
SetAssociatedWithLibdispatchQueue(LazyBool associated_with_libdispatch_queue)2170b57cec5SDimitry Andric void ThreadGDBRemote::SetAssociatedWithLibdispatchQueue(
2180b57cec5SDimitry Andric     LazyBool associated_with_libdispatch_queue) {
2190b57cec5SDimitry Andric   m_associated_with_libdispatch_queue = associated_with_libdispatch_queue;
2200b57cec5SDimitry Andric }
2210b57cec5SDimitry Andric 
FetchThreadExtendedInfo()2220b57cec5SDimitry Andric StructuredData::ObjectSP ThreadGDBRemote::FetchThreadExtendedInfo() {
2230b57cec5SDimitry Andric   StructuredData::ObjectSP object_sp;
2240b57cec5SDimitry Andric   const lldb::user_id_t tid = GetProtocolID();
22504eeddc0SDimitry Andric   Log *log = GetLog(GDBRLog::Thread);
2269dba64beSDimitry Andric   LLDB_LOGF(log, "Fetching extended information for thread %4.4" PRIx64, tid);
2270b57cec5SDimitry Andric   ProcessSP process_sp(GetProcess());
2280b57cec5SDimitry Andric   if (process_sp) {
2290b57cec5SDimitry Andric     ProcessGDBRemote *gdb_process =
2300b57cec5SDimitry Andric         static_cast<ProcessGDBRemote *>(process_sp.get());
2310b57cec5SDimitry Andric     object_sp = gdb_process->GetExtendedInfoForThread(tid);
2320b57cec5SDimitry Andric   }
2330b57cec5SDimitry Andric   return object_sp;
2340b57cec5SDimitry Andric }
2350b57cec5SDimitry Andric 
WillResume(StateType resume_state)2360b57cec5SDimitry Andric void ThreadGDBRemote::WillResume(StateType resume_state) {
2370b57cec5SDimitry Andric   int signo = GetResumeSignal();
2380b57cec5SDimitry Andric   const lldb::user_id_t tid = GetProtocolID();
23904eeddc0SDimitry Andric   Log *log = GetLog(GDBRLog::Thread);
2409dba64beSDimitry Andric   LLDB_LOGF(log, "Resuming thread: %4.4" PRIx64 " with state: %s.", tid,
2410b57cec5SDimitry Andric             StateAsCString(resume_state));
2420b57cec5SDimitry Andric 
2430b57cec5SDimitry Andric   ProcessSP process_sp(GetProcess());
2440b57cec5SDimitry Andric   if (process_sp) {
2450b57cec5SDimitry Andric     ProcessGDBRemote *gdb_process =
2460b57cec5SDimitry Andric         static_cast<ProcessGDBRemote *>(process_sp.get());
2470b57cec5SDimitry Andric     switch (resume_state) {
2480b57cec5SDimitry Andric     case eStateSuspended:
2490b57cec5SDimitry Andric     case eStateStopped:
2500b57cec5SDimitry Andric       // Don't append anything for threads that should stay stopped.
2510b57cec5SDimitry Andric       break;
2520b57cec5SDimitry Andric 
2530b57cec5SDimitry Andric     case eStateRunning:
2540b57cec5SDimitry Andric       if (gdb_process->GetUnixSignals()->SignalIsValid(signo))
2550b57cec5SDimitry Andric         gdb_process->m_continue_C_tids.push_back(std::make_pair(tid, signo));
2560b57cec5SDimitry Andric       else
2570b57cec5SDimitry Andric         gdb_process->m_continue_c_tids.push_back(tid);
2580b57cec5SDimitry Andric       break;
2590b57cec5SDimitry Andric 
2600b57cec5SDimitry Andric     case eStateStepping:
2610b57cec5SDimitry Andric       if (gdb_process->GetUnixSignals()->SignalIsValid(signo))
2620b57cec5SDimitry Andric         gdb_process->m_continue_S_tids.push_back(std::make_pair(tid, signo));
2630b57cec5SDimitry Andric       else
2640b57cec5SDimitry Andric         gdb_process->m_continue_s_tids.push_back(tid);
2650b57cec5SDimitry Andric       break;
2660b57cec5SDimitry Andric 
2670b57cec5SDimitry Andric     default:
2680b57cec5SDimitry Andric       break;
2690b57cec5SDimitry Andric     }
2700b57cec5SDimitry Andric   }
2710b57cec5SDimitry Andric }
2720b57cec5SDimitry Andric 
RefreshStateAfterStop()2730b57cec5SDimitry Andric void ThreadGDBRemote::RefreshStateAfterStop() {
2740b57cec5SDimitry Andric   // Invalidate all registers in our register context. We don't set "force" to
2750b57cec5SDimitry Andric   // true because the stop reply packet might have had some register values
2760b57cec5SDimitry Andric   // that were expedited and these will already be copied into the register
2770b57cec5SDimitry Andric   // context by the time this function gets called. The
2780b57cec5SDimitry Andric   // GDBRemoteRegisterContext class has been made smart enough to detect when
2790b57cec5SDimitry Andric   // it needs to invalidate which registers are valid by putting hooks in the
2800b57cec5SDimitry Andric   // register read and register supply functions where they check the process
2810b57cec5SDimitry Andric   // stop ID and do the right thing.
2820b57cec5SDimitry Andric   const bool force = false;
2830b57cec5SDimitry Andric   GetRegisterContext()->InvalidateIfNeeded(force);
2840b57cec5SDimitry Andric }
2850b57cec5SDimitry Andric 
ThreadIDIsValid(lldb::tid_t thread)2860b57cec5SDimitry Andric bool ThreadGDBRemote::ThreadIDIsValid(lldb::tid_t thread) {
2870b57cec5SDimitry Andric   return thread != 0;
2880b57cec5SDimitry Andric }
2890b57cec5SDimitry Andric 
Dump(Log * log,uint32_t index)2900b57cec5SDimitry Andric void ThreadGDBRemote::Dump(Log *log, uint32_t index) {}
2910b57cec5SDimitry Andric 
ShouldStop(bool & step_more)2920b57cec5SDimitry Andric bool ThreadGDBRemote::ShouldStop(bool &step_more) { return true; }
GetRegisterContext()2930b57cec5SDimitry Andric lldb::RegisterContextSP ThreadGDBRemote::GetRegisterContext() {
2940b57cec5SDimitry Andric   if (!m_reg_context_sp)
2950b57cec5SDimitry Andric     m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
2960b57cec5SDimitry Andric   return m_reg_context_sp;
2970b57cec5SDimitry Andric }
2980b57cec5SDimitry Andric 
2990b57cec5SDimitry Andric lldb::RegisterContextSP
CreateRegisterContextForFrame(StackFrame * frame)3000b57cec5SDimitry Andric ThreadGDBRemote::CreateRegisterContextForFrame(StackFrame *frame) {
3010b57cec5SDimitry Andric   lldb::RegisterContextSP reg_ctx_sp;
3020b57cec5SDimitry Andric   uint32_t concrete_frame_idx = 0;
3030b57cec5SDimitry Andric 
3040b57cec5SDimitry Andric   if (frame)
3050b57cec5SDimitry Andric     concrete_frame_idx = frame->GetConcreteFrameIndex();
3060b57cec5SDimitry Andric 
3070b57cec5SDimitry Andric   if (concrete_frame_idx == 0) {
3080b57cec5SDimitry Andric     ProcessSP process_sp(GetProcess());
3090b57cec5SDimitry Andric     if (process_sp) {
3100b57cec5SDimitry Andric       ProcessGDBRemote *gdb_process =
3110b57cec5SDimitry Andric           static_cast<ProcessGDBRemote *>(process_sp.get());
312480093f4SDimitry Andric       bool pSupported =
313480093f4SDimitry Andric           gdb_process->GetGDBRemote().GetpPacketSupported(GetID());
3140b57cec5SDimitry Andric       bool read_all_registers_at_once =
315480093f4SDimitry Andric           !pSupported || gdb_process->m_use_g_packet_for_reading;
316480093f4SDimitry Andric       bool write_all_registers_at_once = !pSupported;
3170b57cec5SDimitry Andric       reg_ctx_sp = std::make_shared<GDBRemoteRegisterContext>(
318e8d8bef9SDimitry Andric           *this, concrete_frame_idx, m_reg_info_sp, read_all_registers_at_once,
319e8d8bef9SDimitry Andric           write_all_registers_at_once);
3200b57cec5SDimitry Andric     }
3210b57cec5SDimitry Andric   } else {
3225ffd83dbSDimitry Andric     reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
3230b57cec5SDimitry Andric   }
3240b57cec5SDimitry Andric   return reg_ctx_sp;
3250b57cec5SDimitry Andric }
3260b57cec5SDimitry Andric 
PrivateSetRegisterValue(uint32_t reg,llvm::ArrayRef<uint8_t> data)3270b57cec5SDimitry Andric bool ThreadGDBRemote::PrivateSetRegisterValue(uint32_t reg,
3280b57cec5SDimitry Andric                                               llvm::ArrayRef<uint8_t> data) {
3290b57cec5SDimitry Andric   GDBRemoteRegisterContext *gdb_reg_ctx =
3300b57cec5SDimitry Andric       static_cast<GDBRemoteRegisterContext *>(GetRegisterContext().get());
3310b57cec5SDimitry Andric   assert(gdb_reg_ctx);
3320b57cec5SDimitry Andric   return gdb_reg_ctx->PrivateSetRegisterValue(reg, data);
3330b57cec5SDimitry Andric }
3340b57cec5SDimitry Andric 
PrivateSetRegisterValue(uint32_t reg,uint64_t regval)3350b57cec5SDimitry Andric bool ThreadGDBRemote::PrivateSetRegisterValue(uint32_t reg, uint64_t regval) {
3360b57cec5SDimitry Andric   GDBRemoteRegisterContext *gdb_reg_ctx =
3370b57cec5SDimitry Andric       static_cast<GDBRemoteRegisterContext *>(GetRegisterContext().get());
3380b57cec5SDimitry Andric   assert(gdb_reg_ctx);
3390b57cec5SDimitry Andric   return gdb_reg_ctx->PrivateSetRegisterValue(reg, regval);
3400b57cec5SDimitry Andric }
3410b57cec5SDimitry Andric 
CalculateStopInfo()3420b57cec5SDimitry Andric bool ThreadGDBRemote::CalculateStopInfo() {
3430b57cec5SDimitry Andric   ProcessSP process_sp(GetProcess());
3440b57cec5SDimitry Andric   if (process_sp)
3450b57cec5SDimitry Andric     return static_cast<ProcessGDBRemote *>(process_sp.get())
3460b57cec5SDimitry Andric         ->CalculateThreadStopInfo(this);
3470b57cec5SDimitry Andric   return false;
3480b57cec5SDimitry Andric }
34904eeddc0SDimitry Andric 
35004eeddc0SDimitry Andric llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
GetSiginfo(size_t max_size) const35104eeddc0SDimitry Andric ThreadGDBRemote::GetSiginfo(size_t max_size) const {
35204eeddc0SDimitry Andric   ProcessSP process_sp(GetProcess());
35304eeddc0SDimitry Andric   if (!process_sp)
35404eeddc0SDimitry Andric     return llvm::createStringError(llvm::inconvertibleErrorCode(),
35504eeddc0SDimitry Andric                                    "no process");
35604eeddc0SDimitry Andric   ProcessGDBRemote *gdb_process =
35704eeddc0SDimitry Andric       static_cast<ProcessGDBRemote *>(process_sp.get());
35804eeddc0SDimitry Andric   if (!gdb_process->m_gdb_comm.GetQXferSigInfoReadSupported())
35904eeddc0SDimitry Andric     return llvm::createStringError(llvm::inconvertibleErrorCode(),
36004eeddc0SDimitry Andric                                    "qXfer:siginfo:read not supported");
36104eeddc0SDimitry Andric 
36204eeddc0SDimitry Andric   llvm::Expected<std::string> response =
36304eeddc0SDimitry Andric       gdb_process->m_gdb_comm.ReadExtFeature("siginfo", "");
36404eeddc0SDimitry Andric   if (!response)
36504eeddc0SDimitry Andric     return response.takeError();
36604eeddc0SDimitry Andric 
36704eeddc0SDimitry Andric   return llvm::MemoryBuffer::getMemBufferCopy(response.get());
36804eeddc0SDimitry Andric }
369