blob: e13a815edf5bfae48f43b0d604d0fb0f677c9eef [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
14#include "lldb/Target/Process.h"
15#include "lldb/Target/Thread.h"
Pavel Labathf2a8bcc2017-06-27 10:45:31 +000016#include "lldb/Utility/StructuredData.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017
18class StringExtractor;
Tamas Berghammerdb264a62015-03-31 09:52:22 +000019
20namespace lldb_private {
21namespace process_gdb_remote {
22
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023class ProcessGDBRemote;
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025class ThreadGDBRemote : public Thread {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000027 ThreadGDBRemote(Process &process, lldb::tid_t tid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
Kate Stoneb9c1b512016-09-06 20:57:50 +000029 ~ThreadGDBRemote() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030
Kate Stoneb9c1b512016-09-06 20:57:50 +000031 void WillResume(lldb::StateType resume_state) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 void RefreshStateAfterStop() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 const char *GetName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 const char *GetQueueName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 lldb::QueueKind GetQueueKind() override;
Jason Molenda77f89352016-01-12 07:09:16 +000040
Kate Stoneb9c1b512016-09-06 20:57:50 +000041 lldb::queue_id_t GetQueueID() override;
Jason Molenda3dc4f442013-10-18 05:55:24 +000042
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 lldb::QueueSP GetQueue() override;
Jason Molenda2dd5deb2014-04-25 00:02:11 +000044
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 lldb::addr_t GetQueueLibdispatchQueueAddress() override;
Jason Molendaaac16e02014-03-13 02:54:54 +000046
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) override;
Jason Molenda77f89352016-01-12 07:09:16 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049 bool ThreadHasQueueInformation() const override;
Jason Molenda77f89352016-01-12 07:09:16 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 lldb::RegisterContextSP GetRegisterContext() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 lldb::RegisterContextSP
54 CreateRegisterContextForFrame(StackFrame *frame) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 void Dump(Log *log, uint32_t index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
Kate Stoneb9c1b512016-09-06 20:57:50 +000058 static bool ThreadIDIsValid(lldb::tid_t thread);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 bool ShouldStop(bool &step_more);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 const char *GetBasicInfoAsString();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 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 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070
Kate Stoneb9c1b512016-09-06 20:57:50 +000071 lldb::addr_t GetThreadDispatchQAddr() { return m_thread_dispatch_qaddr; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 void SetThreadDispatchQAddr(lldb::addr_t thread_dispatch_qaddr) {
74 m_thread_dispatch_qaddr = thread_dispatch_qaddr;
75 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 void ClearQueueInfo();
Jason Molenda77f89352016-01-12 07:09:16 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 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);
Jason Molenda77f89352016-01-12 07:09:16 +000082
Kate Stoneb9c1b512016-09-06 20:57:50 +000083 lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() override;
Greg Clayton0b90be12015-06-23 21:27:50 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 void SetAssociatedWithLibdispatchQueue(
86 lldb_private::LazyBool associated_with_libdispatch_queue) override;
87
88 StructuredData::ObjectSP FetchThreadExtendedInfo() override;
Jason Molenda705b1802014-06-13 02:37:02 +000089
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 friend class ProcessGDBRemote;
Greg Clayton3e06bd92011-01-09 21:07:35 +000092
Kate Stoneb9c1b512016-09-06 20:57:50 +000093 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;
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000102
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103 bool PrivateSetRegisterValue(uint32_t reg, llvm::ArrayRef<uint8_t> data);
Greg Clayton0b90be12015-06-23 21:27:50 +0000104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105 bool PrivateSetRegisterValue(uint32_t reg, uint64_t regval);
Jason Molenda545304d2015-12-18 00:45:35 +0000106
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107 bool CachedQueueInfoIsValid() const {
108 return m_queue_kind != lldb::eQueueKindUnknown;
109 }
110 void SetStopInfoFromPacket(StringExtractor &stop_packet, uint32_t stop_id);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111
Kate Stoneb9c1b512016-09-06 20:57:50 +0000112 bool CalculateStopInfo() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113};
114
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000115} // namespace process_gdb_remote
116} // namespace lldb_private
117
Eugene Zelenkoedb35d92015-10-24 01:08:35 +0000118#endif // liblldb_ThreadGDBRemote_h_