[Lldb-commits] [lldb] 4322419 - [lldb][NFC] Use a StringRef for AddRegexCommand::AddRegexCommand parameters
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Mon Jul 27 05:37:09 PDT 2020
Author: Raphael Isemann
Date: 2020-07-27T14:36:47+02:00
New Revision: 432241955e032fba3d8b584ee6388212909bee9b
URL: https://github.com/llvm/llvm-project/commit/432241955e032fba3d8b584ee6388212909bee9b
DIFF: https://github.com/llvm/llvm-project/commit/432241955e032fba3d8b584ee6388212909bee9b.diff
LOG: [lldb][NFC] Use a StringRef for AddRegexCommand::AddRegexCommand parameters
Summary: This way we can get rid of this 1024 char buffer workaround.
Reviewers: #lldb, labath
Reviewed By: labath
Subscribers: JDevlieghere
Differential Revision: https://reviews.llvm.org/D84528
Added:
Modified:
lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h
lldb/source/Commands/CommandObjectCommands.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Interpreter/CommandObjectRegexCommand.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h b/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h
index 01d7c6d118d4..cbd50511c483 100644
--- a/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h
+++ b/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h
@@ -30,7 +30,7 @@ class CommandObjectRegexCommand : public CommandObjectRaw {
bool IsRemovable() const override { return m_is_removable; }
- bool AddRegexCommand(const char *re_cstr, const char *command_cstr);
+ bool AddRegexCommand(llvm::StringRef re_cstr, llvm::StringRef command_cstr);
bool HasRegexEntries() const { return !m_entries.empty(); }
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index 255fbe53fb2e..eaf22344fafa 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -970,7 +970,7 @@ a number follows 'f':"
std::string subst(std::string(regex_sed.substr(
second_separator_char_pos + 1,
third_separator_char_pos - second_separator_char_pos - 1)));
- m_regex_cmd_up->AddRegexCommand(regex.c_str(), subst.c_str());
+ m_regex_cmd_up->AddRegexCommand(regex, subst);
}
return error;
}
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index aca3654b0309..4786e4602e4b 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -631,15 +631,10 @@ void CommandInterpreter::LoadCommandDictionary() {
if (tbreak_regex_cmd_up) {
bool success = true;
for (size_t i = 0; i < num_regexes; i++) {
- // If you add a resultant command string longer than 1024 characters be
- // sure to increase the size of this buffer.
- char buffer[1024];
- int num_printed =
- snprintf(buffer, 1024, "%s %s", break_regexes[i][1], "-o 1");
- lldbassert(num_printed < 1024);
- UNUSED_IF_ASSERT_DISABLED(num_printed);
+ std::string command = break_regexes[i][1];
+ command += " -o 1";
success =
- tbreak_regex_cmd_up->AddRegexCommand(break_regexes[i][0], buffer);
+ tbreak_regex_cmd_up->AddRegexCommand(break_regexes[i][0], command);
if (!success)
break;
}
diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
index 5a0265e58c5c..7485fd76cc25 100644
--- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
+++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -69,14 +69,13 @@ bool CommandObjectRegexCommand::DoExecute(llvm::StringRef command,
return false;
}
-bool CommandObjectRegexCommand::AddRegexCommand(const char *re_cstr,
- const char *command_cstr) {
+bool CommandObjectRegexCommand::AddRegexCommand(llvm::StringRef re_cstr,
+ llvm::StringRef command_cstr) {
m_entries.resize(m_entries.size() + 1);
// Only add the regular expression if it compiles
- m_entries.back().regex =
- RegularExpression(llvm::StringRef::withNullAsEmpty(re_cstr));
+ m_entries.back().regex = RegularExpression(re_cstr);
if (m_entries.back().regex.IsValid()) {
- m_entries.back().command.assign(command_cstr);
+ m_entries.back().command = command_cstr.str();
return true;
}
// The regex didn't compile...
More information about the lldb-commits
mailing list