xref: /llvm-project/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h (revision 2946cd701067404b99c39fb29dc9c74bd7193eb3)
1 //===-- ThreadGDBRemote.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_ThreadGDBRemote_h_
10 #define liblldb_ThreadGDBRemote_h_
11 
12 #include <string>
13 
14 #include "lldb/Target/Process.h"
15 #include "lldb/Target/Thread.h"
16 #include "lldb/Utility/StructuredData.h"
17 
18 class StringExtractor;
19 
20 namespace lldb_private {
21 namespace process_gdb_remote {
22 
23 class ProcessGDBRemote;
24 
25 class ThreadGDBRemote : public Thread {
26 public:
27   ThreadGDBRemote(Process &process, lldb::tid_t tid);
28 
29   ~ThreadGDBRemote() override;
30 
31   void WillResume(lldb::StateType resume_state) override;
32 
33   void RefreshStateAfterStop() override;
34 
35   const char *GetName() override;
36 
37   const char *GetQueueName() override;
38 
39   lldb::QueueKind GetQueueKind() override;
40 
41   lldb::queue_id_t GetQueueID() override;
42 
43   lldb::QueueSP GetQueue() override;
44 
45   lldb::addr_t GetQueueLibdispatchQueueAddress() override;
46 
47   void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) override;
48 
49   bool ThreadHasQueueInformation() const override;
50 
51   lldb::RegisterContextSP GetRegisterContext() override;
52 
53   lldb::RegisterContextSP
54   CreateRegisterContextForFrame(StackFrame *frame) override;
55 
56   void Dump(Log *log, uint32_t index);
57 
58   static bool ThreadIDIsValid(lldb::tid_t thread);
59 
60   bool ShouldStop(bool &step_more);
61 
62   const char *GetBasicInfoAsString();
63 
64   void SetName(const char *name) override {
65     if (name && name[0])
66       m_thread_name.assign(name);
67     else
68       m_thread_name.clear();
69   }
70 
71   lldb::addr_t GetThreadDispatchQAddr() { return m_thread_dispatch_qaddr; }
72 
73   void SetThreadDispatchQAddr(lldb::addr_t thread_dispatch_qaddr) {
74     m_thread_dispatch_qaddr = thread_dispatch_qaddr;
75   }
76 
77   void ClearQueueInfo();
78 
79   void SetQueueInfo(std::string &&queue_name, lldb::QueueKind queue_kind,
80                     uint64_t queue_serial, lldb::addr_t dispatch_queue_t,
81                     lldb_private::LazyBool associated_with_libdispatch_queue);
82 
83   lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() override;
84 
85   void SetAssociatedWithLibdispatchQueue(
86       lldb_private::LazyBool associated_with_libdispatch_queue) override;
87 
88   StructuredData::ObjectSP FetchThreadExtendedInfo() override;
89 
90 protected:
91   friend class ProcessGDBRemote;
92 
93   std::string m_thread_name;
94   std::string m_dispatch_queue_name;
95   lldb::addr_t m_thread_dispatch_qaddr;
96   lldb::addr_t m_dispatch_queue_t;
97   lldb::QueueKind
98       m_queue_kind; // Queue info from stop reply/stop info for thread
99   uint64_t
100       m_queue_serial_number; // Queue info from stop reply/stop info for thread
101   lldb_private::LazyBool m_associated_with_libdispatch_queue;
102 
103   bool PrivateSetRegisterValue(uint32_t reg, llvm::ArrayRef<uint8_t> data);
104 
105   bool PrivateSetRegisterValue(uint32_t reg, uint64_t regval);
106 
107   bool CachedQueueInfoIsValid() const {
108     return m_queue_kind != lldb::eQueueKindUnknown;
109   }
110   void SetStopInfoFromPacket(StringExtractor &stop_packet, uint32_t stop_id);
111 
112   bool CalculateStopInfo() override;
113 };
114 
115 } // namespace process_gdb_remote
116 } // namespace lldb_private
117 
118 #endif // liblldb_ThreadGDBRemote_h_
119