blob: c966ca03a017a18e2a49e1e95a244328d562de0c [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 Zelenkoca64d672015-10-30 00:55:29 +000013#include <string>
14
Greg Clayton56d9a1b2011-08-22 02:49:39 +000015#include "lldb/Target/Thread.h"
16
Kate Stoneb9c1b512016-09-06 20:57:50 +000017class ThreadMemory : public lldb_private::Thread {
Greg Clayton56d9a1b2011-08-22 02:49:39 +000018public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000019 ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
20 const lldb::ValueObjectSP &thread_info_valobj_sp);
Greg Clayton56d9a1b2011-08-22 02:49:39 +000021
Kate Stoneb9c1b512016-09-06 20:57:50 +000022 ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
Zachary Turner28333212017-05-12 05:49:54 +000023 llvm::StringRef name, llvm::StringRef queue,
Kate Stoneb9c1b512016-09-06 20:57:50 +000024 lldb::addr_t register_data_addr);
Greg Clayton435ce132012-08-24 05:45:15 +000025
Kate Stoneb9c1b512016-09-06 20:57:50 +000026 ~ThreadMemory() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000027
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 lldb::RegisterContextSP GetRegisterContext() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000029
Kate Stoneb9c1b512016-09-06 20:57:50 +000030 lldb::RegisterContextSP
31 CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 bool CalculateStopInfo() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 const char *GetInfo() override {
36 if (m_backing_thread_sp)
37 m_backing_thread_sp->GetInfo();
38 return nullptr;
39 }
Greg Claytonb3ae8762013-04-12 20:07:46 +000040
Kate Stoneb9c1b512016-09-06 20:57:50 +000041 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 }
Greg Clayton435ce132012-08-24 05:45:15 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049 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 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +000056
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 void WillResume(lldb::StateType resume_state) override;
Greg Claytonb3ae8762013-04-12 20:07:46 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 void DidResume() override {
60 if (m_backing_thread_sp)
61 m_backing_thread_sp->DidResume();
62 }
Greg Clayton160c9d82013-05-01 21:54:04 +000063
Kate Stoneb9c1b512016-09-06 20:57:50 +000064 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 }
Greg Claytonb3ae8762013-04-12 20:07:46 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 void RefreshStateAfterStop() override;
71
72 lldb::ValueObjectSP &GetValueObject() { return m_thread_info_valobj_sp; }
73
74 void ClearStackFrames() override;
75
76 void ClearBackingThread() override { m_backing_thread_sp.reset(); }
77
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
85 lldb::ThreadSP GetBackingThread() const override {
86 return m_backing_thread_sp;
87 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +000088
89protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 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;
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +0000102
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000103private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104 DISALLOW_COPY_AND_ASSIGN(ThreadMemory);
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000105};
106
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +0000107#endif // liblldb_ThreadMemory_h_