summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/Utility/ThreadMemory.h
blob: 1e7cbfa4481537fa90db87bc10a0e08692d55da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//===-- ThreadMemory.h ------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_ThreadMemory_h_
#define liblldb_ThreadMemory_h_

// C Includes
// C++ Includes
#include <string>

// Other libraries and framework includes
// Project includes
#include "lldb/Target/Thread.h"

class ThreadMemory :
    public lldb_private::Thread
{
public:
    ThreadMemory (lldb_private::Process &process,
                  lldb::tid_t tid,
                  const lldb::ValueObjectSP &thread_info_valobj_sp);

    ThreadMemory (lldb_private::Process &process,
                  lldb::tid_t tid,
                  const char *name,
                  const char *queue,
                  lldb::addr_t register_data_addr);

    ~ThreadMemory() override;

    lldb::RegisterContextSP
    GetRegisterContext() override;

    lldb::RegisterContextSP
    CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;

    bool
    CalculateStopInfo() override;

    const char *
    GetInfo() override
    {
        if (m_backing_thread_sp)
            m_backing_thread_sp->GetInfo();
        return nullptr;
    }

    const char *
    GetName() override
    {
        if (!m_name.empty())
            return m_name.c_str();
        if (m_backing_thread_sp)
            m_backing_thread_sp->GetName();
        return nullptr;
    }
    
    const char *
    GetQueueName() override
    {
        if (!m_queue.empty())
            return m_queue.c_str();
        if (m_backing_thread_sp)
            m_backing_thread_sp->GetQueueName();
        return nullptr;
    }

    void
    WillResume(lldb::StateType resume_state) override;

    void
    DidResume() override
    {
        if (m_backing_thread_sp)
            m_backing_thread_sp->DidResume();
    }
    
    lldb::user_id_t
    GetProtocolID() const override
    {
        if (m_backing_thread_sp)
            return m_backing_thread_sp->GetProtocolID();
        return Thread::GetProtocolID();
    }

    void
    RefreshStateAfterStop() override;
    
    lldb::ValueObjectSP &
    GetValueObject ()
    {
        return m_thread_info_valobj_sp;
    }
    
    void
    ClearStackFrames() override;

    void
    ClearBackingThread() override
    {
        m_backing_thread_sp.reset();
    }

    bool
    SetBackingThread(const lldb::ThreadSP &thread_sp) override
    {
        //printf ("Thread 0x%llx is being backed by thread 0x%llx\n", GetID(), thread_sp->GetID());
        m_backing_thread_sp = thread_sp;
        return (bool)thread_sp;
    }
    
    lldb::ThreadSP
    GetBackingThread() const override
    {
        return m_backing_thread_sp;
    }

protected:
    bool
    IsOperatingSystemPluginThread() const override
    {
        return true;
    }
    
    // If this memory thread is actually represented by a thread from the
    // lldb_private::Process subclass, then fill in the thread here and
    // all APIs will be routed through this thread object. If m_backing_thread_sp
    // is empty, then this thread is simply in memory with no representation
    // through the process plug-in.
    lldb::ThreadSP m_backing_thread_sp;
    lldb::ValueObjectSP m_thread_info_valobj_sp;
    std::string m_name;
    std::string m_queue;
    lldb::addr_t m_register_data_addr;

private:
    DISALLOW_COPY_AND_ASSIGN (ThreadMemory);
};

#endif // liblldb_ThreadMemory_h_
OpenPOWER on IntegriCloud