blob: 85bc1451e4a0e8b0725eedd9cc7673080b124d36 [file] [log] [blame]
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +00001//===-- ThreadMemory.h ------------------------------------------*- C++ -*-===//
Greg Clayton56d9a1b2011-08-22 02:49:39 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Greg Clayton56d9a1b2011-08-22 02:49:39 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_ThreadMemory_h_
10#define liblldb_ThreadMemory_h_
11
Eugene Zelenkoca64d672015-10-30 00:55:29 +000012#include <string>
13
Greg Clayton56d9a1b2011-08-22 02:49:39 +000014#include "lldb/Target/Thread.h"
15
Kate Stoneb9c1b512016-09-06 20:57:50 +000016class ThreadMemory : public lldb_private::Thread {
Greg Clayton56d9a1b2011-08-22 02:49:39 +000017public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000018 ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
19 const lldb::ValueObjectSP &thread_info_valobj_sp);
Greg Clayton56d9a1b2011-08-22 02:49:39 +000020
Kate Stoneb9c1b512016-09-06 20:57:50 +000021 ThreadMemory(lldb_private::Process &process, lldb::tid_t tid,
Zachary Turner28333212017-05-12 05:49:54 +000022 llvm::StringRef name, llvm::StringRef queue,
Kate Stoneb9c1b512016-09-06 20:57:50 +000023 lldb::addr_t register_data_addr);
Greg Clayton435ce132012-08-24 05:45:15 +000024
Kate Stoneb9c1b512016-09-06 20:57:50 +000025 ~ThreadMemory() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000026
Kate Stoneb9c1b512016-09-06 20:57:50 +000027 lldb::RegisterContextSP GetRegisterContext() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000028
Kate Stoneb9c1b512016-09-06 20:57:50 +000029 lldb::RegisterContextSP
30 CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000031
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 bool CalculateStopInfo() override;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000033
Kate Stoneb9c1b512016-09-06 20:57:50 +000034 const char *GetInfo() override {
35 if (m_backing_thread_sp)
36 m_backing_thread_sp->GetInfo();
37 return nullptr;
38 }
Greg Claytonb3ae8762013-04-12 20:07:46 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 const char *GetName() override {
41 if (!m_name.empty())
42 return m_name.c_str();
43 if (m_backing_thread_sp)
44 m_backing_thread_sp->GetName();
45 return nullptr;
46 }
Greg Clayton435ce132012-08-24 05:45:15 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 const char *GetQueueName() override {
49 if (!m_queue.empty())
50 return m_queue.c_str();
51 if (m_backing_thread_sp)
52 m_backing_thread_sp->GetQueueName();
53 return nullptr;
54 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 void WillResume(lldb::StateType resume_state) override;
Greg Claytonb3ae8762013-04-12 20:07:46 +000057
Kate Stoneb9c1b512016-09-06 20:57:50 +000058 void DidResume() override {
59 if (m_backing_thread_sp)
60 m_backing_thread_sp->DidResume();
61 }
Greg Clayton160c9d82013-05-01 21:54:04 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 lldb::user_id_t GetProtocolID() const override {
64 if (m_backing_thread_sp)
65 return m_backing_thread_sp->GetProtocolID();
66 return Thread::GetProtocolID();
67 }
Greg Claytonb3ae8762013-04-12 20:07:46 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 void RefreshStateAfterStop() override;
70
71 lldb::ValueObjectSP &GetValueObject() { return m_thread_info_valobj_sp; }
72
73 void ClearStackFrames() override;
74
75 void ClearBackingThread() override { m_backing_thread_sp.reset(); }
76
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;
82 }
83
84 lldb::ThreadSP GetBackingThread() const override {
85 return m_backing_thread_sp;
86 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +000087
88protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 bool IsOperatingSystemPluginThread() const override { return true; }
90
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;
98 std::string m_name;
99 std::string m_queue;
100 lldb::addr_t m_register_data_addr;
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +0000101
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000102private:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103 DISALLOW_COPY_AND_ASSIGN(ThreadMemory);
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000104};
105
Eugene Zelenkoab7f6d02015-10-21 18:46:17 +0000106#endif // liblldb_ThreadMemory_h_