[Lldb-commits] [lldb] r155096 - in /lldb/branches/lldb-platform-work: include/lldb/Host/ source/Host/common/ source/Plugins/Platform/MacOSX/ source/Plugins/Platform/POSIX/ source/Plugins/Platform/gdb-server/ source/Plugins/Process/gdb-remote/ source/Target/ source/Utility/
Enrico Granata
egranata at apple.com
Wed Apr 18 19:30:21 PDT 2012
Author: enrico
Date: Wed Apr 18 21:30:21 2012
New Revision: 155096
URL: http://llvm.org/viewvc/llvm-project?rev=155096&view=rev
Log:
Removing RunProgramAndGetExitCode from the host layer; hooking up RunShellCommand to a new GDB remote packet - next step is to remove the Syscall_System extension packet entirely
Modified:
lldb/branches/lldb-platform-work/include/lldb/Host/Host.h
lldb/branches/lldb-platform-work/source/Host/common/Host.cpp
lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
lldb/branches/lldb-platform-work/source/Target/Platform.cpp
lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp
lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h
Modified: lldb/branches/lldb-platform-work/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/include/lldb/Host/Host.h?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/include/lldb/Host/Host.h (original)
+++ lldb/branches/lldb-platform-work/include/lldb/Host/Host.h Wed Apr 18 21:30:21 2012
@@ -461,9 +461,6 @@
Error &error);
static uint32_t
- RunProgramAndGetExitCode (const char* cmd_line);
-
- static uint32_t
MakeDirectory (const char* path, mode_t mode);
static lldb::user_id_t
Modified: lldb/branches/lldb-platform-work/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Host/common/Host.cpp?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Host/common/Host.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Host/common/Host.cpp Wed Apr 18 21:30:21 2012
@@ -1524,13 +1524,3 @@
{
return file_spec.Exists();
}
-
-uint32_t
-Host::RunProgramAndGetExitCode (const char *cmd_line)
-{
- int exit_code;
- Error err(RunShellCommand(cmd_line, NULL, &exit_code, NULL, NULL, 10));
- if (err.Fail())
- return UINT32_MAX;
- return exit_code;
-}
Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp Wed Apr 18 21:30:21 2012
@@ -180,7 +180,12 @@
StreamString mkdir_folder_cmd;
// try to make the local directory first
mkdir_folder_cmd.Printf("mkdir -p %s/%s", module_cache_folder.GetDirectory().AsCString(), module_cache_folder.GetFilename().AsCString());
- Host::RunProgramAndGetExitCode(mkdir_folder_cmd.GetData());
+ Host::RunShellCommand(mkdir_folder_cmd.GetData(),
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 60);
Error err = GetFile(platform_file, module_cache_spec);
if (err.Fail())
return err;
@@ -245,7 +250,12 @@
StreamString mkdir_folder_cmd;
// try to make the local directory first
mkdir_folder_cmd.Printf("mkdir -p %s/%s", module_cache_folder.GetDirectory().AsCString(), module_cache_folder.GetFilename().AsCString());
- Host::RunProgramAndGetExitCode(mkdir_folder_cmd.GetData());
+ Host::RunShellCommand(mkdir_folder_cmd.GetData(),
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 60);
Error err = GetFile(module_spec.GetFileSpec(), module_cache_spec);
if (err.Fail())
return err;
Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Wed Apr 18 21:30:21 2012
@@ -138,7 +138,16 @@
PlatformPOSIX::RunShellCommand (const std::string &command_line)
{
if (IsHost())
- return Host::RunProgramAndGetExitCode(command_line.c_str());
+ {
+ int retcode;
+ Host::RunShellCommand(command_line.c_str(),
+ NULL,
+ &retcode,
+ NULL,
+ NULL,
+ 60);
+ return retcode;
+ }
if (IsRemote())
{
if (GetSupportsSSH())
@@ -298,7 +307,14 @@
src_path.c_str(),
GetHostname(),
dst_path.c_str());
- if (Host::RunProgramAndGetExitCode(command.GetData()) == 0)
+ int retcode;
+ Host::RunShellCommand(command.GetData(),
+ NULL,
+ &retcode,
+ NULL,
+ NULL,
+ 60);
+ if (retcode == 0)
{
if (chown_file(this,dst_path.c_str(),uid,gid) != 0)
return Error("unable to perform chown");
@@ -408,7 +424,14 @@
src_path.c_str(),
dst_path.c_str());
printf("Running command: %s\n", command.GetData());
- if (Host::RunProgramAndGetExitCode(command.GetData()) == 0)
+ int retcode;
+ Host::RunShellCommand(command.GetData(),
+ NULL,
+ &retcode,
+ NULL,
+ NULL,
+ 60);
+ if (retcode == 0)
return Error();
// If we are here, rsync has failed - let's try the slow way before giving up
}
Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp Wed Apr 18 21:30:21 2012
@@ -475,3 +475,14 @@
{
return m_gdb_client.GetFileExists (file_spec);
}
+
+lldb_private::Error
+PlatformRemoteGDBServer::RunShellCommand (const char *command, // Shouldn't be NULL
+ const char *working_dir, // Pass NULL to use the current working directory
+ int *status_ptr, // Pass NULL if you don't want the process exit status
+ int *signo_ptr, // Pass NULL if you don't want the signal that caused the 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
+{
+ return m_gdb_client.RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
+}
Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h Wed Apr 18 21:30:21 2012
@@ -175,6 +175,14 @@
virtual bool
GetFileExists (const lldb_private::FileSpec& file_spec);
+
+ virtual lldb_private::Error
+ RunShellCommand (const char *command, // Shouldn't be NULL
+ const char *working_dir, // Pass NULL to use the current working directory
+ int *status_ptr, // Pass NULL if you don't want the process exit status
+ int *signo_ptr, // Pass NULL if you don't want the signal that caused the 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
protected:
GDBRemoteCommunicationClient m_gdb_client;
Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Wed Apr 18 21:30:21 2012
@@ -1912,6 +1912,54 @@
return UINT32_MAX;
}
+lldb_private::Error
+GDBRemoteCommunicationClient::RunShellCommand (const char *command, // Shouldn't be NULL
+ const char *working_dir, // Pass NULL to use the current working directory
+ int *status_ptr, // Pass NULL if you don't want the process exit status
+ int *signo_ptr, // Pass NULL if you don't want the signal that caused the 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
+{
+ lldb_private::StreamString stream;
+ stream.PutCString("qPlatform_RunCommand:");
+ stream.PutBytesAsRawHex8(command, strlen(command));
+ stream.PutChar(',');
+ stream.PutHex32(timeout_sec);
+ if (working_dir && *working_dir)
+ {
+ stream.PutChar(',');
+ stream.PutBytesAsRawHex8(working_dir, strlen(working_dir));
+ }
+ const char *packet = stream.GetData();
+ int packet_len = stream.GetSize();
+ StringExtractorGDBRemote response;
+ if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+ {
+ if (response.GetChar() != 'F')
+ return Error("malformed reply");
+ if (response.GetChar() != ',')
+ return Error("malformed reply");
+ uint32_t exitcode = response.GetHexMaxU32(false, UINT32_MAX);
+ if (exitcode == UINT32_MAX)
+ return Error("unable to run remote process");
+ else if (status_ptr)
+ *status_ptr = exitcode;
+ if (response.GetChar() != ',')
+ return Error("malformed reply");
+ uint32_t signo = response.GetHexMaxU32(false, UINT32_MAX);
+ if (signo_ptr)
+ *signo_ptr = signo;
+ if (response.GetChar() != ',')
+ return Error("malformed reply");
+ std::string output;
+ response.GetEscapedBinaryData(output);
+ if (command_output)
+ command_output->assign(output);
+ return Error();
+ }
+ return Error("unable to send packet");
+}
+
uint32_t
GDBRemoteCommunicationClient::MakeDirectory (const std::string &path,
mode_t mode)
Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Wed Apr 18 21:30:21 2012
@@ -367,6 +367,14 @@
virtual bool
GetFileExists (const lldb_private::FileSpec& file_spec);
+ virtual lldb_private::Error
+ RunShellCommand (const char *command, // Shouldn't be NULL
+ const char *working_dir, // Pass NULL to use the current working directory
+ int *status_ptr, // Pass NULL if you don't want the process exit status
+ int *signo_ptr, // Pass NULL if you don't want the signal that caused the 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
+
protected:
//------------------------------------------------------------------
Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Wed Apr 18 21:30:21 2012
@@ -168,6 +168,9 @@
case StringExtractorGDBRemote::eServerPacketType_qPlatform_IO_MkDir:
return Handle_qPlatform_IO_MkDir (packet);
+ case StringExtractorGDBRemote::eServerPacketType_qPlatform_RunCommand:
+ return Handle_qPlatform_RunCommand (packet);
+
case StringExtractorGDBRemote::eServerPacketType_vFile_Open:
return Handle_vFile_Open (packet);
@@ -864,7 +867,13 @@
packet.SetFilePos(::strlen("qPlatform_Syscall_System:"));
std::string path;
packet.GetHexByteString(path);
- uint32_t retcode = Host::RunProgramAndGetExitCode(path.c_str());
+ int retcode;
+ Host::RunShellCommand(path.c_str(),
+ NULL,
+ &retcode,
+ NULL,
+ NULL,
+ 60);
StreamString response;
response.PutHex32(retcode);
SendPacketNoLock(response.GetData(), response.GetSize());
@@ -1038,3 +1047,41 @@
SendPacketNoLock(response.GetData(), response.GetSize());
return true;
}
+
+bool
+GDBRemoteCommunicationServer::Handle_qPlatform_RunCommand (StringExtractorGDBRemote &packet)
+{
+ packet.SetFilePos(::strlen("qPlatform_RunCommand:"));
+ std::string path;
+ std::string working_dir;
+ packet.GetHexByteStringTerminatedBy(path,',');
+ if (path.size() == 0)
+ return false;
+ if (packet.GetChar() != ',')
+ return false;
+ uint32_t timeout = packet.GetHexMaxU32(false, 32);
+ if (packet.GetChar() == ',')
+ packet.GetHexByteString(working_dir);
+ int status, signo;
+ std::string output;
+ Error err = Host::RunShellCommand(path.c_str(),
+ working_dir.empty() ? NULL : working_dir.c_str(),
+ &status, &signo, &output, timeout);
+ StreamGDBRemote response;
+ if (err.Fail())
+ {
+ response.PutCString("F,");
+ response.PutHex32(UINT32_MAX);
+ }
+ else
+ {
+ response.PutCString("F,");
+ response.PutHex32(status);
+ response.PutChar(',');
+ response.PutHex32(signo);
+ response.PutChar(',');
+ response.PutEscapedBytes(output.c_str(), output.size());
+ }
+ SendPacketNoLock(response.GetData(), response.GetSize());
+ return true;
+}
Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h Wed Apr 18 21:30:21 2012
@@ -160,6 +160,9 @@
bool
Handle_vFile_Exists (StringExtractorGDBRemote &packet);
+
+ bool
+ Handle_qPlatform_RunCommand (StringExtractorGDBRemote &packet);
private:
//------------------------------------------------------------------
Modified: lldb/branches/lldb-platform-work/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Target/Platform.cpp?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Target/Platform.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Target/Platform.cpp Wed Apr 18 21:30:21 2012
@@ -731,5 +731,8 @@
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
{
- return Error("unimplemented");
+ if (IsHost())
+ return Host::RunShellCommand (command, working_dir, status_ptr, signo_ptr, command_output, timeout_sec);
+ else
+ return Error("unimplemented");
}
Modified: lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp Wed Apr 18 21:30:21 2012
@@ -128,6 +128,7 @@
case 'P':
if (PACKET_STARTS_WITH ("qProcessInfoPID:")) return eServerPacketType_qProcessInfoPID;
if (PACKET_STARTS_WITH ("qPlatform_Syscall_System:")) return eServerPacketType_qPlatform_Syscall_System;
+ if (PACKET_STARTS_WITH ("qPlatform_RunCommand:")) return eServerPacketType_qPlatform_RunCommand;
if (PACKET_STARTS_WITH ("qPlatform_IO_MkDir:")) return eServerPacketType_qPlatform_IO_MkDir;
break;
Modified: lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h?rev=155096&r1=155095&r2=155096&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h (original)
+++ lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h Wed Apr 18 21:30:21 2012
@@ -65,6 +65,7 @@
eServerPacketType_QSetWorkingDir,
eServerPacketType_QStartNoAckMode,
eServerPacketType_qPlatform_Syscall_System,
+ eServerPacketType_qPlatform_RunCommand,
eServerPacketType_qPlatform_IO_MkDir,
eServerPacketType_vFile_Open,
eServerPacketType_vFile_Close,
More information about the lldb-commits
mailing list