zturner created this revision.
zturner added a reviewer: jingham.
zturner added a subscriber: lldb-commits.
This is an incremental step towards getting some other code converted. In any
case, I believe this makes the breakpoint code significantly easier to
understand and also removes many string copies in the range id code.
https://reviews.llvm.org/D25158
Files:
include/lldb/Breakpoint/BreakpointID.h
include/lldb/Breakpoint/BreakpointIDList.h
source/Breakpoint/BreakpointID.cpp
source/Breakpoint/BreakpointIDList.cpp
Index: source/Breakpoint/BreakpointIDList.cpp
===
--- source/Breakpoint/BreakpointIDList.cpp
+++ source/Breakpoint/BreakpointIDList.cpp
@@ -142,34 +142,32 @@
bool allow_locations,
CommandReturnObject &result,
Args &new_args) {
- std::string range_start;
- const char *range_end;
- const char *current_arg;
+ llvm::StringRef range_from;
+ llvm::StringRef range_to;
+ llvm::StringRef current_arg;
const size_t num_old_args = old_args.GetArgumentCount();
std::set names_found;
for (size_t i = 0; i < num_old_args; ++i) {
bool is_range = false;
current_arg = old_args.GetArgumentAtIndex(i);
-if (!allow_locations && strchr(current_arg, '.') != nullptr) {
+if (!allow_locations && current_arg.contains('.')) {
result.AppendErrorWithFormat(
- "Breakpoint locations not allowed, saw location: %s.", current_arg);
+ "Breakpoint locations not allowed, saw location: %s.",
+ current_arg.str().c_str());
new_args.Clear();
return;
}
-size_t range_start_len = 0;
-size_t range_end_pos = 0;
+llvm::StringRef range_expr;
Error error;
-if (BreakpointIDList::StringContainsIDRangeExpression(
-current_arg, &range_start_len, &range_end_pos)) {
+std::tie(range_from, range_to) =
+BreakpointIDList::SplitIDRangeExpression(current_arg);
+if (!range_from.empty() && !range_to.empty()) {
is_range = true;
- range_start.assign(current_arg, range_start_len);
- range_end = current_arg + range_end_pos;
-} else if (BreakpointID::StringIsBreakpointName(
- llvm::StringRef(current_arg), error)) {
+} else if (BreakpointID::StringIsBreakpointName(current_arg, error)) {
if (!error.Success()) {
new_args.Clear();
result.AppendError(error.AsCString());
@@ -183,23 +181,22 @@
BreakpointID::IsValidIDExpression(current_arg) &&
BreakpointID::IsValidIDExpression(
old_args.GetArgumentAtIndex(i + 2))) {
- range_start.assign(current_arg);
- range_end = old_args.GetArgumentAtIndex(i + 2);
+ range_from = current_arg;
+ range_to = old_args.GetArgumentAtIndex(i + 2);
is_range = true;
i = i + 2;
} else {
// See if user has specified id.*
- std::string tmp_str = old_args.GetArgumentAtIndex(i);
+ llvm::StringRef tmp_str = old_args.GetArgumentAtIndex(i);
size_t pos = tmp_str.find('.');
- if (pos != std::string::npos) {
-std::string bp_id_str = tmp_str.substr(0, pos);
-if (BreakpointID::IsValidIDExpression(bp_id_str.c_str()) &&
-tmp_str[pos + 1] == '*' && tmp_str.length() == (pos + 2)) {
+ if (pos != llvm::StringRef::npos) {
+llvm::StringRef bp_id_str = tmp_str.substr(0, pos);
+if (BreakpointID::IsValidIDExpression(bp_id_str) &&
+tmp_str[pos + 1] == '*' && tmp_str.size() == (pos + 2)) {
break_id_t bp_id;
break_id_t bp_loc_id;
- BreakpointID::ParseCanonicalReference(bp_id_str.c_str(), &bp_id,
-&bp_loc_id);
+ BreakpointID::ParseCanonicalReference(bp_id_str, &bp_id, &bp_loc_id);
BreakpointSP breakpoint_sp = target->GetBreakpointByID(bp_id);
if (!breakpoint_sp) {
new_args.Clear();
@@ -221,119 +218,115 @@
}
}
-if (is_range) {
- break_id_t start_bp_id;
- break_id_t end_bp_id;
- break_id_t start_loc_id;
- break_id_t end_loc_id;
+if (!is_range) {
+ new_args.AppendArgument(current_arg);
+ continue;
+}
- BreakpointID::ParseCanonicalReference(range_start.c_str(), &start_bp_id,
-&start_loc_id);
- BreakpointID::ParseCanonicalReference(range_end, &end_bp_id, &end_loc_id);
+break_id_t start_bp_id;
+break_id_t end_bp_id;
+break_id_t start_loc_id;
+break_id_t end_loc_id;
- if ((start_bp_id == LLDB_INVALID_BREAK_ID) ||
- (!target->GetBreakpointByID(start_bp_id))) {
-new_args.Clear();
-result.AppendErrorWithFormat("'%s' is not a valid breakpoint ID.\n",
- range_start.c_str(