summaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectPlatform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Commands/CommandObjectPlatform.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp77
1 files changed, 55 insertions, 22 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 10e6a4aa17930..fcc8af6f915ce 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1,4 +1,4 @@
-//===-- CommandObjectPlatform.cpp -------------------------------*- C++ -*-===//
+//===-- CommandObjectPlatform.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +11,6 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandOptionValidators.h"
#include "lldb/Interpreter/CommandReturnObject.h"
@@ -133,7 +132,8 @@ public:
uint32_t m_permissions;
private:
- DISALLOW_COPY_AND_ASSIGN(OptionPermissions);
+ OptionPermissions(const OptionPermissions &) = delete;
+ const OptionPermissions &operator=(const OptionPermissions &) = delete;
};
// "platform select <platform-name>"
@@ -421,7 +421,6 @@ protected:
return &m_options;
}
-protected:
OptionGroupOptions m_options;
OptionGroupFile m_option_working_dir;
};
@@ -546,8 +545,13 @@ public:
if (platform_sp) {
std::string cmd_line;
args.GetCommandString(cmd_line);
- const lldb::user_id_t fd =
- StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+ lldb::user_id_t fd;
+ if (!llvm::to_integer(cmd_line, fd)) {
+ result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.\n",
+ cmd_line);
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ }
Status error;
bool success = platform_sp->CloseFile(fd, error);
if (success) {
@@ -586,8 +590,13 @@ public:
if (platform_sp) {
std::string cmd_line;
args.GetCommandString(cmd_line);
- const lldb::user_id_t fd =
- StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+ lldb::user_id_t fd;
+ if (!llvm::to_integer(cmd_line, fd)) {
+ result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.\n",
+ cmd_line);
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ }
std::string buffer(m_options.m_count, 0);
Status error;
uint32_t retcode = platform_sp->ReadFile(
@@ -674,8 +683,13 @@ public:
std::string cmd_line;
args.GetCommandString(cmd_line);
Status error;
- const lldb::user_id_t fd =
- StringConvert::ToUInt64(cmd_line.c_str(), UINT64_MAX);
+ lldb::user_id_t fd;
+ if (!llvm::to_integer(cmd_line, fd)) {
+ result.AppendErrorWithFormatv("'{0}' is not a valid file descriptor.",
+ cmd_line);
+ result.SetStatus(eReturnStatusFailed);
+ return result.Succeeded();
+ }
uint32_t retcode =
platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0],
m_options.m_data.size(), error);
@@ -709,7 +723,7 @@ protected:
option_arg.str().c_str());
break;
case 'd':
- m_data.assign(option_arg);
+ m_data.assign(std::string(option_arg));
break;
default:
llvm_unreachable("Unimplemented option");
@@ -758,7 +772,9 @@ public:
private:
// For CommandObjectPlatform only
- DISALLOW_COPY_AND_ASSIGN(CommandObjectPlatformFile);
+ CommandObjectPlatformFile(const CommandObjectPlatformFile &) = delete;
+ const CommandObjectPlatformFile &
+ operator=(const CommandObjectPlatformFile &) = delete;
};
// "platform get-file remote-file-path host-file-path"
@@ -1020,7 +1036,6 @@ protected:
return result.Succeeded();
}
-protected:
ProcessLaunchCommandOptions m_options;
};
@@ -1128,7 +1143,7 @@ protected:
ProcessInstanceInfo::DumpTableHeader(ostrm, m_options.show_args,
m_options.verbose);
for (uint32_t i = 0; i < matches; ++i) {
- proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(
+ proc_infos[i].DumpAsTableRow(
ostrm, platform_sp->GetUserIDResolver(),
m_options.show_args, m_options.verbose);
}
@@ -1462,12 +1477,12 @@ public:
match_info.SetNameMatchType(NameMatch::StartsWith);
}
platform_sp->FindProcesses(match_info, process_infos);
- const uint32_t num_matches = process_infos.GetSize();
+ const uint32_t num_matches = process_infos.size();
if (num_matches == 0)
return;
for (uint32_t i = 0; i < num_matches; ++i) {
- request.AddCompletion(process_infos.GetProcessNameAtIndex(i));
+ request.AddCompletion(process_infos[i].GetNameAsStringRef());
}
return;
}
@@ -1541,7 +1556,9 @@ public:
private:
// For CommandObjectPlatform only
- DISALLOW_COPY_AND_ASSIGN(CommandObjectPlatformProcess);
+ CommandObjectPlatformProcess(const CommandObjectPlatformProcess &) = delete;
+ const CommandObjectPlatformProcess &
+ operator=(const CommandObjectPlatformProcess &) = delete;
};
// "platform shell"
@@ -1567,6 +1584,9 @@ public:
const char short_option = (char)GetDefinitions()[option_idx].short_option;
switch (short_option) {
+ case 'h':
+ m_use_host_platform = true;
+ break;
case 't':
uint32_t timeout_sec;
if (option_arg.getAsInteger(10, timeout_sec))
@@ -1574,7 +1594,7 @@ public:
"could not convert \"%s\" to a numeric value.",
option_arg.str().c_str());
else
- timeout = std::chrono::seconds(timeout_sec);
+ m_timeout = std::chrono::seconds(timeout_sec);
break;
default:
llvm_unreachable("Unimplemented option");
@@ -1583,9 +1603,13 @@ public:
return error;
}
- void OptionParsingStarting(ExecutionContext *execution_context) override {}
+ void OptionParsingStarting(ExecutionContext *execution_context) override {
+ m_timeout.reset();
+ m_use_host_platform = false;
+ }
- Timeout<std::micro> timeout = std::chrono::seconds(10);
+ Timeout<std::micro> m_timeout = std::chrono::seconds(10);
+ bool m_use_host_platform;
};
CommandObjectPlatformShell(CommandInterpreter &interpreter)
@@ -1609,6 +1633,7 @@ public:
return true;
}
+ const bool is_alias = !raw_command_line.contains("platform");
OptionsWithRaw args(raw_command_line);
const char *expr = args.GetRawPart().c_str();
@@ -1616,8 +1641,16 @@ public:
if (!ParseOptions(args.GetArgs(), result))
return false;
+ if (args.GetRawPart().empty()) {
+ result.GetOutputStream().Printf("%s <shell-command>\n",
+ is_alias ? "shell" : "platform shell");
+ return false;
+ }
+
PlatformSP platform_sp(
- GetDebugger().GetPlatformList().GetSelectedPlatform());
+ m_options.m_use_host_platform
+ ? Platform::GetHostPlatform()
+ : GetDebugger().GetPlatformList().GetSelectedPlatform());
Status error;
if (platform_sp) {
FileSpec working_dir{};
@@ -1625,7 +1658,7 @@ public:
int status = -1;
int signo = -1;
error = (platform_sp->RunShellCommand(expr, working_dir, &status, &signo,
- &output, m_options.timeout));
+ &output, m_options.m_timeout));
if (!output.empty())
result.GetOutputStream().PutCString(output);
if (status > 0) {