blob: 095544d244ba4548e5de282111055acc37819079 [file] [log] [blame]
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +00001//===-- ThreadMemory.h ------------------------------------------*- C++ -*-===//
Greg Clayton56d9a1b2011-08-22 02:49:39 +00002//
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
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +000013// C Includes
14// C++ Includes
Eugene Zelenkoca64d672015-10-30 00:55:29 +000015#include <string>
16
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +000017// Other libraries and framework includes
18// Project includes
Greg Clayton56d9a1b2011-08-22 02:49:39 +000019#include "lldb/Target/Thread.h"
20
Kate Stoneb9c1b512016-09-06 20:57:50 +000021class ThreadMemory : public lldb_private::Thread {
Greg Clayton56d9a1b2011-08-22 02:49:39 +000022public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000023 ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
24 const lldb::ValueObjectSP &thread_info_valobj_sp);
Greg Clayton56d9a1b2011-08-22 02:49:39 +000025
Kate Stoneb9c1b512016-09-06 20:57:50 +000026 ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
27 const char *name, const char *queue,
28 lldb::addr_t register_data_addr);
Greg Clayton435ce132012-08-24 05:45:15 +000029
Kate Stoneb9c1b512016-09-06 20:57:50 +000030 ~ThreadMemory() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000031
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 lldb::RegisterContextSP GetRegisterContext() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034 lldb::RegisterContextSP
35 CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 bool CalculateStopInfo() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000038
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 const char *GetInfo() override {
40 if (m_backing_thread_sp)
41 m_backing_thread_sp->GetInfo();
42 return nullptr;
43 }
Greg Claytonb3ae8762013-04-12 20:07:46 +000044
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 const char *GetName() override {
46 if (!m_name.empty())
47 return m_name.c_str();
48 if (m_backing_thread_sp)
49 m_backing_thread_sp->GetName();
50 return nullptr;
51 }
Greg Clayton435ce132012-08-24 05:45:15 +000052
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 const char *GetQueueName() override {
54 if (!m_queue.empty())
55 return m_queue.c_str();
56 if (m_backing_thread_sp)
57 m_backing_thread_sp->GetQueueName();
58 return nullptr;
59 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +000060
Kate Stoneb9c1b512016-09-06 20:57:50 +000061 void WillResume(lldb::StateType resume_state) override;
Greg Claytonb3ae8762013-04-12 20:07:46 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 void DidResume() override {
64 if (m_backing_thread_sp)
65 m_backing_thread_sp->DidResume();
66 }
Greg Clayton160c9d82013-05-01 21:54:04 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 lldb::user_id_t GetProtocolID() const override {
69 if (m_backing_thread_sp)
70 return m_backing_thread_sp->GetProtocolID();
71 return Thread::GetProtocolID();
72 }
Greg Claytonb3ae8762013-04-12 20:07:46 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 void RefreshStateAfterStop() override;
75
76 lldb::ValueObjectSP &GetValueObject() { return m_thread_info_valobj_sp; }
77
78 void ClearStackFrames() override;
79
80 void ClearBackingThread() override { m_backing_thread_sp.reset(); }
81
82 bool SetBackingThread(const lldb::ThreadSP &thread_sp) override {
83 // printf ("Thread 0x%llx is being backed by thread 0x%llx\n", GetID(),
84 // thread_sp->GetID());
85 m_backing_thread_sp = thread_sp;
86 return (bool)thread_sp;
87 }
88
89 lldb::ThreadSP GetBackingThread() const override {
90 return m_backing_thread_sp;
91 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +000092
93protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 bool IsOperatingSystemPluginThread() const override { return true; }
95
96 // If this memory thread is actually represented by a thread from the
97 // lldb_private::Process subclass, then fill in the thread here and
98 // all APIs will be routed through this thread object. If m_backing_thread_sp
99 // is empty, then this thread is simply in memory with no representation
100 // through the process plug-in.
101 lldb::ThreadSP m_backing_thread_sp;
102 lldb::ValueObjectSP m_thread_info_valobj_sp;
103 std::string m_name;
104 std::string m_queue;
105 lldb::addr_t m_register_data_addr;
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +0000106
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000107private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 DISALLOW_COPY_AND_ASSIGN(ThreadMemory);
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000109};
110
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +0000111#endif // liblldb_ThreadMemory_h_