[Lldb-commits] [lldb] r230065 - Start the refactoring of globbing
Enrico Granata
egranata at apple.com
Fri Feb 20 13:48:38 PST 2015
Author: enrico
Date: Fri Feb 20 15:48:38 2015
New Revision: 230065
URL: http://llvm.org/viewvc/llvm-project?rev=230065&view=rev
Log:
Start the refactoring of globbing
- Add Host::GlobArguments() to perform local-globbing
I implemented this on OSX and Windows in terms of argdumper (Windows implementation is essentially the same as the OSX version + a change in binary name and some string magic)
Other platforms did not specifically chime in, so I left it unimplemented for them for the time being. Please feel free to fill in the blanks
- Add Platform::GlobArguments() to support remote-globbing
For now, no feature change here - but now we have infrastructure to help GDBRemote targets to support globbing - and patches to that effect will follow
No visible feature change
Modified:
lldb/trunk/include/lldb/Host/Host.h
lldb/trunk/include/lldb/Target/Platform.h
lldb/trunk/source/Host/freebsd/Host.cpp
lldb/trunk/source/Host/linux/Host.cpp
lldb/trunk/source/Host/macosx/Host.mm
lldb/trunk/source/Host/windows/Host.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=230065&r1=230064&r2=230065&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Fri Feb 20 15:48:38 2015
@@ -253,6 +253,16 @@ public:
static Error
LaunchProcess (ProcessLaunchInfo &launch_info);
+ //------------------------------------------------------------------
+ /// Perform globbing of the command-line for this launch info
+ /// This can potentially involve wildcard expansion
+ // environment variable replacement, and whatever other
+ // argument magic the platform defines as part of its typical
+ // user experience
+ //------------------------------------------------------------------
+ static Error
+ GlobArguments (ProcessLaunchInfo &launch_info);
+
static Error
RunShellCommand (const char *command, // Shouldn't be NULL
const char *working_dir, // Pass NULL to use the current working directory
Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=230065&r1=230064&r2=230065&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Fri Feb 20 15:48:38 2015
@@ -386,6 +386,16 @@ namespace lldb_private {
LaunchProcess (ProcessLaunchInfo &launch_info);
//------------------------------------------------------------------
+ /// Perform globbing of the command-line for this launch info
+ /// This can potentially involve wildcard expansion
+ // environment variable replacement, and whatever other
+ // argument magic the platform defines as part of its typical
+ // user experience
+ //------------------------------------------------------------------
+ virtual Error
+ GlobArguments (ProcessLaunchInfo &launch_info);
+
+ //------------------------------------------------------------------
/// Kill process on a platform.
//------------------------------------------------------------------
virtual Error
Modified: lldb/trunk/source/Host/freebsd/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/freebsd/Host.cpp?rev=230065&r1=230064&r2=230065&view=diff
==============================================================================
--- lldb/trunk/source/Host/freebsd/Host.cpp (original)
+++ lldb/trunk/source/Host/freebsd/Host.cpp Fri Feb 20 15:48:38 2015
@@ -312,3 +312,9 @@ Host::GetUnixSignals ()
return s_unix_signals_sp;
}
+Error
+Host::GlobArguments (ProcessLaunchInfo &launch_info)
+{
+ return Error("unimplemented");
+}
+
Modified: lldb/trunk/source/Host/linux/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/Host.cpp?rev=230065&r1=230064&r2=230065&view=diff
==============================================================================
--- lldb/trunk/source/Host/linux/Host.cpp (original)
+++ lldb/trunk/source/Host/linux/Host.cpp Fri Feb 20 15:48:38 2015
@@ -417,3 +417,8 @@ Host::GetUnixSignals ()
return s_unix_signals_sp;
}
+Error
+Host::GlobArguments (ProcessLaunchInfo &launch_info)
+{
+ return Error("unimplemented");
+}
Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=230065&r1=230064&r2=230065&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Fri Feb 20 15:48:38 2015
@@ -45,6 +45,7 @@
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/StreamString.h"
+#include "lldb/Core/StructuredData.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/Endian.h"
#include "lldb/Host/FileSpec.h"
@@ -1351,6 +1352,91 @@ Host::LaunchProcess (ProcessLaunchInfo &
return error;
}
+Error
+Host::GlobArguments (ProcessLaunchInfo &launch_info)
+{
+ Error error;
+ if (launch_info.GetFlags().Test(eLaunchFlagGlobArguments))
+ {
+ FileSpec glob_tool_spec;
+ if (!HostInfo::GetLLDBPath(lldb::ePathTypeSupportExecutableDir, glob_tool_spec))
+ {
+ error.SetErrorString("could not find argdumper tool");
+ return error;
+ }
+ glob_tool_spec.AppendPathComponent("argdumper");
+ if (!glob_tool_spec.Exists())
+ {
+ error.SetErrorString("could not find argdumper tool");
+ return error;
+ }
+
+ std::string quoted_cmd_string;
+ launch_info.GetArguments().GetQuotedCommandString(quoted_cmd_string);
+ StreamString glob_command;
+
+ glob_command.Printf("%s %s",
+ glob_tool_spec.GetPath().c_str(),
+ quoted_cmd_string.c_str());
+
+ int status;
+ std::string output;
+ RunShellCommand(glob_command.GetData(), launch_info.GetWorkingDirectory(), &status, nullptr, &output, 10);
+
+ if (status != 0)
+ {
+ error.SetErrorStringWithFormat("argdumper exited with error %d", status);
+ return error;
+ }
+
+ auto data_sp = StructuredData::ParseJSON(output);
+ if (!data_sp)
+ {
+ error.SetErrorString("invalid JSON");
+ return error;
+ }
+
+ auto dict_sp = data_sp->GetAsDictionary();
+ if (!data_sp)
+ {
+ error.SetErrorString("invalid JSON");
+ return error;
+ }
+
+ auto args_sp = dict_sp->GetObjectForDotSeparatedPath("arguments");
+ if (!args_sp)
+ {
+ error.SetErrorString("invalid JSON");
+ return error;
+ }
+
+ auto args_array_sp = args_sp->GetAsArray();
+ if (!args_array_sp)
+ {
+ error.SetErrorString("invalid JSON");
+ return error;
+ }
+
+ launch_info.GetArguments().Clear();
+
+ for (size_t i = 0;
+ i < args_array_sp->GetSize();
+ i++)
+ {
+ auto item_sp = args_array_sp->GetItemAtIndex(i);
+ if (!item_sp)
+ continue;
+ auto str_sp = item_sp->GetAsString();
+ if (!str_sp)
+ continue;
+
+ launch_info.GetArguments().AppendArgument(str_sp->GetValue().c_str());
+ }
+ }
+
+ return error;
+}
+
HostThread
Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)
{
Modified: lldb/trunk/source/Host/windows/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Host.cpp?rev=230065&r1=230064&r2=230065&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Host.cpp (original)
+++ lldb/trunk/source/Host/windows/Host.cpp Fri Feb 20 15:48:38 2015
@@ -217,4 +217,90 @@ HostThread
Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)
{
return HostThread();
-}
\ No newline at end of file
+}
+
+Error
+Host::GlobArguments (ProcessLaunchInfo &launch_info)
+{
+ Error error;
+ if (launch_info.GetFlags().Test(eLaunchFlagGlobArguments))
+ {
+ FileSpec glob_tool_spec;
+ if (!HostInfo::GetLLDBPath(lldb::ePathTypeSupportExecutableDir, glob_tool_spec))
+ {
+ error.SetErrorString("could not find argdumper tool");
+ return error;
+ }
+ glob_tool_spec.AppendPathComponent("argdumper.exe");
+ if (!glob_tool_spec.Exists())
+ {
+ error.SetErrorString("could not find argdumper tool");
+ return error;
+ }
+
+ std::string quoted_cmd_string;
+ launch_info.GetArguments().GetQuotedCommandString(quoted_cmd_string);
+ std::replace(quoted_cmd_string.begin(), quoted_cmd_string.end(), '\\', '/');
+ StreamString glob_command;
+
+ glob_command.Printf("%s %s",
+ glob_tool_spec.GetPath().c_str(),
+ quoted_cmd_string.c_str());
+
+ int status;
+ std::string output;
+ RunShellCommand(glob_command.GetData(), launch_info.GetWorkingDirectory(), &status, nullptr, &output, 10);
+
+ if (status != 0)
+ {
+ error.SetErrorStringWithFormat("argdumper exited with error %d", status);
+ return error;
+ }
+
+ auto data_sp = StructuredData::ParseJSON(output);
+ if (!data_sp)
+ {
+ error.SetErrorString("invalid JSON");
+ return error;
+ }
+
+ auto dict_sp = data_sp->GetAsDictionary();
+ if (!data_sp)
+ {
+ error.SetErrorString("invalid JSON");
+ return error;
+ }
+
+ auto args_sp = dict_sp->GetObjectForDotSeparatedPath("arguments");
+ if (!args_sp)
+ {
+ error.SetErrorString("invalid JSON");
+ return error;
+ }
+
+ auto args_array_sp = args_sp->GetAsArray();
+ if (!args_array_sp)
+ {
+ error.SetErrorString("invalid JSON");
+ return error;
+ }
+
+ launch_info.GetArguments().Clear();
+
+ for (size_t i = 0;
+ i < args_array_sp->GetSize();
+ i++)
+ {
+ auto item_sp = args_array_sp->GetItemAtIndex(i);
+ if (!item_sp)
+ continue;
+ auto str_sp = item_sp->GetAsString();
+ if (!str_sp)
+ continue;
+
+ launch_info.GetArguments().AppendArgument(str_sp->GetValue().c_str());
+ }
+ }
+
+ return error;
+}
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=230065&r1=230064&r2=230065&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Fri Feb 20 15:48:38 2015
@@ -1116,87 +1116,9 @@ Platform::LaunchProcess (ProcessLaunchIn
}
else if (launch_info.GetFlags().Test(eLaunchFlagGlobArguments))
{
- FileSpec glob_tool_spec;
- if (!HostInfo::GetLLDBPath(lldb::ePathTypeSupportExecutableDir, glob_tool_spec))
- {
- error.SetErrorString("could not find argdumper tool");
+ error = GlobArguments(launch_info);
+ if (error.Fail())
return error;
- }
-#if defined(_WIN32)
- glob_tool_spec.AppendPathComponent("argdumper.exe");
-#else
- glob_tool_spec.AppendPathComponent("argdumper");
-#endif
- if (!glob_tool_spec.Exists())
- {
- error.SetErrorString("could not find argdumper tool");
- return error;
- }
-
- std::string quoted_cmd_string;
- launch_info.GetArguments().GetQuotedCommandString(quoted_cmd_string);
-#if defined(_WIN32)
- std::replace(quoted_cmd_string.begin(), quoted_cmd_string.end(), '\\', '/');
-#endif
- StreamString glob_command;
-
- glob_command.Printf("%s %s",
- glob_tool_spec.GetPath().c_str(),
- quoted_cmd_string.c_str());
-
- int status;
- std::string output;
- RunShellCommand(glob_command.GetData(), launch_info.GetWorkingDirectory(), &status, nullptr, &output, 10);
-
- if (status != 0)
- {
- error.SetErrorStringWithFormat("argdumper exited with error %d", status);
- return error;
- }
-
- auto data_sp = StructuredData::ParseJSON(output);
- if (!data_sp)
- {
- error.SetErrorString("invalid JSON");
- return error;
- }
-
- auto dict_sp = data_sp->GetAsDictionary();
- if (!data_sp)
- {
- error.SetErrorString("invalid JSON");
- return error;
- }
-
- auto args_sp = dict_sp->GetObjectForDotSeparatedPath("arguments");
- if (!args_sp)
- {
- error.SetErrorString("invalid JSON");
- return error;
- }
-
- auto args_array_sp = args_sp->GetAsArray();
- if (!args_array_sp)
- {
- error.SetErrorString("invalid JSON");
- return error;
- }
-
- launch_info.GetArguments().Clear();
-
- for (size_t i = 0;
- i < args_array_sp->GetSize();
- i++)
- {
- auto item_sp = args_array_sp->GetItemAtIndex(i);
- if (!item_sp)
- continue;
- auto str_sp = item_sp->GetAsString();
- if (!str_sp)
- continue;
-
- launch_info.GetArguments().AppendArgument(str_sp->GetValue().c_str());
- }
}
if (log)
@@ -1210,6 +1132,14 @@ Platform::LaunchProcess (ProcessLaunchIn
}
Error
+Platform::GlobArguments (ProcessLaunchInfo &launch_info)
+{
+ if (IsHost())
+ return Host::GlobArguments(launch_info);
+ return Error("base lldb_private::Platform class can't glob arguments");
+}
+
+Error
Platform::KillProcess (const lldb::pid_t pid)
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
More information about the lldb-commits
mailing list