Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- BreakpointIDList.cpp ----------------------------------------------===// |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 9 | #include "lldb/lldb-enumerations.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 11 | |
| 12 | #include "lldb/Breakpoint/Breakpoint.h" |
| 13 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 14 | #include "lldb/Interpreter/CommandReturnObject.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Target/Target.h" |
Pavel Labath | 145d95c | 2018-04-17 18:53:35 +0000 | [diff] [blame] | 16 | #include "lldb/Utility/Args.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | // class BreakpointIDList |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | BreakpointIDList::BreakpointIDList() |
| 24 | : m_invalid_id(LLDB_INVALID_BREAK_ID, LLDB_INVALID_BREAK_ID) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | |
Eugene Zelenko | 16fd751 | 2015-10-30 18:50:12 +0000 | [diff] [blame] | 26 | BreakpointIDList::~BreakpointIDList() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | |
Jim Ingham | db30877 | 2016-09-14 19:05:27 +0000 | [diff] [blame] | 28 | size_t BreakpointIDList::GetSize() const { return m_breakpoint_ids.size(); } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 29 | |
Jim Ingham | db30877 | 2016-09-14 19:05:27 +0000 | [diff] [blame] | 30 | const BreakpointID & |
| 31 | BreakpointIDList::GetBreakpointIDAtIndex(size_t index) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | return ((index < m_breakpoint_ids.size()) ? m_breakpoint_ids[index] |
| 33 | : m_invalid_id); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | bool BreakpointIDList::RemoveBreakpointIDAtIndex(size_t index) { |
| 37 | if (index >= m_breakpoint_ids.size()) |
| 38 | return false; |
| 39 | |
| 40 | m_breakpoint_ids.erase(m_breakpoint_ids.begin() + index); |
| 41 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | void BreakpointIDList::Clear() { m_breakpoint_ids.clear(); } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | bool BreakpointIDList::AddBreakpointID(BreakpointID bp_id) { |
| 47 | m_breakpoint_ids.push_back(bp_id); |
| 48 | |
| 49 | return true; // We don't do any verification in this function, so always |
| 50 | // return true. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | bool BreakpointIDList::AddBreakpointID(const char *bp_id_str) { |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 54 | auto bp_id = BreakpointID::ParseCanonicalReference(bp_id_str); |
| 55 | if (!bp_id.hasValue()) |
| 56 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 58 | m_breakpoint_ids.push_back(*bp_id); |
| 59 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Jim Ingham | db30877 | 2016-09-14 19:05:27 +0000 | [diff] [blame] | 62 | bool BreakpointIDList::FindBreakpointID(BreakpointID &bp_id, |
| 63 | size_t *position) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 64 | for (size_t i = 0; i < m_breakpoint_ids.size(); ++i) { |
| 65 | BreakpointID tmp_id = m_breakpoint_ids[i]; |
| 66 | if (tmp_id.GetBreakpointID() == bp_id.GetBreakpointID() && |
| 67 | tmp_id.GetLocationID() == bp_id.GetLocationID()) { |
| 68 | *position = i; |
| 69 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 73 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | bool BreakpointIDList::FindBreakpointID(const char *bp_id_str, |
Jim Ingham | db30877 | 2016-09-14 19:05:27 +0000 | [diff] [blame] | 77 | size_t *position) const { |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 78 | auto bp_id = BreakpointID::ParseCanonicalReference(bp_id_str); |
| 79 | if (!bp_id.hasValue()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | return false; |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 81 | |
| 82 | return FindBreakpointID(*bp_id, position); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Pavel Labath | 16662f3 | 2018-06-20 08:12:50 +0000 | [diff] [blame] | 85 | void BreakpointIDList::InsertStringArray( |
| 86 | llvm::ArrayRef<const char *> string_array, CommandReturnObject &result) { |
| 87 | if(string_array.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | return; |
| 89 | |
Pavel Labath | 16662f3 | 2018-06-20 08:12:50 +0000 | [diff] [blame] | 90 | for (const char *str : string_array) { |
| 91 | auto bp_id = BreakpointID::ParseCanonicalReference(str); |
Zachary Turner | 0d4f23c | 2016-10-05 18:40:51 +0000 | [diff] [blame] | 92 | if (bp_id.hasValue()) |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 93 | m_breakpoint_ids.push_back(*bp_id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | } |
| 95 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 98 | // This function takes OLD_ARGS, which is usually the result of breaking the |
| 99 | // command string arguments into |
| 100 | // an array of space-separated strings, and searches through the arguments for |
| 101 | // any breakpoint ID range specifiers. |
| 102 | // Any string in the array that is not part of an ID range specifier is copied |
| 103 | // directly into NEW_ARGS. If any |
| 104 | // ID range specifiers are found, the range is interpreted and a list of |
| 105 | // canonical breakpoint IDs corresponding to |
| 106 | // all the current breakpoints and locations in the range are added to |
| 107 | // NEW_ARGS. When this function is done, |
| 108 | // NEW_ARGS should be a copy of OLD_ARGS, with and ID range specifiers replaced |
| 109 | // by the members of the range. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target, |
| 112 | bool allow_locations, |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 113 | BreakpointName::Permissions |
| 114 | ::PermissionKinds purpose, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | CommandReturnObject &result, |
| 116 | Args &new_args) { |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 117 | llvm::StringRef range_from; |
| 118 | llvm::StringRef range_to; |
| 119 | llvm::StringRef current_arg; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 120 | std::set<std::string> names_found; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 121 | |
Zachary Turner | d6a2475 | 2016-11-22 17:10:15 +0000 | [diff] [blame] | 122 | for (size_t i = 0; i < old_args.size(); ++i) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | bool is_range = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | |
Raphael Isemann | 0d9a201 | 2019-09-13 11:26:48 +0000 | [diff] [blame] | 125 | current_arg = old_args[i].ref(); |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 126 | if (!allow_locations && current_arg.contains('.')) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 127 | result.AppendErrorWithFormat( |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 128 | "Breakpoint locations not allowed, saw location: %s.", |
| 129 | current_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | new_args.Clear(); |
| 131 | return; |
| 132 | } |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 133 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 134 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 135 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 136 | std::tie(range_from, range_to) = |
| 137 | BreakpointIDList::SplitIDRangeExpression(current_arg); |
| 138 | if (!range_from.empty() && !range_to.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | is_range = true; |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 140 | } else if (BreakpointID::StringIsBreakpointName(current_arg, error)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | if (!error.Success()) { |
| 142 | new_args.Clear(); |
| 143 | result.AppendError(error.AsCString()); |
| 144 | result.SetStatus(eReturnStatusFailed); |
| 145 | return; |
| 146 | } else |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 147 | names_found.insert(std::string(current_arg)); |
Zachary Turner | d6a2475 | 2016-11-22 17:10:15 +0000 | [diff] [blame] | 148 | } else if ((i + 2 < old_args.size()) && |
Raphael Isemann | 0d9a201 | 2019-09-13 11:26:48 +0000 | [diff] [blame] | 149 | BreakpointID::IsRangeIdentifier(old_args[i + 1].ref()) && |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | BreakpointID::IsValidIDExpression(current_arg) && |
Raphael Isemann | 0d9a201 | 2019-09-13 11:26:48 +0000 | [diff] [blame] | 151 | BreakpointID::IsValidIDExpression(old_args[i + 2].ref())) { |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 152 | range_from = current_arg; |
Raphael Isemann | 0d9a201 | 2019-09-13 11:26:48 +0000 | [diff] [blame] | 153 | range_to = old_args[i + 2].ref(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | is_range = true; |
| 155 | i = i + 2; |
| 156 | } else { |
| 157 | // See if user has specified id.* |
Raphael Isemann | 0d9a201 | 2019-09-13 11:26:48 +0000 | [diff] [blame] | 158 | llvm::StringRef tmp_str = old_args[i].ref(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 159 | size_t pos = tmp_str.find('.'); |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 160 | if (pos != llvm::StringRef::npos) { |
| 161 | llvm::StringRef bp_id_str = tmp_str.substr(0, pos); |
| 162 | if (BreakpointID::IsValidIDExpression(bp_id_str) && |
| 163 | tmp_str[pos + 1] == '*' && tmp_str.size() == (pos + 2)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 164 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 165 | BreakpointSP breakpoint_sp; |
| 166 | auto bp_id = BreakpointID::ParseCanonicalReference(bp_id_str); |
| 167 | if (bp_id.hasValue()) |
| 168 | breakpoint_sp = target->GetBreakpointByID(bp_id->GetBreakpointID()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 169 | if (!breakpoint_sp) { |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 170 | new_args.Clear(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | result.AppendErrorWithFormat("'%d' is not a valid breakpoint ID.\n", |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 172 | bp_id->GetBreakpointID()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 173 | result.SetStatus(eReturnStatusFailed); |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 174 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 175 | } |
| 176 | const size_t num_locations = breakpoint_sp->GetNumLocations(); |
| 177 | for (size_t j = 0; j < num_locations; ++j) { |
| 178 | BreakpointLocation *bp_loc = |
| 179 | breakpoint_sp->GetLocationAtIndex(j).get(); |
| 180 | StreamString canonical_id_str; |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 181 | BreakpointID::GetCanonicalReference( |
| 182 | &canonical_id_str, bp_id->GetBreakpointID(), bp_loc->GetID()); |
Zachary Turner | ecbb0bb | 2016-09-19 17:54:06 +0000 | [diff] [blame] | 183 | new_args.AppendArgument(canonical_id_str.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | } |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 185 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 189 | if (!is_range) { |
| 190 | new_args.AppendArgument(current_arg); |
| 191 | continue; |
| 192 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 193 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 194 | auto start_bp = BreakpointID::ParseCanonicalReference(range_from); |
| 195 | auto end_bp = BreakpointID::ParseCanonicalReference(range_to); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 196 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 197 | if (!start_bp.hasValue() || |
| 198 | !target->GetBreakpointByID(start_bp->GetBreakpointID())) { |
| 199 | new_args.Clear(); |
| 200 | result.AppendErrorWithFormat("'%s' is not a valid breakpoint ID.\n", |
| 201 | range_from.str().c_str()); |
| 202 | result.SetStatus(eReturnStatusFailed); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | if (!end_bp.hasValue() || |
| 207 | !target->GetBreakpointByID(end_bp->GetBreakpointID())) { |
| 208 | new_args.Clear(); |
| 209 | result.AppendErrorWithFormat("'%s' is not a valid breakpoint ID.\n", |
| 210 | range_to.str().c_str()); |
| 211 | result.SetStatus(eReturnStatusFailed); |
| 212 | return; |
| 213 | } |
| 214 | break_id_t start_bp_id = start_bp->GetBreakpointID(); |
| 215 | break_id_t start_loc_id = start_bp->GetLocationID(); |
| 216 | break_id_t end_bp_id = end_bp->GetBreakpointID(); |
| 217 | break_id_t end_loc_id = end_bp->GetLocationID(); |
Zachary Turner | 0d4f23c | 2016-10-05 18:40:51 +0000 | [diff] [blame] | 218 | if (((start_loc_id == LLDB_INVALID_BREAK_ID) && |
| 219 | (end_loc_id != LLDB_INVALID_BREAK_ID)) || |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 220 | ((start_loc_id != LLDB_INVALID_BREAK_ID) && |
| 221 | (end_loc_id == LLDB_INVALID_BREAK_ID))) { |
| 222 | new_args.Clear(); |
Jonas Devlieghere | 8953376 | 2020-07-20 22:57:06 -0700 | [diff] [blame] | 223 | result.AppendError("Invalid breakpoint id range: Either " |
| 224 | "both ends of range must specify" |
| 225 | " a breakpoint location, or neither can " |
Jonas Devlieghere | 7926143 | 2020-07-20 23:10:29 -0700 | [diff] [blame] | 226 | "specify a breakpoint location."); |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 227 | result.SetStatus(eReturnStatusFailed); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | // We have valid range starting & ending breakpoint IDs. Go through all |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 232 | // the breakpoints in the target and find all the breakpoints that fit into |
| 233 | // this range, and add them to new_args. |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 234 | |
| 235 | // Next check to see if we have location id's. If so, make sure the |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 236 | // start_bp_id and end_bp_id are for the same breakpoint; otherwise we have |
| 237 | // an illegal range: breakpoint id ranges that specify bp locations are NOT |
| 238 | // allowed to cross major bp id numbers. |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 239 | |
| 240 | if ((start_loc_id != LLDB_INVALID_BREAK_ID) || |
| 241 | (end_loc_id != LLDB_INVALID_BREAK_ID)) { |
| 242 | if (start_bp_id != end_bp_id) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 243 | new_args.Clear(); |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 244 | result.AppendErrorWithFormat( |
| 245 | "Invalid range: Ranges that specify particular breakpoint " |
| 246 | "locations" |
| 247 | " must be within the same major breakpoint; you specified two" |
| 248 | " different major breakpoints, %d and %d.\n", |
| 249 | start_bp_id, end_bp_id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 250 | result.SetStatus(eReturnStatusFailed); |
| 251 | return; |
| 252 | } |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 253 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 254 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 255 | const BreakpointList &breakpoints = target->GetBreakpointList(); |
| 256 | const size_t num_breakpoints = breakpoints.GetSize(); |
| 257 | for (size_t j = 0; j < num_breakpoints; ++j) { |
| 258 | Breakpoint *breakpoint = breakpoints.GetBreakpointAtIndex(j).get(); |
| 259 | break_id_t cur_bp_id = breakpoint->GetID(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 260 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 261 | if ((cur_bp_id < start_bp_id) || (cur_bp_id > end_bp_id)) |
| 262 | continue; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 263 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 264 | const size_t num_locations = breakpoint->GetNumLocations(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 265 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 266 | if ((cur_bp_id == start_bp_id) && |
| 267 | (start_loc_id != LLDB_INVALID_BREAK_ID)) { |
| 268 | for (size_t k = 0; k < num_locations; ++k) { |
| 269 | BreakpointLocation *bp_loc = breakpoint->GetLocationAtIndex(k).get(); |
| 270 | if ((bp_loc->GetID() >= start_loc_id) && |
| 271 | (bp_loc->GetID() <= end_loc_id)) { |
| 272 | StreamString canonical_id_str; |
| 273 | BreakpointID::GetCanonicalReference(&canonical_id_str, cur_bp_id, |
| 274 | bp_loc->GetID()); |
| 275 | new_args.AppendArgument(canonical_id_str.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 276 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 277 | } |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 278 | } else if ((cur_bp_id == end_bp_id) && |
| 279 | (end_loc_id != LLDB_INVALID_BREAK_ID)) { |
| 280 | for (size_t k = 0; k < num_locations; ++k) { |
| 281 | BreakpointLocation *bp_loc = breakpoint->GetLocationAtIndex(k).get(); |
| 282 | if (bp_loc->GetID() <= end_loc_id) { |
| 283 | StreamString canonical_id_str; |
| 284 | BreakpointID::GetCanonicalReference(&canonical_id_str, cur_bp_id, |
| 285 | bp_loc->GetID()); |
| 286 | new_args.AppendArgument(canonical_id_str.GetString()); |
| 287 | } |
| 288 | } |
| 289 | } else { |
| 290 | StreamString canonical_id_str; |
| 291 | BreakpointID::GetCanonicalReference(&canonical_id_str, cur_bp_id, |
| 292 | LLDB_INVALID_BREAK_ID); |
| 293 | new_args.AppendArgument(canonical_id_str.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 294 | } |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 295 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 296 | } |
Jim Ingham | 5e09c8c | 2014-12-16 23:40:14 +0000 | [diff] [blame] | 297 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 298 | // Okay, now see if we found any names, and if we did, add them: |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 299 | if (target && !names_found.empty()) { |
| 300 | Status error; |
| 301 | // Remove any names that aren't visible for this purpose: |
| 302 | auto iter = names_found.begin(); |
| 303 | while (iter != names_found.end()) { |
| 304 | BreakpointName *bp_name = target->FindBreakpointName(ConstString(*iter), |
| 305 | true, |
| 306 | error); |
| 307 | if (bp_name && !bp_name->GetPermission(purpose)) |
| 308 | iter = names_found.erase(iter); |
| 309 | else |
| 310 | iter++; |
| 311 | } |
| 312 | |
| 313 | if (!names_found.empty()) { |
| 314 | for (BreakpointSP bkpt_sp : target->GetBreakpointList().Breakpoints()) { |
| 315 | for (std::string name : names_found) { |
| 316 | if (bkpt_sp->MatchesName(name.c_str())) { |
| 317 | StreamString canonical_id_str; |
| 318 | BreakpointID::GetCanonicalReference( |
| 319 | &canonical_id_str, bkpt_sp->GetID(), LLDB_INVALID_BREAK_ID); |
| 320 | new_args.AppendArgument(canonical_id_str.GetString()); |
| 321 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 330 | std::pair<llvm::StringRef, llvm::StringRef> |
| 331 | BreakpointIDList::SplitIDRangeExpression(llvm::StringRef in_string) { |
| 332 | for (auto specifier_str : BreakpointID::GetRangeSpecifiers()) { |
| 333 | size_t idx = in_string.find(specifier_str); |
| 334 | if (idx == llvm::StringRef::npos) |
| 335 | continue; |
| 336 | llvm::StringRef right1 = in_string.drop_front(idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 337 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 338 | llvm::StringRef from = in_string.take_front(idx); |
| 339 | llvm::StringRef to = right1.drop_front(specifier_str.size()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 340 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 341 | if (BreakpointID::IsValidIDExpression(from) && |
| 342 | BreakpointID::IsValidIDExpression(to)) { |
| 343 | return std::make_pair(from, to); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
Zachary Turner | 401f55d | 2016-10-05 17:07:47 +0000 | [diff] [blame] | 347 | return std::pair<llvm::StringRef, llvm::StringRef>(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 348 | } |