summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/API/SBPlatform.cpp25
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp10
-rw-r--r--lldb/source/Host/common/Host.cpp12
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp4
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp2
-rw-r--r--lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp26
-rw-r--r--lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h3
-rw-r--r--lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp6
-rw-r--r--lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h3
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp9
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h3
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp7
-rw-r--r--lldb/source/Target/Platform.cpp6
13 files changed, 58 insertions, 58 deletions
diff --git a/lldb/source/API/SBPlatform.cpp b/lldb/source/API/SBPlatform.cpp
index 8d2c4013582..d559a66070f 100644
--- a/lldb/source/API/SBPlatform.cpp
+++ b/lldb/source/API/SBPlatform.cpp
@@ -53,8 +53,7 @@ struct PlatformConnectOptions {
//----------------------------------------------------------------------
struct PlatformShellCommand {
PlatformShellCommand(const char *shell_command = NULL)
- : m_command(), m_working_dir(), m_status(0), m_signo(0),
- m_timeout_sec(UINT32_MAX) {
+ : m_command(), m_working_dir(), m_status(0), m_signo(0) {
if (shell_command && shell_command[0])
m_command = shell_command;
}
@@ -66,7 +65,7 @@ struct PlatformShellCommand {
std::string m_output;
int m_status;
int m_signo;
- uint32_t m_timeout_sec;
+ Timeout<std::ratio<1>> m_timeout = llvm::None;
};
//----------------------------------------------------------------------
// SBPlatformConnectOptions
@@ -182,11 +181,16 @@ void SBPlatformShellCommand::SetWorkingDirectory(const char *path) {
}
uint32_t SBPlatformShellCommand::GetTimeoutSeconds() {
- return m_opaque_ptr->m_timeout_sec;
+ if (m_opaque_ptr->m_timeout)
+ return m_opaque_ptr->m_timeout->count();
+ return UINT32_MAX;
}
void SBPlatformShellCommand::SetTimeoutSeconds(uint32_t sec) {
- m_opaque_ptr->m_timeout_sec = sec;
+ if (sec == UINT32_MAX)
+ m_opaque_ptr->m_timeout = llvm::None;
+ else
+ m_opaque_ptr->m_timeout = std::chrono::seconds(sec);
}
int SBPlatformShellCommand::GetSignal() { return m_opaque_ptr->m_signo; }
@@ -405,12 +409,11 @@ SBError SBPlatform::Run(SBPlatformShellCommand &shell_command) {
if (working_dir)
shell_command.SetWorkingDirectory(working_dir);
}
- return platform_sp->RunShellCommand(
- command, FileSpec{working_dir, false},
- &shell_command.m_opaque_ptr->m_status,
- &shell_command.m_opaque_ptr->m_signo,
- &shell_command.m_opaque_ptr->m_output,
- shell_command.m_opaque_ptr->m_timeout_sec);
+ return platform_sp->RunShellCommand(command, FileSpec{working_dir, false},
+ &shell_command.m_opaque_ptr->m_status,
+ &shell_command.m_opaque_ptr->m_signo,
+ &shell_command.m_opaque_ptr->m_output,
+ shell_command.m_opaque_ptr->m_timeout);
});
}
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 379e8507f4e..0c979032708 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -1692,7 +1692,7 @@ class CommandObjectPlatformShell : public CommandObjectRaw {
public:
class CommandOptions : public Options {
public:
- CommandOptions() : Options(), timeout(10) {}
+ CommandOptions() : Options() {}
~CommandOptions() override = default;
@@ -1708,11 +1708,13 @@ public:
switch (short_option) {
case 't':
- timeout = 10;
- if (option_arg.getAsInteger(10, timeout))
+ uint32_t timeout_sec;
+ if (option_arg.getAsInteger(10, timeout_sec))
error.SetErrorStringWithFormat(
"could not convert \"%s\" to a numeric value.",
option_arg.str().c_str());
+ else
+ timeout = std::chrono::seconds(timeout_sec);
break;
default:
error.SetErrorStringWithFormat("invalid short option character '%c'",
@@ -1725,7 +1727,7 @@ public:
void OptionParsingStarting(ExecutionContext *execution_context) override {}
- uint32_t timeout;
+ Timeout<std::micro> timeout = std::chrono::seconds(10);
};
CommandObjectPlatformShell(CommandInterpreter &interpreter)
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index becd914650b..1b779449b5f 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -463,15 +463,17 @@ MonitorShellCommand(std::shared_ptr<ShellInfo> shell_info, lldb::pid_t pid,
Status Host::RunShellCommand(const char *command, const FileSpec &working_dir,
int *status_ptr, int *signo_ptr,
std::string *command_output_ptr,
- uint32_t timeout_sec, bool run_in_default_shell) {
+ const Timeout<std::micro> &timeout,
+ bool run_in_default_shell) {
return RunShellCommand(Args(command), working_dir, status_ptr, signo_ptr,
- command_output_ptr, timeout_sec, run_in_default_shell);
+ command_output_ptr, timeout, run_in_default_shell);
}
Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
int *status_ptr, int *signo_ptr,
std::string *command_output_ptr,
- uint32_t timeout_sec, bool run_in_default_shell) {
+ const Timeout<std::micro> &timeout,
+ bool run_in_default_shell) {
Status error;
ProcessLaunchInfo launch_info;
launch_info.SetArchitecture(HostInfo::GetArchitecture());
@@ -536,10 +538,6 @@ Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
error.SetErrorString("failed to get process ID");
if (error.Success()) {
- // TODO: Remove this and make the function take Timeout<> argument.
- Timeout<std::micro> timeout(llvm::None);
- if (timeout_sec != 0)
- timeout = std::chrono::seconds(timeout_sec);
if (!shell_info_sp->process_reaped.WaitForValueEqualTo(true, timeout)) {
error.SetErrorString("timed out waiting for shell command to complete");
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index e6ed57ac716..73b4003ff05 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1193,7 +1193,7 @@ const char *PlatformDarwin::GetDeveloperDirectory() {
Host::RunShellCommand("/usr/bin/xcode-select --print-path",
NULL, // current working directory
&exit_status, &signo, &command_output,
- 2, // short timeout
+ std::chrono::seconds(2), // short timeout
false); // don't run in a shell
if (error.Success() && exit_status == 0 && !command_output.empty()) {
const char *cmd_output_ptr = command_output.c_str();
@@ -1365,7 +1365,7 @@ static FileSpec GetXcodeContentsPath() {
&signo, // Put the signal that caused the process to exit in here
&output, // Get the output from the command and place it in this
// string
- 3); // Timeout in seconds to wait for shell program to finish
+ std::chrono::seconds(3));
if (status == 0 && !output.empty()) {
size_t first_non_newline = output.find_last_not_of("\r\n");
if (first_non_newline != std::string::npos) {
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
index e6311abfc04..50b5988b48a 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
@@ -196,7 +196,7 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
// here
&output, // Get the output from the command and place it in this
// string
- 3); // Timeout in seconds to wait for shell program to finish
+ std::chrono::seconds(3));
if (status == 0 && !output.empty()) {
size_t first_non_newline = output.find_last_not_of("\r\n");
if (first_non_newline != std::string::npos)
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
index c5b796d850d..f7a82651022 100644
--- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -102,17 +102,14 @@ lldb_private::Status PlatformPOSIX::RunShellCommand(
// process to exit
std::string
*command_output, // Pass NULL if you don't want the command output
- uint32_t
- timeout_sec) // Timeout in seconds to wait for shell program to finish
-{
+ const Timeout<std::micro> &timeout) {
if (IsHost())
return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr,
- command_output, timeout_sec);
+ command_output, timeout);
else {
if (m_remote_platform_sp)
- return m_remote_platform_sp->RunShellCommand(command, working_dir,
- status_ptr, signo_ptr,
- command_output, timeout_sec);
+ return m_remote_platform_sp->RunShellCommand(
+ command, working_dir, status_ptr, signo_ptr, command_output, timeout);
else
return Status("unable to run a remote command without a platform");
}
@@ -372,7 +369,8 @@ static uint32_t chown_file(Platform *platform, const char *path,
command.Printf(":%d", gid);
command.Printf("%s", path);
int status;
- platform->RunShellCommand(command.GetData(), NULL, &status, NULL, NULL, 10);
+ platform->RunShellCommand(command.GetData(), NULL, &status, NULL, NULL,
+ std::chrono::seconds(10));
return status;
}
@@ -396,7 +394,8 @@ PlatformPOSIX::PutFile(const lldb_private::FileSpec &source,
StreamString command;
command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
int status;
- RunShellCommand(command.GetData(), NULL, &status, NULL, NULL, 10);
+ RunShellCommand(command.GetData(), NULL, &status, NULL, NULL,
+ std::chrono::seconds(10));
if (status != 0)
return Status("unable to perform copy");
if (uid == UINT32_MAX && gid == UINT32_MAX)
@@ -426,7 +425,8 @@ PlatformPOSIX::PutFile(const lldb_private::FileSpec &source,
if (log)
log->Printf("[PutFile] Running command: %s\n", command.GetData());
int retcode;
- Host::RunShellCommand(command.GetData(), NULL, &retcode, NULL, NULL, 60);
+ Host::RunShellCommand(command.GetData(), NULL, &retcode, NULL, NULL,
+ std::chrono::minutes(1));
if (retcode == 0) {
// Don't chown a local file for a remote system
// if (chown_file(this,dst_path.c_str(),uid,gid) != 0)
@@ -500,7 +500,8 @@ lldb_private::Status PlatformPOSIX::GetFile(
StreamString cp_command;
cp_command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
int status;
- RunShellCommand(cp_command.GetData(), NULL, &status, NULL, NULL, 10);
+ RunShellCommand(cp_command.GetData(), NULL, &status, NULL, NULL,
+ std::chrono::seconds(10));
if (status != 0)
return Status("unable to perform copy");
return Status();
@@ -521,7 +522,8 @@ lldb_private::Status PlatformPOSIX::GetFile(
if (log)
log->Printf("[GetFile] Running command: %s\n", command.GetData());
int retcode;
- Host::RunShellCommand(command.GetData(), NULL, &retcode, NULL, NULL, 60);
+ Host::RunShellCommand(command.GetData(), NULL, &retcode, NULL, NULL,
+ std::chrono::minutes(1));
if (retcode == 0)
return Status();
// If we are here, rsync has failed - let's try the slow way before
diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h
index d9ebdff72df..1235e21f30d 100644
--- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h
+++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.h
@@ -99,8 +99,7 @@ public:
// the process to exit
std::string
*command_output, // Pass nullptr if you don't want the command output
- uint32_t timeout_sec)
- override; // Timeout in seconds to wait for shell program to finish
+ const lldb_private::Timeout<std::micro> &timeout) override;
lldb_private::Status ResolveExecutable(
const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index a67980156f3..10cff9e5943 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -720,11 +720,9 @@ Status PlatformRemoteGDBServer::RunShellCommand(
// process to exit
std::string
*command_output, // Pass NULL if you don't want the command output
- uint32_t
- timeout_sec) // Timeout in seconds to wait for shell program to finish
-{
+ const Timeout<std::micro> &timeout) {
return m_gdb_client.RunShellCommand(command, working_dir, status_ptr,
- signo_ptr, command_output, timeout_sec);
+ signo_ptr, command_output, timeout);
}
void PlatformRemoteGDBServer::CalculateTrapHandlerSymbolNames() {
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
index 210544f752e..944871052fc 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
@@ -155,8 +155,7 @@ public:
// process to exit
std::string
*command_output, // Pass NULL if you don't want the command output
- uint32_t timeout_sec)
- override; // Timeout in seconds to wait for shell program to finish
+ const lldb_private::Timeout<std::micro> &timeout) override;
void CalculateTrapHandlerSymbolNames() override;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 231fa9043c4..844e248dd0a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -2796,13 +2796,16 @@ lldb_private::Status GDBRemoteCommunicationClient::RunShellCommand(
// process to exit
std::string
*command_output, // Pass NULL if you don't want the command output
- uint32_t
- timeout_sec) // Timeout in seconds to wait for shell program to finish
-{
+ const Timeout<std::micro> &timeout) {
lldb_private::StreamString stream;
stream.PutCString("qPlatform_shell:");
stream.PutBytesAsRawHex8(command, strlen(command));
stream.PutChar(',');
+ uint32_t timeout_sec = UINT32_MAX;
+ if (timeout) {
+ // TODO: Use chrono version of std::ceil once c++17 is available.
+ timeout_sec = std::ceil(std::chrono::duration<double>(*timeout).count());
+ }
stream.PutHex32(timeout_sec);
if (working_dir) {
std::string path{working_dir.GetPath(false)};
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index 8898767e83c..fcf578f9918 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -404,8 +404,7 @@ public:
// the process to exit
std::string
*command_output, // Pass nullptr if you don't want the command output
- uint32_t timeout_sec); // Timeout in seconds to wait for shell program to
- // finish
+ const Timeout<std::micro> &timeout);
bool CalculateMD5(const FileSpec &file_spec, uint64_t &high, uint64_t &low);
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
index 47dca596eb4..c73fc56119c 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -735,14 +735,13 @@ GDBRemoteCommunicationServerCommon::Handle_qPlatform_shell(
if (packet.GetChar() == ',') {
// FIXME: add timeout to qPlatform_shell packet
// uint32_t timeout = packet.GetHexMaxU32(false, 32);
- uint32_t timeout = 10;
if (packet.GetChar() == ',')
packet.GetHexByteString(working_dir);
int status, signo;
std::string output;
- Status err =
- Host::RunShellCommand(path.c_str(), FileSpec{working_dir, true},
- &status, &signo, &output, timeout);
+ Status err = Host::RunShellCommand(
+ path.c_str(), FileSpec{working_dir, true}, &status, &signo, &output,
+ std::chrono::seconds(10));
StreamGDBRemote response;
if (err.Fail()) {
response.PutCString("F,");
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index e5d1f47347f..be94f37aea9 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1368,12 +1368,10 @@ lldb_private::Status Platform::RunShellCommand(
// process to exit
std::string
*command_output, // Pass nullptr if you don't want the command output
- uint32_t
- timeout_sec) // Timeout in seconds to wait for shell program to finish
-{
+ const Timeout<std::micro> &timeout) {
if (IsHost())
return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr,
- command_output, timeout_sec);
+ command_output, timeout);
else
return Status("unimplemented");
}
OpenPOWER on IntegriCloud