[Lldb-commits] [lldb] r331970 - Convert all RunShellCommand functions to use the Timeout class
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu May 10 03:46:03 PDT 2018
Author: labath
Date: Thu May 10 03:46:03 2018
New Revision: 331970
URL: http://llvm.org/viewvc/llvm-project?rev=331970&view=rev
Log:
Convert all RunShellCommand functions to use the Timeout class
this completes the Timeout migration started in r331880 with the
Predicate class.
Modified:
lldb/trunk/include/lldb/Host/Host.h
lldb/trunk/include/lldb/Target/Platform.h
lldb/trunk/source/API/SBPlatform.cpp
lldb/trunk/source/Commands/CommandObjectPlatform.cpp
lldb/trunk/source/Host/common/Host.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/trunk/source/Target/Platform.cpp
Modified: lldb/trunk/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Thu May 10 03:46:03 2018
@@ -14,6 +14,7 @@
#include "lldb/Host/HostThread.h"
#include "lldb/Utility/Environment.h"
#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Timeout.h"
#include "lldb/lldb-private-forward.h"
#include "lldb/lldb-private.h"
#include <cerrno>
@@ -219,8 +220,7 @@ public:
// process to exit
std::string
*command_output, // Pass NULL if you don't want the command output
- uint32_t timeout_sec,
- bool run_in_default_shell = true);
+ const Timeout<std::micro> &timeout, bool run_in_default_shell = true);
static Status RunShellCommand(
const Args &args,
@@ -231,8 +231,7 @@ public:
// process to exit
std::string
*command_output, // Pass NULL if you don't want the command output
- uint32_t timeout_sec,
- bool run_in_default_shell = true);
+ const Timeout<std::micro> &timeout, bool run_in_default_shell = true);
static bool OpenFileInExternalEditor(const FileSpec &file_spec,
uint32_t line_no);
Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Thu May 10 03:46:03 2018
@@ -27,6 +27,7 @@
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Timeout.h"
#include "lldb/lldb-private-forward.h"
#include "lldb/lldb-public.h"
@@ -676,8 +677,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);
virtual void SetLocalCacheDirectory(const char *local);
Modified: lldb/trunk/source/API/SBPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBPlatform.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/API/SBPlatform.cpp (original)
+++ lldb/trunk/source/API/SBPlatform.cpp Thu May 10 03:46:03 2018
@@ -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::SetWorkingD
}
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(SBPlatformShellC
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);
});
}
Modified: lldb/trunk/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectPlatform.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectPlatform.cpp Thu May 10 03:46:03 2018
@@ -1692,7 +1692,7 @@ class CommandObjectPlatformShell : publi
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)
Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Thu May 10 03:46:03 2018
@@ -463,15 +463,17 @@ MonitorShellCommand(std::shared_ptr<Shel
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
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");
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Thu May 10 03:46:03 2018
@@ -1193,7 +1193,7 @@ const char *PlatformDarwin::GetDeveloper
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) {
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp Thu May 10 03:46:03 2018
@@ -196,7 +196,7 @@ ConstString PlatformMacOSX::GetSDKDirect
// 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)
Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Thu May 10 03:46:03 2018
@@ -102,17 +102,14 @@ lldb_private::Status PlatformPOSIX::RunS
// 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 *pla
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_privat
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_privat
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::GetF
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::GetF
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
Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h (original)
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.h Thu May 10 03:46:03 2018
@@ -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,
Modified: lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp Thu May 10 03:46:03 2018
@@ -720,11 +720,9 @@ Status PlatformRemoteGDBServer::RunShell
// 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() {
Modified: lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h (original)
+++ lldb/trunk/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h Thu May 10 03:46:03 2018
@@ -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;
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Thu May 10 03:46:03 2018
@@ -2796,13 +2796,16 @@ lldb_private::Status GDBRemoteCommunicat
// 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)};
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Thu May 10 03:46:03 2018
@@ -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);
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Thu May 10 03:46:03 2018
@@ -735,14 +735,13 @@ GDBRemoteCommunicationServerCommon::Hand
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,");
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=331970&r1=331969&r2=331970&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Thu May 10 03:46:03 2018
@@ -1368,12 +1368,10 @@ lldb_private::Status Platform::RunShellC
// 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");
}
More information about the lldb-commits
mailing list