1 //===-- BreakpointID.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
14 // Other libraries and framework includes
16 #include "lldb/Breakpoint/Breakpoint.h"
17 #include "lldb/Breakpoint/BreakpointID.h"
18 #include "lldb/Utility/Status.h"
19 #include "lldb/Utility/Stream.h"
22 using namespace lldb_private;
24 BreakpointID::BreakpointID(break_id_t bp_id, break_id_t loc_id)
25 : m_break_id(bp_id), m_location_id(loc_id) {}
27 BreakpointID::~BreakpointID() = default;
29 static llvm::StringRef g_range_specifiers[] = {"-", "to", "To", "TO"};
31 // Tells whether or not STR is valid to use between two strings representing
33 // indicate a range of breakpoint IDs. This is broken out into a separate
34 // function so that we can
35 // easily change or add to the format for specifying ID ranges at a later date.
37 bool BreakpointID::IsRangeIdentifier(llvm::StringRef str) {
38 for (auto spec : g_range_specifiers) {
46 bool BreakpointID::IsValidIDExpression(llvm::StringRef str) {
47 return BreakpointID::ParseCanonicalReference(str).hasValue();
50 llvm::ArrayRef<llvm::StringRef> BreakpointID::GetRangeSpecifiers() {
51 return llvm::makeArrayRef(g_range_specifiers);
54 void BreakpointID::GetDescription(Stream *s, lldb::DescriptionLevel level) {
55 if (level == eDescriptionLevelVerbose)
56 s->Printf("%p BreakpointID:", static_cast<void *>(this));
58 if (m_break_id == LLDB_INVALID_BREAK_ID)
59 s->PutCString("<invalid>");
60 else if (m_location_id == LLDB_INVALID_BREAK_ID)
61 s->Printf("%i", m_break_id);
63 s->Printf("%i.%i", m_break_id, m_location_id);
66 void BreakpointID::GetCanonicalReference(Stream *s, break_id_t bp_id,
68 if (bp_id == LLDB_INVALID_BREAK_ID)
69 s->PutCString("<invalid>");
70 else if (loc_id == LLDB_INVALID_BREAK_ID)
71 s->Printf("%i", bp_id);
73 s->Printf("%i.%i", bp_id, loc_id);
76 llvm::Optional<BreakpointID>
77 BreakpointID::ParseCanonicalReference(llvm::StringRef input) {
79 break_id_t loc_id = LLDB_INVALID_BREAK_ID;
84 // If it doesn't start with an integer, it's not valid.
85 if (input.consumeInteger(0, bp_id))
88 // period is optional, but if it exists, it must be followed by a number.
89 if (input.consume_front(".")) {
90 if (input.consumeInteger(0, loc_id))
94 // And at the end, the entire string must have been consumed.
98 return BreakpointID(bp_id, loc_id);
101 bool BreakpointID::StringIsBreakpointName(llvm::StringRef str, Status &error) {
105 error.SetErrorStringWithFormat("Empty breakpoint names are not allowed");
109 // First character must be a letter or _
110 if (!isalpha(str[0]) && str[0] != '_')
112 error.SetErrorStringWithFormat("Breakpoint names must start with a "
113 "character or underscore: %s",
118 // Cannot contain ., -, or space.
119 if (str.find_first_of(".- ") != llvm::StringRef::npos) {
120 error.SetErrorStringWithFormat("Breakpoint names cannot contain "
121 "'.' or '-': \"%s\"",