1 //===-- BreakpointID.cpp ----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 11 // C Includes 12 // C++ Includes 13 // Other libraries and framework includes 14 // Project includes 15 16 #include "lldb/Breakpoint/BreakpointID.h" 17 #include "lldb/Breakpoint/Breakpoint.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 BreakpointID::BreakpointID (break_id_t bp_id, break_id_t loc_id) : 23 m_break_id (bp_id), 24 m_location_id (loc_id) 25 { 26 } 27 28 BreakpointID::~BreakpointID () 29 { 30 } 31 32 const char *BreakpointID::g_range_specifiers[] = { "-", "to", "To", "TO", NULL }; 33 34 // Tells whether or not STR is valid to use between two strings representing breakpoint IDs, to 35 // indicate a range of breakpoint IDs. This is broken out into a separate function so that we can 36 // easily change or add to the format for specifying ID ranges at a later date. 37 38 bool 39 BreakpointID::IsRangeIdentifier (const char *str) 40 { 41 int specifier_count = 0; 42 for (int i = 0; g_range_specifiers[i] != NULL; ++i) 43 ++specifier_count; 44 45 for (int i = 0; i < specifier_count; ++i) 46 { 47 if (strcmp (g_range_specifiers[i], str) == 0) 48 return true; 49 } 50 51 return false; 52 } 53 54 bool 55 BreakpointID::IsValidIDExpression (const char *str) 56 { 57 break_id_t bp_id; 58 break_id_t loc_id; 59 BreakpointID::ParseCanonicalReference (str, &bp_id, &loc_id); 60 61 if (bp_id == LLDB_INVALID_BREAK_ID) 62 return false; 63 else 64 return true; 65 } 66 67 void 68 BreakpointID::GetDescription (Stream *s, lldb::DescriptionLevel level) 69 { 70 if (level == eDescriptionLevelVerbose) 71 s->Printf("%p BreakpointID:", this); 72 73 if (m_break_id == LLDB_INVALID_BREAK_ID) 74 s->PutCString ("<invalid>"); 75 else if (m_location_id == LLDB_INVALID_BREAK_ID) 76 s->Printf("%i", m_break_id); 77 else 78 s->Printf("%i.%i", m_break_id, m_location_id); 79 } 80 81 void 82 BreakpointID::GetCanonicalReference (Stream *s, break_id_t bp_id, break_id_t loc_id) 83 { 84 if (bp_id == LLDB_INVALID_BREAK_ID) 85 s->PutCString ("<invalid>"); 86 else if (loc_id == LLDB_INVALID_BREAK_ID) 87 s->Printf("%i", bp_id); 88 else 89 s->Printf("%i.%i", bp_id, loc_id); 90 } 91 92 bool 93 BreakpointID::ParseCanonicalReference (const char *input, break_id_t *break_id_ptr, break_id_t *break_loc_id_ptr) 94 { 95 *break_id_ptr = LLDB_INVALID_BREAK_ID; 96 *break_loc_id_ptr = LLDB_INVALID_BREAK_ID; 97 98 if (input == NULL || *input == '\0') 99 return false; 100 101 const char *format = "%i%n.%i%n"; 102 int chars_consumed_1 = 0; 103 int chars_consumed_2 = 0; 104 int n_items_parsed = ::sscanf (input, 105 format, 106 break_id_ptr, // %i parse the breakpoint ID 107 &chars_consumed_1, // %n gets the number of characters parsed so far 108 break_loc_id_ptr, // %i parse the breakpoint location ID 109 &chars_consumed_2); // %n gets the number of characters parsed so far 110 111 if ((n_items_parsed == 1 && input[chars_consumed_1] == '\0') || 112 (n_items_parsed == 2 && input[chars_consumed_2] == '\0')) 113 return true; 114 115 // Badly formatted canonical reference. 116 *break_id_ptr = LLDB_INVALID_BREAK_ID; 117 *break_loc_id_ptr = LLDB_INVALID_BREAK_ID; 118 return false; 119 } 120 121