Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Breakpoint/BreakpointName.h
Line
Count
Source (jump to first uncovered line)
1
//===-- BreakpointName.h --------------------------------------------*- C++ -*-===//
2
//
3
// 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
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLDB_BREAKPOINT_BREAKPOINTNAME_H
10
#define LLDB_BREAKPOINT_BREAKPOINTNAME_H
11
12
#include <memory>
13
#include <string>
14
#include <unordered_set>
15
#include <vector>
16
17
#include "lldb/Breakpoint/BreakpointID.h"
18
#include "lldb/Breakpoint/BreakpointLocationCollection.h"
19
#include "lldb/Breakpoint/BreakpointLocationList.h"
20
#include "lldb/Breakpoint/BreakpointOptions.h"
21
#include "lldb/Breakpoint/Stoppoint.h"
22
#include "lldb/Core/SearchFilter.h"
23
#include "lldb/Utility/Event.h"
24
#include "lldb/Utility/Flags.h"
25
#include "lldb/Utility/StringList.h"
26
#include "lldb/Utility/StructuredData.h"
27
28
namespace lldb_private {
29
30
class BreakpointName {
31
public:
32
  class Permissions
33
  {
34
  public:
35
  
36
    enum PermissionKinds { listPerm = 0, disablePerm = 1, 
37
                       deletePerm = 2, allPerms = 3 };
38
39
    Permissions(bool in_list, bool in_disable, bool in_delete) 
40
0
    {
41
0
      m_permissions[listPerm]    = in_list;
42
0
      m_permissions[disablePerm] = in_disable;
43
0
      m_permissions[deletePerm]  = in_delete;
44
0
      m_set_mask.Set(permissions_mask[allPerms]);
45
0
    }
46
    
47
    Permissions(const Permissions &rhs)
48
1
    {
49
1
      m_permissions[listPerm]    = rhs.m_permissions[listPerm];
50
1
      m_permissions[disablePerm] = rhs.m_permissions[disablePerm];
51
1
      m_permissions[deletePerm]  = rhs.m_permissions[deletePerm];
52
1
      m_set_mask = rhs.m_set_mask;
53
1
    }
54
    
55
    Permissions() 
56
21.5k
    {
57
21.5k
      m_permissions[listPerm]    = true;
58
21.5k
      m_permissions[disablePerm] = true;
59
21.5k
      m_permissions[deletePerm]  = true;
60
21.5k
      m_set_mask.Clear();
61
21.5k
    }
62
    
63
    const Permissions &operator= (const Permissions &rhs)
64
0
    {
65
0
      if (this != &rhs) {
66
0
        m_permissions[listPerm]    = rhs.m_permissions[listPerm];
67
0
        m_permissions[disablePerm] = rhs.m_permissions[disablePerm];
68
0
        m_permissions[deletePerm]  = rhs.m_permissions[deletePerm];
69
0
        m_set_mask = rhs.m_set_mask;
70
0
      }
71
0
      return *this;
72
0
    }
73
    
74
0
    void Clear() {
75
0
      *this = Permissions();
76
0
    }
77
    
78
    // Merge the permissions from incoming into this set of permissions. Only
79
    // merge set permissions, and most restrictive permission wins.
80
    void MergeInto(const Permissions &incoming)
81
24
    {
82
24
      MergePermission(incoming, listPerm);
83
24
      MergePermission(incoming, disablePerm);
84
24
      MergePermission(incoming, deletePerm);
85
24
    }
86
87
223
    bool GetAllowList() const { return GetPermission(listPerm); }
88
2
    bool SetAllowList(bool value) { return SetPermission(listPerm, value); }
89
    
90
48
    bool GetAllowDelete() const { return GetPermission(deletePerm); }
91
2
    bool SetAllowDelete(bool value) { return SetPermission(deletePerm, value); }
92
    
93
11
    bool GetAllowDisable() const { return GetPermission(disablePerm); }
94
2
    bool SetAllowDisable(bool value) { return SetPermission(disablePerm, 
95
2
                                                            value); }
96
97
    bool GetPermission(enum PermissionKinds permission) const
98
288
    {
99
288
      return m_permissions[permission];
100
288
    }
101
102
    bool GetDescription(Stream *s, lldb::DescriptionLevel level);
103
104
    bool IsSet(enum PermissionKinds permission) const
105
72
    {
106
72
      return m_set_mask.Test(permissions_mask[permission]);
107
72
    }
108
    
109
0
    bool AnySet() {
110
0
      return m_set_mask.AnySet(permissions_mask[allPerms]);
111
0
    }
112
    
113
  private:
114
    static const Flags::ValueType permissions_mask[allPerms + 1];
115
    
116
    bool m_permissions[allPerms];
117
    Flags m_set_mask;
118
    
119
    bool SetPermission(enum PermissionKinds permission, bool value)
120
15
    {
121
15
      bool old_value = m_permissions[permission];
122
15
      m_permissions[permission] = value;
123
15
      m_set_mask.Set(permissions_mask[permission]);
124
15
      return old_value;
125
15
    }
126
    
127
    // If either side disallows the permission, the resultant disallows it.
128
    void MergePermission(const Permissions &incoming, 
129
                         enum PermissionKinds permission)
130
72
    {
131
72
      if (incoming.IsSet(permission))
132
9
      {
133
9
        SetPermission(permission, !(m_permissions[permission] |
134
9
            incoming.m_permissions[permission]));
135
9
      }
136
72
    }
137
  };
138
  
139
  BreakpointName(ConstString name, const char *help = nullptr) :
140
      m_name(name), m_options(false)
141
23
   {
142
23
     SetHelp(help);
143
23
   }
144
      
145
  BreakpointName(ConstString name,
146
                 BreakpointOptions &options,
147
                 const Permissions &permissions = Permissions(),
148
                 const char *help = nullptr) :
149
      m_name(name), m_options(options), 
150
0
      m_permissions(permissions) {
151
0
        SetHelp(help);
152
0
  };
153
  
154
  BreakpointName(const BreakpointName &rhs) :
155
      m_name(rhs.m_name), m_options(rhs.m_options),
156
      m_permissions(rhs.m_permissions), m_help(rhs.m_help)
157
1
  {}
158
  
159
  BreakpointName(ConstString name, const Breakpoint &bkpt,
160
                 const char *help);
161
      
162
14
  ConstString GetName() const { return m_name; }
163
59
  BreakpointOptions &GetOptions() { return m_options; }
164
3
  const BreakpointOptions &GetOptions() const { return m_options; }
165
  
166
0
  void SetOptions(const BreakpointOptions &options) {
167
0
    m_options = options;
168
0
  }
169
  
170
29
  Permissions &GetPermissions() { return m_permissions; }
171
0
  const Permissions &GetPermissions() const { return m_permissions; }
172
0
  void SetPermissions(const Permissions &permissions) {
173
0
    m_permissions = permissions;
174
0
  }
175
  
176
  bool GetPermission(Permissions::PermissionKinds permission) const
177
6
  {
178
6
    return m_permissions.GetPermission(permission);
179
6
  }
180
  
181
  void SetHelp(const char *description)
182
25
  {
183
25
    if (description)
184
2
      m_help.assign(description);
185
23
    else
186
23
      m_help.clear();
187
25
  }
188
  
189
  const char *GetHelp()
190
2
  {
191
2
    return m_help.c_str();
192
2
  }
193
  
194
  // Returns true if any options were set in the name
195
  bool GetDescription(Stream *s, lldb::DescriptionLevel level);
196
  
197
  void ConfigureBreakpoint(lldb::BreakpointSP bp_sp);
198
  
199
private:
200
  ConstString        m_name;
201
  BreakpointOptions  m_options;
202
  Permissions        m_permissions;
203
  std::string        m_help;
204
};
205
206
} // namespace lldb_private
207
208
#endif // LLDB_BREAKPOINT_BREAKPOINTNAME_H