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