1*0b57cec5SDimitry Andric //===-- ThreadGDBRemote.cpp -----------------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric
9*0b57cec5SDimitry Andric #include "ThreadGDBRemote.h"
10*0b57cec5SDimitry Andric
11*0b57cec5SDimitry Andric #include "lldb/Breakpoint/Watchpoint.h"
12*0b57cec5SDimitry Andric #include "lldb/Target/Platform.h"
13*0b57cec5SDimitry Andric #include "lldb/Target/Process.h"
14*0b57cec5SDimitry Andric #include "lldb/Target/RegisterContext.h"
15*0b57cec5SDimitry Andric #include "lldb/Target/StopInfo.h"
16*0b57cec5SDimitry Andric #include "lldb/Target/SystemRuntime.h"
17*0b57cec5SDimitry Andric #include "lldb/Target/Target.h"
18*0b57cec5SDimitry Andric #include "lldb/Target/UnixSignals.h"
19*0b57cec5SDimitry Andric #include "lldb/Target/Unwind.h"
20*0b57cec5SDimitry Andric #include "lldb/Utility/DataExtractor.h"
21*0b57cec5SDimitry Andric #include "lldb/Utility/State.h"
22*0b57cec5SDimitry Andric #include "lldb/Utility/StreamString.h"
23*0b57cec5SDimitry Andric #include "lldb/Utility/StringExtractorGDBRemote.h"
24*0b57cec5SDimitry Andric
25*0b57cec5SDimitry Andric #include "ProcessGDBRemote.h"
26*0b57cec5SDimitry Andric #include "ProcessGDBRemoteLog.h"
27*0b57cec5SDimitry Andric
28*0b57cec5SDimitry Andric #include <memory>
29*0b57cec5SDimitry Andric
30*0b57cec5SDimitry Andric using namespace lldb;
31*0b57cec5SDimitry Andric using namespace lldb_private;
32*0b57cec5SDimitry Andric using namespace lldb_private::process_gdb_remote;
33*0b57cec5SDimitry Andric
34*0b57cec5SDimitry Andric // Thread Registers
35*0b57cec5SDimitry Andric
ThreadGDBRemote(Process & process,lldb::tid_t tid)36*0b57cec5SDimitry Andric ThreadGDBRemote::ThreadGDBRemote(Process &process, lldb::tid_t tid)
37*0b57cec5SDimitry Andric : Thread(process, tid), m_thread_name(), m_dispatch_queue_name(),
38*0b57cec5SDimitry Andric m_thread_dispatch_qaddr(LLDB_INVALID_ADDRESS),
39*0b57cec5SDimitry Andric m_dispatch_queue_t(LLDB_INVALID_ADDRESS), m_queue_kind(eQueueKindUnknown),
40*0b57cec5SDimitry Andric m_queue_serial_number(LLDB_INVALID_QUEUE_ID),
41*0b57cec5SDimitry Andric m_associated_with_libdispatch_queue(eLazyBoolCalculate) {
42*0b57cec5SDimitry Andric Log *log = GetLog(GDBRLog::Thread);
43*0b57cec5SDimitry Andric LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this, process.GetID(),
44*0b57cec5SDimitry Andric GetID());
45*0b57cec5SDimitry Andric // At this point we can clone reg_info for architectures supporting
46*0b57cec5SDimitry Andric // run-time update to register sizes and offsets..
47*0b57cec5SDimitry Andric auto &gdb_process = static_cast<ProcessGDBRemote &>(process);
48*0b57cec5SDimitry Andric if (!gdb_process.m_register_info_sp->IsReconfigurable())
49*0b57cec5SDimitry Andric m_reg_info_sp = gdb_process.m_register_info_sp;
50*0b57cec5SDimitry Andric else
51*0b57cec5SDimitry Andric m_reg_info_sp = std::make_shared<GDBRemoteDynamicRegisterInfo>(
52*0b57cec5SDimitry Andric *gdb_process.m_register_info_sp);
53*0b57cec5SDimitry Andric }
54*0b57cec5SDimitry Andric
~ThreadGDBRemote()55*0b57cec5SDimitry Andric ThreadGDBRemote::~ThreadGDBRemote() {
56*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
57*0b57cec5SDimitry Andric Log *log = GetLog(GDBRLog::Thread);
58*0b57cec5SDimitry Andric LLDB_LOG(log, "this = {0}, pid = {1}, tid = {2}", this,
59*0b57cec5SDimitry Andric process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID, GetID());
60*0b57cec5SDimitry Andric DestroyThread();
61*0b57cec5SDimitry Andric }
62*0b57cec5SDimitry Andric
GetName()63*0b57cec5SDimitry Andric const char *ThreadGDBRemote::GetName() {
64*0b57cec5SDimitry Andric if (m_thread_name.empty())
65*0b57cec5SDimitry Andric return nullptr;
66*0b57cec5SDimitry Andric return m_thread_name.c_str();
67*0b57cec5SDimitry Andric }
68*0b57cec5SDimitry Andric
ClearQueueInfo()69*0b57cec5SDimitry Andric void ThreadGDBRemote::ClearQueueInfo() {
70*0b57cec5SDimitry Andric m_dispatch_queue_name.clear();
71*0b57cec5SDimitry Andric m_queue_kind = eQueueKindUnknown;
72*0b57cec5SDimitry Andric m_queue_serial_number = 0;
73*0b57cec5SDimitry Andric m_dispatch_queue_t = LLDB_INVALID_ADDRESS;
74*0b57cec5SDimitry Andric m_associated_with_libdispatch_queue = eLazyBoolCalculate;
75*0b57cec5SDimitry Andric }
76*0b57cec5SDimitry Andric
SetQueueInfo(std::string && queue_name,QueueKind queue_kind,uint64_t queue_serial,addr_t dispatch_queue_t,LazyBool associated_with_libdispatch_queue)77*0b57cec5SDimitry Andric void ThreadGDBRemote::SetQueueInfo(std::string &&queue_name,
78*0b57cec5SDimitry Andric QueueKind queue_kind, uint64_t queue_serial,
79*0b57cec5SDimitry Andric addr_t dispatch_queue_t,
80*0b57cec5SDimitry Andric LazyBool associated_with_libdispatch_queue) {
81*0b57cec5SDimitry Andric m_dispatch_queue_name = queue_name;
82*0b57cec5SDimitry Andric m_queue_kind = queue_kind;
83*0b57cec5SDimitry Andric m_queue_serial_number = queue_serial;
84*0b57cec5SDimitry Andric m_dispatch_queue_t = dispatch_queue_t;
85*0b57cec5SDimitry Andric m_associated_with_libdispatch_queue = associated_with_libdispatch_queue;
86*0b57cec5SDimitry Andric }
87*0b57cec5SDimitry Andric
GetQueueName()88*0b57cec5SDimitry Andric const char *ThreadGDBRemote::GetQueueName() {
89*0b57cec5SDimitry Andric // If our cached queue info is valid, then someone called
90*0b57cec5SDimitry Andric // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
91*0b57cec5SDimitry Andric // from the stop reply packet. In this case we trust that the info is valid
92*0b57cec5SDimitry Andric // in m_dispatch_queue_name without refetching it
93*0b57cec5SDimitry Andric if (CachedQueueInfoIsValid()) {
94*0b57cec5SDimitry Andric if (m_dispatch_queue_name.empty())
95*0b57cec5SDimitry Andric return nullptr;
96*0b57cec5SDimitry Andric else
97*0b57cec5SDimitry Andric return m_dispatch_queue_name.c_str();
98*0b57cec5SDimitry Andric }
99*0b57cec5SDimitry Andric // Always re-fetch the dispatch queue name since it can change
100*0b57cec5SDimitry Andric
101*0b57cec5SDimitry Andric if (m_associated_with_libdispatch_queue == eLazyBoolNo)
102*0b57cec5SDimitry Andric return nullptr;
103*0b57cec5SDimitry Andric
104*0b57cec5SDimitry Andric if (m_thread_dispatch_qaddr != 0 &&
105*0b57cec5SDimitry Andric m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) {
106*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
107*0b57cec5SDimitry Andric if (process_sp) {
108*0b57cec5SDimitry Andric SystemRuntime *runtime = process_sp->GetSystemRuntime();
109*0b57cec5SDimitry Andric if (runtime)
110*0b57cec5SDimitry Andric m_dispatch_queue_name =
111*0b57cec5SDimitry Andric runtime->GetQueueNameFromThreadQAddress(m_thread_dispatch_qaddr);
112*0b57cec5SDimitry Andric else
113*0b57cec5SDimitry Andric m_dispatch_queue_name.clear();
114*0b57cec5SDimitry Andric
115*0b57cec5SDimitry Andric if (!m_dispatch_queue_name.empty())
116*0b57cec5SDimitry Andric return m_dispatch_queue_name.c_str();
117*0b57cec5SDimitry Andric }
118*0b57cec5SDimitry Andric }
119*0b57cec5SDimitry Andric return nullptr;
120*0b57cec5SDimitry Andric }
121*0b57cec5SDimitry Andric
GetQueueKind()122*0b57cec5SDimitry Andric QueueKind ThreadGDBRemote::GetQueueKind() {
123*0b57cec5SDimitry Andric // If our cached queue info is valid, then someone called
124*0b57cec5SDimitry Andric // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
125*0b57cec5SDimitry Andric // from the stop reply packet. In this case we trust that the info is valid
126*0b57cec5SDimitry Andric // in m_dispatch_queue_name without refetching it
127*0b57cec5SDimitry Andric if (CachedQueueInfoIsValid()) {
128*0b57cec5SDimitry Andric return m_queue_kind;
129*0b57cec5SDimitry Andric }
130*0b57cec5SDimitry Andric
131*0b57cec5SDimitry Andric if (m_associated_with_libdispatch_queue == eLazyBoolNo)
132*0b57cec5SDimitry Andric return eQueueKindUnknown;
133*0b57cec5SDimitry Andric
134*0b57cec5SDimitry Andric if (m_thread_dispatch_qaddr != 0 &&
135*0b57cec5SDimitry Andric m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) {
136*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
137*0b57cec5SDimitry Andric if (process_sp) {
138*0b57cec5SDimitry Andric SystemRuntime *runtime = process_sp->GetSystemRuntime();
139*0b57cec5SDimitry Andric if (runtime)
140*0b57cec5SDimitry Andric m_queue_kind = runtime->GetQueueKind(m_thread_dispatch_qaddr);
141*0b57cec5SDimitry Andric return m_queue_kind;
142*0b57cec5SDimitry Andric }
143*0b57cec5SDimitry Andric }
144*0b57cec5SDimitry Andric return eQueueKindUnknown;
145*0b57cec5SDimitry Andric }
146*0b57cec5SDimitry Andric
GetQueueID()147*0b57cec5SDimitry Andric queue_id_t ThreadGDBRemote::GetQueueID() {
148*0b57cec5SDimitry Andric // If our cached queue info is valid, then someone called
149*0b57cec5SDimitry Andric // ThreadGDBRemote::SetQueueInfo(...) with valid information that was gleaned
150*0b57cec5SDimitry Andric // from the stop reply packet. In this case we trust that the info is valid
151*0b57cec5SDimitry Andric // in m_dispatch_queue_name without refetching it
152*0b57cec5SDimitry Andric if (CachedQueueInfoIsValid())
153*0b57cec5SDimitry Andric return m_queue_serial_number;
154*0b57cec5SDimitry Andric
155*0b57cec5SDimitry Andric if (m_associated_with_libdispatch_queue == eLazyBoolNo)
156*0b57cec5SDimitry Andric return LLDB_INVALID_QUEUE_ID;
157*0b57cec5SDimitry Andric
158*0b57cec5SDimitry Andric if (m_thread_dispatch_qaddr != 0 &&
159*0b57cec5SDimitry Andric m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) {
160*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
161*0b57cec5SDimitry Andric if (process_sp) {
162*0b57cec5SDimitry Andric SystemRuntime *runtime = process_sp->GetSystemRuntime();
163*0b57cec5SDimitry Andric if (runtime) {
164*0b57cec5SDimitry Andric return runtime->GetQueueIDFromThreadQAddress(m_thread_dispatch_qaddr);
165*0b57cec5SDimitry Andric }
166*0b57cec5SDimitry Andric }
167*0b57cec5SDimitry Andric }
168*0b57cec5SDimitry Andric return LLDB_INVALID_QUEUE_ID;
169*0b57cec5SDimitry Andric }
170*0b57cec5SDimitry Andric
GetQueue()171*0b57cec5SDimitry Andric QueueSP ThreadGDBRemote::GetQueue() {
172*0b57cec5SDimitry Andric queue_id_t queue_id = GetQueueID();
173*0b57cec5SDimitry Andric QueueSP queue;
174*0b57cec5SDimitry Andric if (queue_id != LLDB_INVALID_QUEUE_ID) {
175*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
176*0b57cec5SDimitry Andric if (process_sp) {
177*0b57cec5SDimitry Andric queue = process_sp->GetQueueList().FindQueueByID(queue_id);
178*0b57cec5SDimitry Andric }
179*0b57cec5SDimitry Andric }
180*0b57cec5SDimitry Andric return queue;
181*0b57cec5SDimitry Andric }
182*0b57cec5SDimitry Andric
GetQueueLibdispatchQueueAddress()183*0b57cec5SDimitry Andric addr_t ThreadGDBRemote::GetQueueLibdispatchQueueAddress() {
184*0b57cec5SDimitry Andric if (m_dispatch_queue_t == LLDB_INVALID_ADDRESS) {
185*0b57cec5SDimitry Andric if (m_thread_dispatch_qaddr != 0 &&
186*0b57cec5SDimitry Andric m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) {
187*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
188*0b57cec5SDimitry Andric if (process_sp) {
189*0b57cec5SDimitry Andric SystemRuntime *runtime = process_sp->GetSystemRuntime();
190*0b57cec5SDimitry Andric if (runtime) {
191*0b57cec5SDimitry Andric m_dispatch_queue_t =
192*0b57cec5SDimitry Andric runtime->GetLibdispatchQueueAddressFromThreadQAddress(
193*0b57cec5SDimitry Andric m_thread_dispatch_qaddr);
194*0b57cec5SDimitry Andric }
195*0b57cec5SDimitry Andric }
196*0b57cec5SDimitry Andric }
197*0b57cec5SDimitry Andric }
198*0b57cec5SDimitry Andric return m_dispatch_queue_t;
199*0b57cec5SDimitry Andric }
200*0b57cec5SDimitry Andric
SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t)201*0b57cec5SDimitry Andric void ThreadGDBRemote::SetQueueLibdispatchQueueAddress(
202*0b57cec5SDimitry Andric lldb::addr_t dispatch_queue_t) {
203*0b57cec5SDimitry Andric m_dispatch_queue_t = dispatch_queue_t;
204*0b57cec5SDimitry Andric }
205*0b57cec5SDimitry Andric
ThreadHasQueueInformation() const206*0b57cec5SDimitry Andric bool ThreadGDBRemote::ThreadHasQueueInformation() const {
207*0b57cec5SDimitry Andric return m_thread_dispatch_qaddr != 0 &&
208*0b57cec5SDimitry Andric m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS &&
209*0b57cec5SDimitry Andric m_dispatch_queue_t != LLDB_INVALID_ADDRESS &&
210*0b57cec5SDimitry Andric m_queue_kind != eQueueKindUnknown && m_queue_serial_number != 0;
211*0b57cec5SDimitry Andric }
212*0b57cec5SDimitry Andric
GetAssociatedWithLibdispatchQueue()213*0b57cec5SDimitry Andric LazyBool ThreadGDBRemote::GetAssociatedWithLibdispatchQueue() {
214*0b57cec5SDimitry Andric return m_associated_with_libdispatch_queue;
215*0b57cec5SDimitry Andric }
216*0b57cec5SDimitry Andric
SetAssociatedWithLibdispatchQueue(LazyBool associated_with_libdispatch_queue)217*0b57cec5SDimitry Andric void ThreadGDBRemote::SetAssociatedWithLibdispatchQueue(
218*0b57cec5SDimitry Andric LazyBool associated_with_libdispatch_queue) {
219*0b57cec5SDimitry Andric m_associated_with_libdispatch_queue = associated_with_libdispatch_queue;
220*0b57cec5SDimitry Andric }
221*0b57cec5SDimitry Andric
FetchThreadExtendedInfo()222*0b57cec5SDimitry Andric StructuredData::ObjectSP ThreadGDBRemote::FetchThreadExtendedInfo() {
223*0b57cec5SDimitry Andric StructuredData::ObjectSP object_sp;
224*0b57cec5SDimitry Andric const lldb::user_id_t tid = GetProtocolID();
225*0b57cec5SDimitry Andric Log *log = GetLog(GDBRLog::Thread);
226*0b57cec5SDimitry Andric LLDB_LOGF(log, "Fetching extended information for thread %4.4" PRIx64, tid);
227*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
228*0b57cec5SDimitry Andric if (process_sp) {
229*0b57cec5SDimitry Andric ProcessGDBRemote *gdb_process =
230*0b57cec5SDimitry Andric static_cast<ProcessGDBRemote *>(process_sp.get());
231*0b57cec5SDimitry Andric object_sp = gdb_process->GetExtendedInfoForThread(tid);
232*0b57cec5SDimitry Andric }
233*0b57cec5SDimitry Andric return object_sp;
234*0b57cec5SDimitry Andric }
235*0b57cec5SDimitry Andric
WillResume(StateType resume_state)236*0b57cec5SDimitry Andric void ThreadGDBRemote::WillResume(StateType resume_state) {
237*0b57cec5SDimitry Andric int signo = GetResumeSignal();
238*0b57cec5SDimitry Andric const lldb::user_id_t tid = GetProtocolID();
239*0b57cec5SDimitry Andric Log *log = GetLog(GDBRLog::Thread);
240*0b57cec5SDimitry Andric LLDB_LOGF(log, "Resuming thread: %4.4" PRIx64 " with state: %s.", tid,
241*0b57cec5SDimitry Andric StateAsCString(resume_state));
242*0b57cec5SDimitry Andric
243*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
244*0b57cec5SDimitry Andric if (process_sp) {
245*0b57cec5SDimitry Andric ProcessGDBRemote *gdb_process =
246*0b57cec5SDimitry Andric static_cast<ProcessGDBRemote *>(process_sp.get());
247*0b57cec5SDimitry Andric switch (resume_state) {
248*0b57cec5SDimitry Andric case eStateSuspended:
249*0b57cec5SDimitry Andric case eStateStopped:
250*0b57cec5SDimitry Andric // Don't append anything for threads that should stay stopped.
251*0b57cec5SDimitry Andric break;
252*0b57cec5SDimitry Andric
253*0b57cec5SDimitry Andric case eStateRunning:
254*0b57cec5SDimitry Andric if (gdb_process->GetUnixSignals()->SignalIsValid(signo))
255*0b57cec5SDimitry Andric gdb_process->m_continue_C_tids.push_back(std::make_pair(tid, signo));
256*0b57cec5SDimitry Andric else
257*0b57cec5SDimitry Andric gdb_process->m_continue_c_tids.push_back(tid);
258*0b57cec5SDimitry Andric break;
259*0b57cec5SDimitry Andric
260*0b57cec5SDimitry Andric case eStateStepping:
261*0b57cec5SDimitry Andric if (gdb_process->GetUnixSignals()->SignalIsValid(signo))
262*0b57cec5SDimitry Andric gdb_process->m_continue_S_tids.push_back(std::make_pair(tid, signo));
263*0b57cec5SDimitry Andric else
264*0b57cec5SDimitry Andric gdb_process->m_continue_s_tids.push_back(tid);
265*0b57cec5SDimitry Andric break;
266*0b57cec5SDimitry Andric
267*0b57cec5SDimitry Andric default:
268*0b57cec5SDimitry Andric break;
269*0b57cec5SDimitry Andric }
270*0b57cec5SDimitry Andric }
271*0b57cec5SDimitry Andric }
272*0b57cec5SDimitry Andric
RefreshStateAfterStop()273*0b57cec5SDimitry Andric void ThreadGDBRemote::RefreshStateAfterStop() {
274*0b57cec5SDimitry Andric // Invalidate all registers in our register context. We don't set "force" to
275*0b57cec5SDimitry Andric // true because the stop reply packet might have had some register values
276*0b57cec5SDimitry Andric // that were expedited and these will already be copied into the register
277*0b57cec5SDimitry Andric // context by the time this function gets called. The
278*0b57cec5SDimitry Andric // GDBRemoteRegisterContext class has been made smart enough to detect when
279*0b57cec5SDimitry Andric // it needs to invalidate which registers are valid by putting hooks in the
280*0b57cec5SDimitry Andric // register read and register supply functions where they check the process
281*0b57cec5SDimitry Andric // stop ID and do the right thing.
282*0b57cec5SDimitry Andric const bool force = false;
283*0b57cec5SDimitry Andric GetRegisterContext()->InvalidateIfNeeded(force);
284*0b57cec5SDimitry Andric }
285*0b57cec5SDimitry Andric
ThreadIDIsValid(lldb::tid_t thread)286*0b57cec5SDimitry Andric bool ThreadGDBRemote::ThreadIDIsValid(lldb::tid_t thread) {
287*0b57cec5SDimitry Andric return thread != 0;
288*0b57cec5SDimitry Andric }
289*0b57cec5SDimitry Andric
Dump(Log * log,uint32_t index)290*0b57cec5SDimitry Andric void ThreadGDBRemote::Dump(Log *log, uint32_t index) {}
291*0b57cec5SDimitry Andric
ShouldStop(bool & step_more)292*0b57cec5SDimitry Andric bool ThreadGDBRemote::ShouldStop(bool &step_more) { return true; }
GetRegisterContext()293*0b57cec5SDimitry Andric lldb::RegisterContextSP ThreadGDBRemote::GetRegisterContext() {
294*0b57cec5SDimitry Andric if (!m_reg_context_sp)
295*0b57cec5SDimitry Andric m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
296*0b57cec5SDimitry Andric return m_reg_context_sp;
297*0b57cec5SDimitry Andric }
298*0b57cec5SDimitry Andric
299*0b57cec5SDimitry Andric lldb::RegisterContextSP
CreateRegisterContextForFrame(StackFrame * frame)300*0b57cec5SDimitry Andric ThreadGDBRemote::CreateRegisterContextForFrame(StackFrame *frame) {
301*0b57cec5SDimitry Andric lldb::RegisterContextSP reg_ctx_sp;
302*0b57cec5SDimitry Andric uint32_t concrete_frame_idx = 0;
303*0b57cec5SDimitry Andric
304*0b57cec5SDimitry Andric if (frame)
305*0b57cec5SDimitry Andric concrete_frame_idx = frame->GetConcreteFrameIndex();
306*0b57cec5SDimitry Andric
307*0b57cec5SDimitry Andric if (concrete_frame_idx == 0) {
308*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
309*0b57cec5SDimitry Andric if (process_sp) {
310*0b57cec5SDimitry Andric ProcessGDBRemote *gdb_process =
311*0b57cec5SDimitry Andric static_cast<ProcessGDBRemote *>(process_sp.get());
312*0b57cec5SDimitry Andric bool pSupported =
313*0b57cec5SDimitry Andric gdb_process->GetGDBRemote().GetpPacketSupported(GetID());
314*0b57cec5SDimitry Andric bool read_all_registers_at_once =
315*0b57cec5SDimitry Andric !pSupported || gdb_process->m_use_g_packet_for_reading;
316*0b57cec5SDimitry Andric bool write_all_registers_at_once = !pSupported;
317*0b57cec5SDimitry Andric reg_ctx_sp = std::make_shared<GDBRemoteRegisterContext>(
318*0b57cec5SDimitry Andric *this, concrete_frame_idx, m_reg_info_sp, read_all_registers_at_once,
319*0b57cec5SDimitry Andric write_all_registers_at_once);
320*0b57cec5SDimitry Andric }
321*0b57cec5SDimitry Andric } else {
322*0b57cec5SDimitry Andric reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
323*0b57cec5SDimitry Andric }
324*0b57cec5SDimitry Andric return reg_ctx_sp;
325*0b57cec5SDimitry Andric }
326*0b57cec5SDimitry Andric
PrivateSetRegisterValue(uint32_t reg,llvm::ArrayRef<uint8_t> data)327*0b57cec5SDimitry Andric bool ThreadGDBRemote::PrivateSetRegisterValue(uint32_t reg,
328*0b57cec5SDimitry Andric llvm::ArrayRef<uint8_t> data) {
329*0b57cec5SDimitry Andric GDBRemoteRegisterContext *gdb_reg_ctx =
330*0b57cec5SDimitry Andric static_cast<GDBRemoteRegisterContext *>(GetRegisterContext().get());
331*0b57cec5SDimitry Andric assert(gdb_reg_ctx);
332*0b57cec5SDimitry Andric return gdb_reg_ctx->PrivateSetRegisterValue(reg, data);
333*0b57cec5SDimitry Andric }
334*0b57cec5SDimitry Andric
PrivateSetRegisterValue(uint32_t reg,uint64_t regval)335*0b57cec5SDimitry Andric bool ThreadGDBRemote::PrivateSetRegisterValue(uint32_t reg, uint64_t regval) {
336*0b57cec5SDimitry Andric GDBRemoteRegisterContext *gdb_reg_ctx =
337*0b57cec5SDimitry Andric static_cast<GDBRemoteRegisterContext *>(GetRegisterContext().get());
338*0b57cec5SDimitry Andric assert(gdb_reg_ctx);
339*0b57cec5SDimitry Andric return gdb_reg_ctx->PrivateSetRegisterValue(reg, regval);
340*0b57cec5SDimitry Andric }
341*0b57cec5SDimitry Andric
CalculateStopInfo()342*0b57cec5SDimitry Andric bool ThreadGDBRemote::CalculateStopInfo() {
343*0b57cec5SDimitry Andric ProcessSP process_sp(GetProcess());
344 if (process_sp)
345 return static_cast<ProcessGDBRemote *>(process_sp.get())
346 ->CalculateThreadStopInfo(this);
347 return false;
348 }
349
350 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
GetSiginfo(size_t max_size) const351 ThreadGDBRemote::GetSiginfo(size_t max_size) const {
352 ProcessSP process_sp(GetProcess());
353 if (!process_sp)
354 return llvm::createStringError(llvm::inconvertibleErrorCode(),
355 "no process");
356 ProcessGDBRemote *gdb_process =
357 static_cast<ProcessGDBRemote *>(process_sp.get());
358 if (!gdb_process->m_gdb_comm.GetQXferSigInfoReadSupported())
359 return llvm::createStringError(llvm::inconvertibleErrorCode(),
360 "qXfer:siginfo:read not supported");
361
362 llvm::Expected<std::string> response =
363 gdb_process->m_gdb_comm.ReadExtFeature("siginfo", "");
364 if (!response)
365 return response.takeError();
366
367 return llvm::MemoryBuffer::getMemBufferCopy(response.get());
368 }
369