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