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 //===----------------------------------------------------------------------===//
15 // Other libraries and framework includes
18 #include "lldb/Breakpoint/BreakpointID.h"
19 #include "lldb/Breakpoint/Breakpoint.h"
20 #include "lldb/Core/Stream.h"
23 using namespace lldb_private;
25 BreakpointID::BreakpointID (break_id_t bp_id, break_id_t loc_id) :
27 m_location_id (loc_id)
31 BreakpointID::~BreakpointID ()
35 const char *BreakpointID::g_range_specifiers[] = { "-", "to", "To", "TO", NULL };
37 // Tells whether or not STR is valid to use between two strings representing breakpoint IDs, to
38 // indicate a range of breakpoint IDs. This is broken out into a separate function so that we can
39 // easily change or add to the format for specifying ID ranges at a later date.
42 BreakpointID::IsRangeIdentifier (const char *str)
44 int specifier_count = 0;
45 for (int i = 0; g_range_specifiers[i] != NULL; ++i)
48 for (int i = 0; i < specifier_count; ++i)
50 if (strcmp (g_range_specifiers[i], str) == 0)
58 BreakpointID::IsValidIDExpression (const char *str)
62 BreakpointID::ParseCanonicalReference (str, &bp_id, &loc_id);
64 if (bp_id == LLDB_INVALID_BREAK_ID)
71 BreakpointID::GetDescription (Stream *s, lldb::DescriptionLevel level)
73 if (level == eDescriptionLevelVerbose)
74 s->Printf("%p BreakpointID:", this);
76 if (m_break_id == LLDB_INVALID_BREAK_ID)
77 s->PutCString ("<invalid>");
78 else if (m_location_id == LLDB_INVALID_BREAK_ID)
79 s->Printf("%i", m_break_id);
81 s->Printf("%i.%i", m_break_id, m_location_id);
85 BreakpointID::GetCanonicalReference (Stream *s, break_id_t bp_id, break_id_t loc_id)
87 if (bp_id == LLDB_INVALID_BREAK_ID)
88 s->PutCString ("<invalid>");
89 else if (loc_id == LLDB_INVALID_BREAK_ID)
90 s->Printf("%i", bp_id);
92 s->Printf("%i.%i", bp_id, loc_id);
96 BreakpointID::ParseCanonicalReference (const char *input, break_id_t *break_id_ptr, break_id_t *break_loc_id_ptr)
98 *break_id_ptr = LLDB_INVALID_BREAK_ID;
99 *break_loc_id_ptr = LLDB_INVALID_BREAK_ID;
101 if (input == NULL || *input == '\0')
104 const char *format = "%i%n.%i%n";
105 int chars_consumed_1 = 0;
106 int chars_consumed_2 = 0;
107 int n_items_parsed = ::sscanf (input,
109 break_id_ptr, // %i parse the breakpoint ID
110 &chars_consumed_1, // %n gets the number of characters parsed so far
111 break_loc_id_ptr, // %i parse the breakpoint location ID
112 &chars_consumed_2); // %n gets the number of characters parsed so far
114 if ((n_items_parsed == 1 && input[chars_consumed_1] == '\0') ||
115 (n_items_parsed == 2 && input[chars_consumed_2] == '\0'))
118 // Badly formatted canonical reference.
119 *break_id_ptr = LLDB_INVALID_BREAK_ID;
120 *break_loc_id_ptr = LLDB_INVALID_BREAK_ID;