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