xref: /llvm-project/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h (revision 545304d323d6bbebdddcd93a7b657e761b8df168)
1 //===-- ThreadGDBRemote.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_ThreadGDBRemote_h_
11 #define liblldb_ThreadGDBRemote_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <string>
16 
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/Core/StructuredData.h"
20 #include "lldb/Target/Process.h"
21 #include "lldb/Target/Thread.h"
22 
23 class StringExtractor;
24 
25 namespace lldb_private {
26 namespace process_gdb_remote {
27 
28 class ProcessGDBRemote;
29 
30 class ThreadGDBRemote : public Thread
31 {
32 public:
33     ThreadGDBRemote (Process &process, lldb::tid_t tid);
34 
35     ~ThreadGDBRemote() override;
36 
37     void
38     WillResume (lldb::StateType resume_state) override;
39 
40     void
41     RefreshStateAfterStop() override;
42 
43     const char *
44     GetName () override;
45 
46     const char *
47     GetQueueName () override;
48 
49     lldb::queue_id_t
50     GetQueueID () override;
51 
52     lldb::QueueSP
53     GetQueue () override;
54 
55     lldb::addr_t
56     GetQueueLibdispatchQueueAddress () override;
57 
58     lldb::RegisterContextSP
59     GetRegisterContext () override;
60 
61     lldb::RegisterContextSP
62     CreateRegisterContextForFrame (StackFrame *frame) override;
63 
64     void
65     Dump (Log *log, uint32_t index);
66 
67     static bool
68     ThreadIDIsValid (lldb::tid_t thread);
69 
70     bool
71     ShouldStop (bool &step_more);
72 
73     const char *
74     GetBasicInfoAsString ();
75 
76     void
77     SetName (const char *name) override
78     {
79         if (name && name[0])
80             m_thread_name.assign (name);
81         else
82             m_thread_name.clear();
83     }
84 
85     lldb::addr_t
86     GetThreadDispatchQAddr ()
87     {
88         return m_thread_dispatch_qaddr;
89     }
90 
91     void
92     SetThreadDispatchQAddr (lldb::addr_t thread_dispatch_qaddr)
93     {
94         m_thread_dispatch_qaddr = thread_dispatch_qaddr;
95     }
96 
97     void
98     ClearQueueInfo ();
99 
100     void
101     SetQueueInfo (std::string &&queue_name, lldb::QueueKind queue_kind, uint64_t queue_serial);
102 
103     StructuredData::ObjectSP
104     FetchThreadExtendedInfo () override;
105 
106 protected:
107     friend class ProcessGDBRemote;
108 
109     std::string m_thread_name;
110     std::string m_dispatch_queue_name;
111     lldb::addr_t m_thread_dispatch_qaddr;
112     lldb::QueueKind m_queue_kind;     // Queue info from stop reply/stop info for thread
113     uint64_t m_queue_serial;    // Queue info from stop reply/stop info for thread
114 
115     bool
116     PrivateSetRegisterValue (uint32_t reg,
117                              StringExtractor &response);
118 
119     bool
120     PrivateSetRegisterValue (uint32_t reg,
121                              uint64_t regval);
122 
123     bool
124     CachedQueueInfoIsValid() const
125     {
126         return m_queue_kind != lldb::eQueueKindUnknown;
127     }
128     void
129     SetStopInfoFromPacket (StringExtractor &stop_packet, uint32_t stop_id);
130 
131     bool
132     CalculateStopInfo () override;
133 };
134 
135 } // namespace process_gdb_remote
136 } // namespace lldb_private
137 
138 #endif // liblldb_ThreadGDBRemote_h_
139