1 //===-- ThreadMemory.h ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_ThreadMemory_h_
11 #define liblldb_ThreadMemory_h_
12 
13 #include <string>
14 
15 #include "lldb/Target/Thread.h"
16 
17 class ThreadMemory : public lldb_private::Thread {
18 public:
19   ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
20                const lldb::ValueObjectSP &thread_info_valobj_sp);
21 
22   ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
23                llvm::StringRef name, llvm::StringRef queue,
24                lldb::addr_t register_data_addr);
25 
26   ~ThreadMemory() override;
27 
28   lldb::RegisterContextSP GetRegisterContext() override;
29 
30   lldb::RegisterContextSP
31   CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
32 
33   bool CalculateStopInfo() override;
34 
GetInfo()35   const char *GetInfo() override {
36     if (m_backing_thread_sp)
37       m_backing_thread_sp->GetInfo();
38     return nullptr;
39   }
40 
GetName()41   const char *GetName() override {
42     if (!m_name.empty())
43       return m_name.c_str();
44     if (m_backing_thread_sp)
45       m_backing_thread_sp->GetName();
46     return nullptr;
47   }
48 
GetQueueName()49   const char *GetQueueName() override {
50     if (!m_queue.empty())
51       return m_queue.c_str();
52     if (m_backing_thread_sp)
53       m_backing_thread_sp->GetQueueName();
54     return nullptr;
55   }
56 
57   void WillResume(lldb::StateType resume_state) override;
58 
DidResume()59   void DidResume() override {
60     if (m_backing_thread_sp)
61       m_backing_thread_sp->DidResume();
62   }
63 
GetProtocolID()64   lldb::user_id_t GetProtocolID() const override {
65     if (m_backing_thread_sp)
66       return m_backing_thread_sp->GetProtocolID();
67     return Thread::GetProtocolID();
68   }
69 
70   void RefreshStateAfterStop() override;
71 
GetValueObject()72   lldb::ValueObjectSP &GetValueObject() { return m_thread_info_valobj_sp; }
73 
74   void ClearStackFrames() override;
75 
ClearBackingThread()76   void ClearBackingThread() override { m_backing_thread_sp.reset(); }
77 
SetBackingThread(const lldb::ThreadSP & thread_sp)78   bool SetBackingThread(const lldb::ThreadSP &thread_sp) override {
79     // printf ("Thread 0x%llx is being backed by thread 0x%llx\n", GetID(),
80     // thread_sp->GetID());
81     m_backing_thread_sp = thread_sp;
82     return (bool)thread_sp;
83   }
84 
GetBackingThread()85   lldb::ThreadSP GetBackingThread() const override {
86     return m_backing_thread_sp;
87   }
88 
89 protected:
IsOperatingSystemPluginThread()90   bool IsOperatingSystemPluginThread() const override { return true; }
91 
92   // If this memory thread is actually represented by a thread from the
93   // lldb_private::Process subclass, then fill in the thread here and
94   // all APIs will be routed through this thread object. If m_backing_thread_sp
95   // is empty, then this thread is simply in memory with no representation
96   // through the process plug-in.
97   lldb::ThreadSP m_backing_thread_sp;
98   lldb::ValueObjectSP m_thread_info_valobj_sp;
99   std::string m_name;
100   std::string m_queue;
101   lldb::addr_t m_register_data_addr;
102 
103 private:
104   DISALLOW_COPY_AND_ASSIGN(ThreadMemory);
105 };
106 
107 #endif // liblldb_ThreadMemory_h_
108