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