xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Breakpoint/BreakpointID.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===-- BreakpointID.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_BREAKPOINTID_H
10 #define LLDB_BREAKPOINT_BREAKPOINTID_H
11 
12 #include "lldb/lldb-private.h"
13 
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/StringRef.h"
16 #include <optional>
17 
18 namespace lldb_private {
19 
20 // class BreakpointID
21 
22 class BreakpointID {
23 public:
24   BreakpointID(lldb::break_id_t bp_id = LLDB_INVALID_BREAK_ID,
25                lldb::break_id_t loc_id = LLDB_INVALID_BREAK_ID);
26 
27   virtual ~BreakpointID();
28 
29   bool operator==(BreakpointID rhs) const {
30     return m_break_id == rhs.m_break_id && m_location_id == rhs.m_location_id;
31   }
32 
GetBreakpointID()33   lldb::break_id_t GetBreakpointID() const { return m_break_id; }
34 
GetLocationID()35   lldb::break_id_t GetLocationID() const { return m_location_id; }
36 
SetID(lldb::break_id_t bp_id,lldb::break_id_t loc_id)37   void SetID(lldb::break_id_t bp_id, lldb::break_id_t loc_id) {
38     m_break_id = bp_id;
39     m_location_id = loc_id;
40   }
41 
SetBreakpointID(lldb::break_id_t bp_id)42   void SetBreakpointID(lldb::break_id_t bp_id) { m_break_id = bp_id; }
43 
SetBreakpointLocationID(lldb::break_id_t loc_id)44   void SetBreakpointLocationID(lldb::break_id_t loc_id) {
45     m_location_id = loc_id;
46   }
47 
48   void GetDescription(Stream *s, lldb::DescriptionLevel level);
49 
50   static bool IsRangeIdentifier(llvm::StringRef str);
51   static bool IsValidIDExpression(llvm::StringRef str);
52   static llvm::ArrayRef<llvm::StringRef> GetRangeSpecifiers();
53 
54   /// Takes an input string containing the description of a breakpoint or
55   /// breakpoint and location and returns a BreakpointID filled out with
56   /// the proper id and location.
57   ///
58   /// \param[in] input
59   ///     A string containing JUST the breakpoint description.
60   /// \return
61   ///     If \p input was not a valid breakpoint ID string, returns
62   ///     \b std::nullopt.  Otherwise returns a BreakpointID with members filled
63   ///     out accordingly.
64   static std::optional<BreakpointID>
65   ParseCanonicalReference(llvm::StringRef input);
66 
67   /// Takes an input string and checks to see whether it is a breakpoint name.
68   /// If it is a mal-formed breakpoint name, error will be set to an appropriate
69   /// error string.
70   ///
71   /// \param[in] str
72   ///     A string containing JUST the breakpoint description.
73   /// \param[out] error
74   ///     If the name is a well-formed breakpoint name, set to success,
75   ///     otherwise set to an error.
76   /// \return
77   ///     \b true if the name is a breakpoint name (as opposed to an ID or
78   ///     range) false otherwise.
79   static bool StringIsBreakpointName(llvm::StringRef str, Status &error);
80 
81   /// Takes a breakpoint ID and the breakpoint location id and returns
82   /// a string containing the canonical description for the breakpoint
83   /// or breakpoint location.
84   ///
85   /// \param[out] break_id
86   ///     This is the break id.
87   ///
88   /// \param[out] break_loc_id
89   ///     This is breakpoint location id, or LLDB_INVALID_BREAK_ID is no
90   ///     location is to be specified.
91   static void GetCanonicalReference(Stream *s, lldb::break_id_t break_id,
92                                     lldb::break_id_t break_loc_id);
93 
94 protected:
95   lldb::break_id_t m_break_id;
96   lldb::break_id_t m_location_id;
97 };
98 
99 } // namespace lldb_private
100 
101 #endif // LLDB_BREAKPOINT_BREAKPOINTID_H
102