diff --git a/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h b/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h --- a/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h +++ b/lldb/include/lldb/Interpreter/CommandObjectRegexCommand.h @@ -30,7 +30,7 @@ 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 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -970,7 +970,7 @@ 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 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -631,15 +631,10 @@ 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 --- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp +++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp @@ -69,14 +69,13 @@ 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...