1 //===-- ThreadMemory.h ------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_THREADMEMORY_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_THREADMEMORY_H
14 #include "lldb/Target/Thread.h"
16 class ThreadMemory : public lldb_private::Thread {
18 ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
19 const lldb::ValueObjectSP &thread_info_valobj_sp);
21 ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
22 llvm::StringRef name, llvm::StringRef queue,
23 lldb::addr_t register_data_addr);
25 ~ThreadMemory() override;
27 lldb::RegisterContextSP GetRegisterContext() override;
29 lldb::RegisterContextSP
30 CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
32 bool CalculateStopInfo() override;
34 const char *GetInfo() override {
35 if (m_backing_thread_sp)
36 m_backing_thread_sp->GetInfo();
40 const char *GetName() override {
42 return m_name.c_str();
43 if (m_backing_thread_sp)
44 m_backing_thread_sp->GetName();
48 const char *GetQueueName() override {
50 return m_queue.c_str();
51 if (m_backing_thread_sp)
52 m_backing_thread_sp->GetQueueName();
56 void WillResume(lldb::StateType resume_state) override;
58 void DidResume() override {
59 if (m_backing_thread_sp)
60 m_backing_thread_sp->DidResume();
63 lldb::user_id_t GetProtocolID() const override {
64 if (m_backing_thread_sp)
65 return m_backing_thread_sp->GetProtocolID();
66 return Thread::GetProtocolID();
69 void RefreshStateAfterStop() override;
71 lldb::ValueObjectSP &GetValueObject() { return m_thread_info_valobj_sp; }
73 void ClearStackFrames() override;
75 void ClearBackingThread() override { m_backing_thread_sp.reset(); }
77 bool SetBackingThread(const lldb::ThreadSP &thread_sp) override {
78 // printf ("Thread 0x%llx is being backed by thread 0x%llx\n", GetID(),
79 // thread_sp->GetID());
80 m_backing_thread_sp = thread_sp;
81 return (bool)thread_sp;
84 lldb::ThreadSP GetBackingThread() const override {
85 return m_backing_thread_sp;
89 bool IsOperatingSystemPluginThread() const override { return true; }
91 // If this memory thread is actually represented by a thread from the
92 // lldb_private::Process subclass, then fill in the thread here and
93 // all APIs will be routed through this thread object. If m_backing_thread_sp
94 // is empty, then this thread is simply in memory with no representation
95 // through the process plug-in.
96 lldb::ThreadSP m_backing_thread_sp;
97 lldb::ValueObjectSP m_thread_info_valobj_sp;
100 lldb::addr_t m_register_data_addr;
103 ThreadMemory(const ThreadMemory &) = delete;
104 const ThreadMemory &operator=(const ThreadMemory &) = delete;
107 #endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_THREADMEMORY_H