aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Target/ThreadSpec.h
blob: e0d30934f373768f97cdc744690a749480d1f3a8 (plain) (blame)
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
147
148
149
150
151
152
153
154
155
//===-- ThreadSpec.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_ThreadSpec_h_
#define liblldb_ThreadSpec_h_

#include <map>
#include <string>

#include "lldb/lldb-private.h"

namespace lldb_private {

// Note: For now the thread spec has only fixed elements -
//   Thread ID
//   Thread Index
//   Thread Name
//   Thread Queue Name
//
//  But if we need more generality, we can hang a key/value map off of this structure.
//  That's why the thread matches spec test is done as a virtual method in Thread::MatchesSpec,
//  since it is the native thread that would know how to interpret the keys.
//  I was going to do the Queue Name this way out of sheer orneriness, but that seems a
//  sufficiently general concept, so I put it in here on its own.

class ThreadSpec
{
public:
    ThreadSpec ();
    
    ThreadSpec (const ThreadSpec &rhs);
    
    const ThreadSpec &
    operator=(const ThreadSpec &rhs);
    
    void
    SetIndex (uint32_t index)
    {
        m_index = index;
    }
    
    void
    SetTID   (lldb::tid_t tid)
    {
        m_tid = tid;
    }
    
    void
    SetName (const char *name)
    {
        m_name = name;
    }
    
    void 
    SetQueueName (const char *queue_name)
    {
        m_queue_name = queue_name;
    }

    uint32_t
    GetIndex () const
    {
        return m_index;
    }
    
    lldb::tid_t 
    GetTID () const
    {
        return m_tid;
    }

    const char *
    GetName () const;
    
    const char *
    GetQueueName () const;
    
    bool
    TIDMatches (lldb::tid_t thread_id) const
    {
        if (m_tid == LLDB_INVALID_THREAD_ID || thread_id == LLDB_INVALID_THREAD_ID)
            return true;
        else
            return thread_id == m_tid;
    }
        
    bool
    TIDMatches (Thread &thread) const;
    
    bool 
    IndexMatches (uint32_t index) const
    {
        if (m_index == UINT32_MAX || index == UINT32_MAX)
            return true;
        else
            return index == m_index;
    }
    
    bool 
    IndexMatches (Thread &thread) const;
    
    bool 
    NameMatches (const char *name) const
    {
        if (m_name.empty())
            return true;
        else if (name == NULL)
            return false;
        else
            return m_name == name;
    }
    
    bool 
    NameMatches (Thread &thread) const;
    
    bool 
    QueueNameMatches (const char *queue_name) const
    {
        if (m_queue_name.empty())
            return true;
        else if (queue_name == NULL)
            return false;
        else
            return m_queue_name == queue_name;
    }
    
    bool 
    QueueNameMatches (Thread &thread) const;
    
    bool
    ThreadPassesBasicTests (Thread &thread) const;
    
    bool
    HasSpecification () const;
    
    void
    GetDescription (Stream *s, lldb::DescriptionLevel level) const;

protected:
private:
    uint32_t m_index;
    lldb::tid_t m_tid;
    std::string m_name;
    std::string m_queue_name;
};

} // namespace lldb_private

#endif  // liblldb_ThreadSpec_h_