summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2018-07-12 22:28:52 +0000
committerRaphael Isemann <teemperor@gmail.com>2018-07-12 22:28:52 +0000
commit4d51a90297d34389b53c00c5cd6fa6f73998c298 (patch)
treefb8d42ce62a2a5e7bff1c397626c774ce51e3fee /lldb/source/Commands
parent3a1347721454c50c0f06cdf99388b8d38a49c408 (diff)
downloadbcm5719-llvm-4d51a90297d34389b53c00c5cd6fa6f73998c298.tar.gz
bcm5719-llvm-4d51a90297d34389b53c00c5cd6fa6f73998c298.zip
Get rid of the C-string parameter in DoExecute
Summary: This patch gets rid of the C-string parameter in the RawCommandObject::DoExecute function, making the code simpler and less memory unsafe. There seems to be a assumption in some command objects that this parameter could be a nullptr, but from what I can see the rest of the API doesn't actually allow this (and other command objects and related code pieces dereference this parameter without any checks). Especially CommandObjectRegexCommand has error handling code for a nullptr that is now gone. Reviewers: davide, jingham, teemperor Reviewed By: teemperor Subscribers: jingham, lldb-commits Differential Revision: https://reviews.llvm.org/D49207 llvm-svn: 336955
Diffstat (limited to 'lldb/source/Commands')
-rw-r--r--lldb/source/Commands/CommandObjectCommands.cpp8
-rw-r--r--lldb/source/Commands/CommandObjectExpression.cpp10
-rw-r--r--lldb/source/Commands/CommandObjectExpression.h4
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp4
-rw-r--r--lldb/source/Commands/CommandObjectSettings.cpp18
-rw-r--r--lldb/source/Commands/CommandObjectThread.cpp9
-rw-r--r--lldb/source/Commands/CommandObjectType.cpp23
-rw-r--r--lldb/source/Commands/CommandObjectWatchpoint.cpp4
8 files changed, 44 insertions, 36 deletions
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index 5e7f272ec22..b7f439e5219 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -543,9 +543,9 @@ rather than using a positional placeholder:"
~CommandObjectCommandsAlias() override = default;
protected:
- bool DoExecute(const char *raw_command_line,
+ bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
- if (!raw_command_line || !raw_command_line[0]) {
+ if (raw_command_line.empty()) {
result.AppendError("'command alias' requires at least two arguments");
return false;
}
@@ -1275,7 +1275,7 @@ public:
}
protected:
- bool DoExecute(const char *raw_command_line,
+ bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
@@ -1364,7 +1364,7 @@ public:
}
protected:
- bool DoExecute(const char *raw_command_line,
+ bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter();
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index 9373813b8d0..08959ff8473 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -318,7 +318,7 @@ CanBeUsedForElementCountPrinting(ValueObject &valobj) {
return Status();
}
-bool CommandObjectExpression::EvaluateExpression(const char *expr,
+bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
Stream *output_stream,
Stream *error_stream,
CommandReturnObject *result) {
@@ -508,19 +508,19 @@ void CommandObjectExpression::GetMultilineExpression() {
debugger.PushIOHandler(io_handler_sp);
}
-bool CommandObjectExpression::DoExecute(const char *command,
+bool CommandObjectExpression::DoExecute(llvm::StringRef command,
CommandReturnObject &result) {
m_fixed_expression.clear();
auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
m_option_group.NotifyOptionParsingStarting(&exe_ctx);
- if (command[0] == '\0') {
+ if (command.empty()) {
GetMultilineExpression();
return result.Succeeded();
}
OptionsWithRaw args(command);
- const char *expr = args.GetRawPart().c_str();
+ llvm::StringRef expr = args.GetRawPart();
if (args.HasArgs()) {
if (!ParseOptionsAndNotify(args.GetArgs(), result, m_option_group, exe_ctx))
@@ -584,7 +584,7 @@ bool CommandObjectExpression::DoExecute(const char *command,
}
}
// No expression following options
- else if (expr[0] == '\0') {
+ else if (expr.empty()) {
GetMultilineExpression();
return result.Succeeded();
}
diff --git a/lldb/source/Commands/CommandObjectExpression.h b/lldb/source/Commands/CommandObjectExpression.h
index 0cf2a7263d5..710f8714097 100644
--- a/lldb/source/Commands/CommandObjectExpression.h
+++ b/lldb/source/Commands/CommandObjectExpression.h
@@ -72,9 +72,9 @@ protected:
bool IOHandlerIsInputComplete(IOHandler &io_handler,
StringList &lines) override;
- bool DoExecute(const char *command, CommandReturnObject &result) override;
+ bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
- bool EvaluateExpression(const char *expr, Stream *output_stream,
+ bool EvaluateExpression(llvm::StringRef expr, Stream *output_stream,
Stream *error_stream,
CommandReturnObject *result = NULL);
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 417d0ebddd5..3a27f34fec7 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1742,14 +1742,14 @@ public:
Options *GetOptions() override { return &m_options; }
- bool DoExecute(const char *raw_command_line,
+ bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext();
m_options.NotifyOptionParsingStarting(&exe_ctx);
// Print out an usage syntax on an empty command line.
- if (raw_command_line[0] == '\0') {
+ if (raw_command_line.empty()) {
result.GetOutputStream().Printf("%s\n", this->GetSyntax().str().c_str());
return true;
}
diff --git a/lldb/source/Commands/CommandObjectSettings.cpp b/lldb/source/Commands/CommandObjectSettings.cpp
index 58dbaee967d..ed58ca45d04 100644
--- a/lldb/source/Commands/CommandObjectSettings.cpp
+++ b/lldb/source/Commands/CommandObjectSettings.cpp
@@ -188,7 +188,8 @@ insert-before or insert-after.");
}
protected:
- bool DoExecute(const char *command, CommandReturnObject &result) override {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
Args cmd_args(command);
// Process possible options.
@@ -467,7 +468,8 @@ public:
}
protected:
- bool DoExecute(const char *command, CommandReturnObject &result) override {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
Args cmd_args(command);
@@ -591,7 +593,8 @@ public:
}
protected:
- bool DoExecute(const char *command, CommandReturnObject &result) override {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
Args cmd_args(command);
@@ -698,7 +701,8 @@ public:
}
protected:
- bool DoExecute(const char *command, CommandReturnObject &result) override {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
Args cmd_args(command);
@@ -810,7 +814,8 @@ public:
}
protected:
- bool DoExecute(const char *command, CommandReturnObject &result) override {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
Args cmd_args(command);
@@ -911,7 +916,8 @@ public:
}
protected:
- bool DoExecute(const char *command, CommandReturnObject &result) override {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
result.SetStatus(eReturnStatusSuccessFinishNoResult);
Args cmd_args(command);
const size_t argc = cmd_args.GetArgumentCount();
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index 7ea908eb8ae..3be559963df 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -1603,12 +1603,13 @@ public:
Options *GetOptions() override { return &m_options; }
protected:
- bool DoExecute(const char *command, CommandReturnObject &result) override {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
// I am going to handle this by hand, because I don't want you to have to
// say:
// "thread return -- -5".
- if (command[0] == '-' && command[1] == 'x') {
- if (command && command[2] != '\0')
+ if (command.startswith("-x")) {
+ if (command.size() != 2U)
result.AppendWarning("Return values ignored when returning from user "
"called expressions");
@@ -1645,7 +1646,7 @@ protected:
return false;
}
- if (command && command[0] != '\0') {
+ if (!command.empty()) {
Target *target = m_exe_ctx.GetTargetPtr();
EvaluateExpressionOptions options;
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index 1ff19d1853c..6bcc334198f 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -2862,9 +2862,9 @@ public:
return m_cmd_help_long;
}
- bool DoExecute(const char *raw_command_line,
+ bool DoExecute(llvm::StringRef raw_command_line,
CommandReturnObject &result) override {
- if (!raw_command_line || !raw_command_line[0]) {
+ if (raw_command_line.empty()) {
result.SetError(
"type lookup cannot be invoked without a type name as argument");
return false;
@@ -2994,7 +2994,8 @@ public:
~CommandObjectFormatterInfo() override = default;
protected:
- bool DoExecute(const char *command, CommandReturnObject &result) override {
+ bool DoExecute(llvm::StringRef command,
+ CommandReturnObject &result) override {
TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
Thread *thread = GetDefaultThread();
if (!thread) {
@@ -3017,16 +3018,16 @@ protected:
m_discovery_function(*result_valobj_sp);
if (formatter_sp) {
std::string description(formatter_sp->GetDescription());
- result.AppendMessageWithFormat(
- "%s applied to (%s) %s is: %s\n", m_formatter_name.c_str(),
- result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
- command, description.c_str());
+ result.GetOutputStream()
+ << m_formatter_name << " applied to ("
+ << result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>")
+ << ") " << command << " is: " << description << "\n";
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
} else {
- result.AppendMessageWithFormat(
- "no %s applies to (%s) %s\n", m_formatter_name.c_str(),
- result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
- command);
+ result.GetOutputStream()
+ << "no " << m_formatter_name << " applies to ("
+ << result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>")
+ << ") " << command << "\n";
result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
}
return true;
diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp
index 14d1083ca31..96ae18b3574 100644
--- a/lldb/source/Commands/CommandObjectWatchpoint.cpp
+++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp
@@ -1026,7 +1026,7 @@ Examples:
Options *GetOptions() override { return &m_option_group; }
protected:
- bool DoExecute(const char *raw_command,
+ bool DoExecute(llvm::StringRef raw_command,
CommandReturnObject &result) override {
auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
m_option_group.NotifyOptionParsingStarting(
@@ -1046,7 +1046,7 @@ protected:
// If no argument is present, issue an error message. There's no way to
// set a watchpoint.
- if (llvm::StringRef(raw_command).trim().empty()) {
+ if (raw_command.trim().empty()) {
result.GetErrorStream().Printf("error: required argument missing; "
"specify an expression to evaulate into "
"the address to watch for\n");
OpenPOWER on IntegriCloud