Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:43

0001 //===-- BreakpointName.h ----------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_BREAKPOINT_BREAKPOINTNAME_H
0010 #define LLDB_BREAKPOINT_BREAKPOINTNAME_H
0011 
0012 #include <memory>
0013 #include <string>
0014 #include <unordered_set>
0015 #include <vector>
0016 
0017 #include "lldb/Breakpoint/BreakpointID.h"
0018 #include "lldb/Breakpoint/BreakpointLocationCollection.h"
0019 #include "lldb/Breakpoint/BreakpointLocationList.h"
0020 #include "lldb/Breakpoint/BreakpointOptions.h"
0021 #include "lldb/Breakpoint/Stoppoint.h"
0022 #include "lldb/Core/SearchFilter.h"
0023 #include "lldb/Utility/Event.h"
0024 #include "lldb/Utility/Flags.h"
0025 #include "lldb/Utility/StringList.h"
0026 #include "lldb/Utility/StructuredData.h"
0027 
0028 namespace lldb_private {
0029 
0030 class BreakpointName {
0031 public:
0032   class Permissions
0033   {
0034   public:
0035   
0036     enum PermissionKinds { listPerm = 0, disablePerm = 1, 
0037                        deletePerm = 2, allPerms = 3 };
0038 
0039     Permissions(bool in_list, bool in_disable, bool in_delete) 
0040     {
0041       m_permissions[listPerm]    = in_list;
0042       m_permissions[disablePerm] = in_disable;
0043       m_permissions[deletePerm]  = in_delete;
0044       m_set_mask.Set(permissions_mask[allPerms]);
0045     }
0046     
0047     Permissions(const Permissions &rhs)
0048     {
0049       m_permissions[listPerm]    = rhs.m_permissions[listPerm];
0050       m_permissions[disablePerm] = rhs.m_permissions[disablePerm];
0051       m_permissions[deletePerm]  = rhs.m_permissions[deletePerm];
0052       m_set_mask = rhs.m_set_mask;
0053     }
0054     
0055     Permissions() 
0056     {
0057       m_permissions[listPerm]    = true;
0058       m_permissions[disablePerm] = true;
0059       m_permissions[deletePerm]  = true;
0060       m_set_mask.Clear();
0061     }
0062     
0063     const Permissions &operator= (const Permissions &rhs)
0064     {
0065       if (this != &rhs) {
0066         m_permissions[listPerm]    = rhs.m_permissions[listPerm];
0067         m_permissions[disablePerm] = rhs.m_permissions[disablePerm];
0068         m_permissions[deletePerm]  = rhs.m_permissions[deletePerm];
0069         m_set_mask = rhs.m_set_mask;
0070       }
0071       return *this;
0072     }
0073     
0074     void Clear() {
0075       *this = Permissions();
0076     }
0077     
0078     // Merge the permissions from incoming into this set of permissions. Only
0079     // merge set permissions, and most restrictive permission wins.
0080     void MergeInto(const Permissions &incoming)
0081     {
0082       MergePermission(incoming, listPerm);
0083       MergePermission(incoming, disablePerm);
0084       MergePermission(incoming, deletePerm);
0085     }
0086 
0087     bool GetAllowList() const { return GetPermission(listPerm); }
0088     bool SetAllowList(bool value) { return SetPermission(listPerm, value); }
0089     
0090     bool GetAllowDelete() const { return GetPermission(deletePerm); }
0091     bool SetAllowDelete(bool value) { return SetPermission(deletePerm, value); }
0092     
0093     bool GetAllowDisable() const { return GetPermission(disablePerm); }
0094     bool SetAllowDisable(bool value) { return SetPermission(disablePerm, 
0095                                                             value); }
0096 
0097     bool GetPermission(enum PermissionKinds permission) const
0098     {
0099       return m_permissions[permission];
0100     }
0101 
0102     bool GetDescription(Stream *s, lldb::DescriptionLevel level);
0103 
0104     bool IsSet(enum PermissionKinds permission) const
0105     {
0106       return m_set_mask.Test(permissions_mask[permission]);
0107     }
0108     
0109     bool AnySet() {
0110       return m_set_mask.AnySet(permissions_mask[allPerms]);
0111     }
0112     
0113   private:
0114     static const Flags::ValueType permissions_mask[allPerms + 1];
0115     
0116     bool m_permissions[allPerms];
0117     Flags m_set_mask;
0118     
0119     bool SetPermission(enum PermissionKinds permission, bool value)
0120     {
0121       bool old_value = m_permissions[permission];
0122       m_permissions[permission] = value;
0123       m_set_mask.Set(permissions_mask[permission]);
0124       return old_value;
0125     }
0126     
0127     // If either side disallows the permission, the resultant disallows it.
0128     void MergePermission(const Permissions &incoming, 
0129                          enum PermissionKinds permission)
0130     {
0131       if (incoming.IsSet(permission))
0132       {
0133         SetPermission(permission, !(m_permissions[permission] |
0134             incoming.m_permissions[permission]));
0135       }
0136     }
0137   };
0138   
0139   BreakpointName(ConstString name, const char *help = nullptr) :
0140       m_name(name), m_options(false)
0141    {
0142      SetHelp(help);
0143    }
0144   
0145   BreakpointName(const BreakpointName &rhs) :
0146       m_name(rhs.m_name), m_options(rhs.m_options),
0147       m_permissions(rhs.m_permissions), m_help(rhs.m_help)
0148   {}
0149       
0150   ConstString GetName() const { return m_name; }
0151   BreakpointOptions &GetOptions() { return m_options; }
0152   const BreakpointOptions &GetOptions() const { return m_options; }
0153   
0154   void SetOptions(const BreakpointOptions &options) {
0155     m_options = options;
0156   }
0157   
0158   Permissions &GetPermissions() { return m_permissions; }
0159   const Permissions &GetPermissions() const { return m_permissions; }
0160   void SetPermissions(const Permissions &permissions) {
0161     m_permissions = permissions;
0162   }
0163   
0164   bool GetPermission(Permissions::PermissionKinds permission) const
0165   {
0166     return m_permissions.GetPermission(permission);
0167   }
0168   
0169   void SetHelp(const char *description)
0170   {
0171     if (description)
0172       m_help.assign(description);
0173     else
0174       m_help.clear();
0175   }
0176   
0177   const char *GetHelp()
0178   {
0179     return m_help.c_str();
0180   }
0181   
0182   // Returns true if any options were set in the name
0183   bool GetDescription(Stream *s, lldb::DescriptionLevel level);
0184   
0185   void ConfigureBreakpoint(lldb::BreakpointSP bp_sp);
0186   
0187 private:
0188   ConstString        m_name;
0189   BreakpointOptions  m_options;
0190   Permissions        m_permissions;
0191   std::string        m_help;
0192 };
0193 
0194 } // namespace lldb_private
0195 
0196 #endif // LLDB_BREAKPOINT_BREAKPOINTNAME_H