blob: c74be169abaf7be512af6d57f6adc666cf0c6736 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ThreadGDBRemote.h ---------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_ThreadGDBRemote_h_
10#define liblldb_ThreadGDBRemote_h_
11
12#include <string>
13
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include "lldb/Target/Thread.h"
Pavel Labathf2a8bcc2017-06-27 10:45:31 +000015#include "lldb/Utility/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016
17class StringExtractor;
Tamas Berghammerdb264a62015-03-31 09:52:22 +000018
19namespace lldb_private {
Saleem Abdulrasoolbd689b92019-05-02 18:15:03 +000020class Process;
21
Tamas Berghammerdb264a62015-03-31 09:52:22 +000022namespace process_gdb_remote {
23
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024class ProcessGDBRemote;
25
Kate Stoneb9c1b512016-09-06 20:57:50 +000026class ThreadGDBRemote : public Thread {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 ThreadGDBRemote(Process &process, lldb::tid_t tid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029
Kate Stoneb9c1b512016-09-06 20:57:50 +000030 ~ThreadGDBRemote() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 void WillResume(lldb::StateType resume_state) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034 void RefreshStateAfterStop() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Kate Stoneb9c1b512016-09-06 20:57:50 +000036 const char *GetName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 const char *GetQueueName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 lldb::QueueKind GetQueueKind() override;
Jason Molenda77f89352016-01-12 07:09:16 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 lldb::queue_id_t GetQueueID() override;
Jason Molenda3dc4f442013-10-18 05:55:24 +000043
Kate Stoneb9c1b512016-09-06 20:57:50 +000044 lldb::QueueSP GetQueue() override;
Jason Molenda2dd5deb2014-04-25 00:02:11 +000045
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 lldb::addr_t GetQueueLibdispatchQueueAddress() override;
Jason Molendaaac16e02014-03-13 02:54:54 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) override;
Jason Molenda77f89352016-01-12 07:09:16 +000049
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 bool ThreadHasQueueInformation() const override;
Jason Molenda77f89352016-01-12 07:09:16 +000051
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 lldb::RegisterContextSP GetRegisterContext() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054 lldb::RegisterContextSP
55 CreateRegisterContextForFrame(StackFrame *frame) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 void Dump(Log *log, uint32_t index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 static bool ThreadIDIsValid(lldb::tid_t thread);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
Kate Stoneb9c1b512016-09-06 20:57:50 +000061 bool ShouldStop(bool &step_more);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 const char *GetBasicInfoAsString();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 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 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 lldb::addr_t GetThreadDispatchQAddr() { return m_thread_dispatch_qaddr; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 void SetThreadDispatchQAddr(lldb::addr_t thread_dispatch_qaddr) {
75 m_thread_dispatch_qaddr = thread_dispatch_qaddr;
76 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 void ClearQueueInfo();
Jason Molenda77f89352016-01-12 07:09:16 +000079
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 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);
Jason Molenda77f89352016-01-12 07:09:16 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() override;
Greg Clayton0b90be12015-06-23 21:27:50 +000085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 void SetAssociatedWithLibdispatchQueue(
87 lldb_private::LazyBool associated_with_libdispatch_queue) override;
88
89 StructuredData::ObjectSP FetchThreadExtendedInfo() override;
Jason Molenda705b1802014-06-13 02:37:02 +000090
Chris Lattner30fdc8d2010-06-08 16:52:24 +000091protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 friend class ProcessGDBRemote;
Greg Clayton3e06bd92011-01-09 21:07:35 +000093
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 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;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104 bool PrivateSetRegisterValue(uint32_t reg, llvm::ArrayRef<uint8_t> data);
Greg Clayton0b90be12015-06-23 21:27:50 +0000105
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106 bool PrivateSetRegisterValue(uint32_t reg, uint64_t regval);
Jason Molenda545304d2015-12-18 00:45:35 +0000107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 bool CachedQueueInfoIsValid() const {
109 return m_queue_kind != lldb::eQueueKindUnknown;
110 }
111 void SetStopInfoFromPacket(StringExtractor &stop_packet, uint32_t stop_id);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 bool CalculateStopInfo() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114};
115
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000116} // namespace process_gdb_remote
117} // namespace lldb_private
118
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000119#endif // liblldb_ThreadGDBRemote_h_