<div dir="ltr">In a followup patch, would you mind changing the terminology from GlobArguments to something more descriptive, like ShellExpand?  When I think glob I only think of wildcards, not full shell exnapsion.  So I think it would be better if it were more explicit.<br></div><br><div class="gmail_quote">On Fri Feb 20 2015 at 1:51:26 PM Enrico Granata <<a href="mailto:egranata@apple.com">egranata@apple.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: enrico<br>
Date: Fri Feb 20 15:48:38 2015<br>
New Revision: 230065<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=230065&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=230065&view=rev</a><br>
Log:<br>
Start the refactoring of globbing<br>
<br>
- Add Host::GlobArguments() to perform local-globbing<br>
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)<br>
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<br>
<br>
- Add Platform::GlobArguments() to support remote-globbing<br>
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<br>
<br>
No visible feature change<br>
<br>
<br>
Modified:<br>
    lldb/trunk/include/lldb/Host/<u></u>Host.h<br>
    lldb/trunk/include/lldb/<u></u>Target/Platform.h<br>
    lldb/trunk/source/Host/<u></u>freebsd/Host.cpp<br>
    lldb/trunk/source/Host/linux/<u></u>Host.cpp<br>
    lldb/trunk/source/Host/macosx/<u></u>Host.mm<br>
    lldb/trunk/source/Host/<u></u>windows/Host.cpp<br>
    lldb/trunk/source/Target/<u></u>Platform.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/Host/<u></u>Host.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=230065&r1=230064&r2=230065&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lldb/trunk/include/<u></u>lldb/Host/Host.h?rev=230065&<u></u>r1=230064&r2=230065&view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- lldb/trunk/include/lldb/Host/<u></u>Host.h (original)<br>
+++ lldb/trunk/include/lldb/Host/<u></u>Host.h Fri Feb 20 15:48:38 2015<br>
@@ -253,6 +253,16 @@ public:<br>
     static Error<br>
     LaunchProcess (ProcessLaunchInfo &launch_info);<br>
<br>
+    //----------------------------<u></u>------------------------------<u></u>--------<br>
+    /// Perform globbing of the command-line for this launch info<br>
+    /// This can potentially involve wildcard expansion<br>
+    //  environment variable replacement, and whatever other<br>
+    //  argument magic the platform defines as part of its typical<br>
+    //  user experience<br>
+    //----------------------------<u></u>------------------------------<u></u>--------<br>
+    static Error<br>
+    GlobArguments (ProcessLaunchInfo &launch_info);<br>
+<br>
     static Error<br>
     RunShellCommand (const char *command,           // Shouldn't be NULL<br>
                      const char *working_dir,       // Pass NULL to use the current working directory<br>
<br>
Modified: lldb/trunk/include/lldb/<u></u>Target/Platform.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=230065&r1=230064&r2=230065&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lldb/trunk/include/<u></u>lldb/Target/Platform.h?rev=<u></u>230065&r1=230064&r2=230065&<u></u>view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- lldb/trunk/include/lldb/<u></u>Target/Platform.h (original)<br>
+++ lldb/trunk/include/lldb/<u></u>Target/Platform.h Fri Feb 20 15:48:38 2015<br>
@@ -386,6 +386,16 @@ namespace lldb_private {<br>
         LaunchProcess (ProcessLaunchInfo &launch_info);<br>
<br>
         //----------------------------<u></u>------------------------------<u></u>--------<br>
+        /// Perform globbing of the command-line for this launch info<br>
+        /// This can potentially involve wildcard expansion<br>
+        //  environment variable replacement, and whatever other<br>
+        //  argument magic the platform defines as part of its typical<br>
+        //  user experience<br>
+        //----------------------------<u></u>------------------------------<u></u>--------<br>
+        virtual Error<br>
+        GlobArguments (ProcessLaunchInfo &launch_info);<br>
+<br>
+        //----------------------------<u></u>------------------------------<u></u>--------<br>
         /// Kill process on a platform.<br>
         //----------------------------<u></u>------------------------------<u></u>--------<br>
         virtual Error<br>
<br>
Modified: lldb/trunk/source/Host/<u></u>freebsd/Host.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/freebsd/Host.cpp?rev=230065&r1=230064&r2=230065&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lldb/trunk/source/<u></u>Host/freebsd/Host.cpp?rev=<u></u>230065&r1=230064&r2=230065&<u></u>view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- lldb/trunk/source/Host/<u></u>freebsd/Host.cpp (original)<br>
+++ lldb/trunk/source/Host/<u></u>freebsd/Host.cpp Fri Feb 20 15:48:38 2015<br>
@@ -312,3 +312,9 @@ Host::GetUnixSignals ()<br>
     return s_unix_signals_sp;<br>
 }<br>
<br>
+Error<br>
+Host::GlobArguments (ProcessLaunchInfo &launch_info)<br>
+{<br>
+    return Error("unimplemented");<br>
+}<br>
+<br>
<br>
Modified: lldb/trunk/source/Host/linux/<u></u>Host.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/linux/Host.cpp?rev=230065&r1=230064&r2=230065&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lldb/trunk/source/<u></u>Host/linux/Host.cpp?rev=<u></u>230065&r1=230064&r2=230065&<u></u>view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- lldb/trunk/source/Host/linux/<u></u>Host.cpp (original)<br>
+++ lldb/trunk/source/Host/linux/<u></u>Host.cpp Fri Feb 20 15:48:38 2015<br>
@@ -417,3 +417,8 @@ Host::GetUnixSignals ()<br>
     return s_unix_signals_sp;<br>
 }<br>
<br>
+Error<br>
+Host::GlobArguments (ProcessLaunchInfo &launch_info)<br>
+{<br>
+    return Error("unimplemented");<br>
+}<br>
<br>
Modified: lldb/trunk/source/Host/macosx/<u></u>Host.mm<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=230065&r1=230064&r2=230065&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lldb/trunk/source/<u></u>Host/macosx/Host.mm?rev=<u></u>230065&r1=230064&r2=230065&<u></u>view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- lldb/trunk/source/Host/macosx/<u></u>Host.mm (original)<br>
+++ lldb/trunk/source/Host/macosx/<u></u>Host.mm Fri Feb 20 15:48:38 2015<br>
@@ -45,6 +45,7 @@<br>
 #include "lldb/Core/ModuleSpec.h"<br>
 #include "lldb/Core/StreamFile.h"<br>
 #include "lldb/Core/StreamString.h"<br>
+#include "lldb/Core/StructuredData.h"<br>
 #include "lldb/Host/<u></u>ConnectionFileDescriptor.h"<br>
 #include "lldb/Host/Endian.h"<br>
 #include "lldb/Host/FileSpec.h"<br>
@@ -1351,6 +1352,91 @@ Host::LaunchProcess (ProcessLaunchInfo &<br>
     return error;<br>
 }<br>
<br>
+Error<br>
+Host::GlobArguments (ProcessLaunchInfo &launch_info)<br>
+{<br>
+    Error error;<br>
+    if (launch_info.GetFlags().Test(<u></u>eLaunchFlagGlobArguments))<br>
+    {<br>
+        FileSpec glob_tool_spec;<br>
+        if (!HostInfo::GetLLDBPath(lldb::<u></u>ePathTypeSupportExecutableDir, glob_tool_spec))<br>
+        {<br>
+            error.SetErrorString("could not find argdumper tool");<br>
+            return error;<br>
+        }<br>
+        glob_tool_spec.<u></u>AppendPathComponent("<u></u>argdumper");<br>
+        if (!glob_tool_spec.Exists())<br>
+        {<br>
+            error.SetErrorString("could not find argdumper tool");<br>
+            return error;<br>
+        }<br>
+<br>
+        std::string quoted_cmd_string;<br>
+        launch_info.GetArguments().<u></u>GetQuotedCommandString(quoted_<u></u>cmd_string);<br>
+        StreamString glob_command;<br>
+<br>
+        glob_command.Printf("%s %s",<br>
+                            glob_tool_spec.GetPath().c_<u></u>str(),<br>
+                            quoted_cmd_string.c_str());<br>
+<br>
+        int status;<br>
+        std::string output;<br>
+        RunShellCommand(glob_command.<u></u>GetData(), launch_info.<u></u>GetWorkingDirectory(), &status, nullptr, &output, 10);<br>
+<br>
+        if (status != 0)<br>
+        {<br>
+            error.<u></u>SetErrorStringWithFormat("<u></u>argdumper exited with error %d", status);<br>
+            return error;<br>
+        }<br>
+<br>
+        auto data_sp = StructuredData::ParseJSON(<u></u>output);<br>
+        if (!data_sp)<br>
+        {<br>
+            error.SetErrorString("invalid JSON");<br>
+            return error;<br>
+        }<br>
+<br>
+        auto dict_sp = data_sp->GetAsDictionary();<br>
+        if (!data_sp)<br>
+        {<br>
+            error.SetErrorString("invalid JSON");<br>
+            return error;<br>
+        }<br>
+<br>
+        auto args_sp = dict_sp-><u></u>GetObjectForDotSeparatedPath("<u></u>arguments");<br>
+        if (!args_sp)<br>
+        {<br>
+            error.SetErrorString("invalid JSON");<br>
+            return error;<br>
+        }<br>
+<br>
+        auto args_array_sp = args_sp->GetAsArray();<br>
+        if (!args_array_sp)<br>
+        {<br>
+            error.SetErrorString("invalid JSON");<br>
+            return error;<br>
+        }<br>
+<br>
+        launch_info.GetArguments().<u></u>Clear();<br>
+<br>
+        for (size_t i = 0;<br>
+             i < args_array_sp->GetSize();<br>
+             i++)<br>
+        {<br>
+            auto item_sp = args_array_sp->GetItemAtIndex(<u></u>i);<br>
+            if (!item_sp)<br>
+                continue;<br>
+            auto str_sp = item_sp->GetAsString();<br>
+            if (!str_sp)<br>
+                continue;<br>
+<br>
+            launch_info.GetArguments().<u></u>AppendArgument(str_sp-><u></u>GetValue().c_str());<br>
+        }<br>
+    }<br>
+<br>
+    return error;<br>
+}<br>
+<br>
 HostThread<br>
 Host::<u></u>StartMonitoringChildProcess(<u></u>Host::<u></u>MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)<br>
 {<br>
<br>
Modified: lldb/trunk/source/Host/<u></u>windows/Host.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Host.cpp?rev=230065&r1=230064&r2=230065&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lldb/trunk/source/<u></u>Host/windows/Host.cpp?rev=<u></u>230065&r1=230064&r2=230065&<u></u>view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- lldb/trunk/source/Host/<u></u>windows/Host.cpp (original)<br>
+++ lldb/trunk/source/Host/<u></u>windows/Host.cpp Fri Feb 20 15:48:38 2015<br>
@@ -217,4 +217,90 @@ HostThread<br>
 Host::<u></u>StartMonitoringChildProcess(<u></u>Host::<u></u>MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)<br>
 {<br>
     return HostThread();<br>
-}<br>
\ No newline at end of file<br>
+}<br>
+<br>
+Error<br>
+Host::GlobArguments (ProcessLaunchInfo &launch_info)<br>
+{<br>
+    Error error;<br>
+    if (launch_info.GetFlags().Test(<u></u>eLaunchFlagGlobArguments))<br>
+    {<br>
+        FileSpec glob_tool_spec;<br>
+        if (!HostInfo::GetLLDBPath(lldb::<u></u>ePathTypeSupportExecutableDir, glob_tool_spec))<br>
+        {<br>
+            error.SetErrorString("could not find argdumper tool");<br>
+            return error;<br>
+        }<br>
+        glob_tool_spec.<u></u>AppendPathComponent("<u></u>argdumper.exe");<br>
+        if (!glob_tool_spec.Exists())<br>
+        {<br>
+            error.SetErrorString("could not find argdumper tool");<br>
+            return error;<br>
+        }<br>
+<br>
+        std::string quoted_cmd_string;<br>
+        launch_info.GetArguments().<u></u>GetQuotedCommandString(quoted_<u></u>cmd_string);<br>
+        std::replace(quoted_cmd_<u></u>string.begin(), quoted_cmd_string.end(), '\\', '/');<br>
+        StreamString glob_command;<br>
+<br>
+        glob_command.Printf("%s %s",<br>
+                            glob_tool_spec.GetPath().c_<u></u>str(),<br>
+                            quoted_cmd_string.c_str());<br>
+<br>
+        int status;<br>
+        std::string output;<br>
+        RunShellCommand(glob_command.<u></u>GetData(), launch_info.<u></u>GetWorkingDirectory(), &status, nullptr, &output, 10);<br>
+<br>
+        if (status != 0)<br>
+        {<br>
+            error.<u></u>SetErrorStringWithFormat("<u></u>argdumper exited with error %d", status);<br>
+            return error;<br>
+        }<br>
+<br>
+        auto data_sp = StructuredData::ParseJSON(<u></u>output);<br>
+        if (!data_sp)<br>
+        {<br>
+            error.SetErrorString("invalid JSON");<br>
+            return error;<br>
+        }<br>
+<br>
+        auto dict_sp = data_sp->GetAsDictionary();<br>
+        if (!data_sp)<br>
+        {<br>
+            error.SetErrorString("invalid JSON");<br>
+            return error;<br>
+        }<br>
+<br>
+        auto args_sp = dict_sp-><u></u>GetObjectForDotSeparatedPath("<u></u>arguments");<br>
+        if (!args_sp)<br>
+        {<br>
+            error.SetErrorString("invalid JSON");<br>
+            return error;<br>
+        }<br>
+<br>
+        auto args_array_sp = args_sp->GetAsArray();<br>
+        if (!args_array_sp)<br>
+        {<br>
+            error.SetErrorString("invalid JSON");<br>
+            return error;<br>
+        }<br>
+<br>
+        launch_info.GetArguments().<u></u>Clear();<br>
+<br>
+        for (size_t i = 0;<br>
+             i < args_array_sp->GetSize();<br>
+             i++)<br>
+        {<br>
+            auto item_sp = args_array_sp->GetItemAtIndex(<u></u>i);<br>
+            if (!item_sp)<br>
+                continue;<br>
+            auto str_sp = item_sp->GetAsString();<br>
+            if (!str_sp)<br>
+                continue;<br>
+<br>
+            launch_info.GetArguments().<u></u>AppendArgument(str_sp-><u></u>GetValue().c_str());<br>
+        }<br>
+    }<br>
+<br>
+    return error;<br>
+}<br>
<br>
Modified: lldb/trunk/source/Target/<u></u>Platform.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=230065&r1=230064&r2=230065&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lldb/trunk/source/<u></u>Target/Platform.cpp?rev=<u></u>230065&r1=230064&r2=230065&<u></u>view=diff</a><br>
==============================<u></u>==============================<u></u>==================<br>
--- lldb/trunk/source/Target/<u></u>Platform.cpp (original)<br>
+++ lldb/trunk/source/Target/<u></u>Platform.cpp Fri Feb 20 15:48:38 2015<br>
@@ -1116,87 +1116,9 @@ Platform::LaunchProcess (ProcessLaunchIn<br>
         }<br>
         else if (launch_info.GetFlags().Test(<u></u>eLaunchFlagGlobArguments))<br>
         {<br>
-            FileSpec glob_tool_spec;<br>
-            if (!HostInfo::GetLLDBPath(lldb::<u></u>ePathTypeSupportExecutableDir, glob_tool_spec))<br>
-            {<br>
-                error.SetErrorString("could not find argdumper tool");<br>
+            error = GlobArguments(launch_info);<br>
+            if (error.Fail())<br>
                 return error;<br>
-            }<br>
-#if defined(_WIN32)<br>
-            glob_tool_spec.<u></u>AppendPathComponent("<u></u>argdumper.exe");<br>
-#else<br>
-            glob_tool_spec.<u></u>AppendPathComponent("<u></u>argdumper");<br>
-#endif<br>
-            if (!glob_tool_spec.Exists())<br>
-            {<br>
-                error.SetErrorString("could not find argdumper tool");<br>
-                return error;<br>
-            }<br>
-<br>
-            std::string quoted_cmd_string;<br>
-            launch_info.GetArguments().<u></u>GetQuotedCommandString(quoted_<u></u>cmd_string);<br>
-#if defined(_WIN32)<br>
-            std::replace(quoted_cmd_<u></u>string.begin(), quoted_cmd_string.end(), '\\', '/');<br>
-#endif<br>
-            StreamString glob_command;<br>
-<br>
-            glob_command.Printf("%s %s",<br>
-                                glob_tool_spec.GetPath().c_<u></u>str(),<br>
-                                quoted_cmd_string.c_str());<br>
-<br>
-            int status;<br>
-            std::string output;<br>
-            RunShellCommand(glob_command.<u></u>GetData(), launch_info.<u></u>GetWorkingDirectory(), &status, nullptr, &output, 10);<br>
-<br>
-            if (status != 0)<br>
-            {<br>
-                error.<u></u>SetErrorStringWithFormat("<u></u>argdumper exited with error %d", status);<br>
-                return error;<br>
-            }<br>
-<br>
-            auto data_sp = StructuredData::ParseJSON(<u></u>output);<br>
-            if (!data_sp)<br>
-            {<br>
-                error.SetErrorString("invalid JSON");<br>
-                return error;<br>
-            }<br>
-<br>
-            auto dict_sp = data_sp->GetAsDictionary();<br>
-            if (!data_sp)<br>
-            {<br>
-                error.SetErrorString("invalid JSON");<br>
-                return error;<br>
-            }<br>
-<br>
-            auto args_sp = dict_sp-><u></u>GetObjectForDotSeparatedPath("<u></u>arguments");<br>
-            if (!args_sp)<br>
-            {<br>
-                error.SetErrorString("invalid JSON");<br>
-                return error;<br>
-            }<br>
-<br>
-            auto args_array_sp = args_sp->GetAsArray();<br>
-            if (!args_array_sp)<br>
-            {<br>
-                error.SetErrorString("invalid JSON");<br>
-                return error;<br>
-            }<br>
-<br>
-            launch_info.GetArguments().<u></u>Clear();<br>
-<br>
-            for (size_t i = 0;<br>
-                 i < args_array_sp->GetSize();<br>
-                 i++)<br>
-            {<br>
-                auto item_sp = args_array_sp->GetItemAtIndex(<u></u>i);<br>
-                if (!item_sp)<br>
-                    continue;<br>
-                auto str_sp = item_sp->GetAsString();<br>
-                if (!str_sp)<br>
-                    continue;<br>
-<br>
-                launch_info.GetArguments().<u></u>AppendArgument(str_sp-><u></u>GetValue().c_str());<br>
-            }<br>
         }<br>
<br>
         if (log)<br>
@@ -1210,6 +1132,14 @@ Platform::LaunchProcess (ProcessLaunchIn<br>
 }<br>
<br>
 Error<br>
+Platform::GlobArguments (ProcessLaunchInfo &launch_info)<br>
+{<br>
+    if (IsHost())<br>
+        return Host::GlobArguments(launch_<u></u>info);<br>
+    return Error("base lldb_private::Platform class can't glob arguments");<br>
+}<br>
+<br>
+Error<br>
 Platform::KillProcess (const lldb::pid_t pid)<br>
 {<br>
     Log *log(lldb_private::<u></u>GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));<br>
<br>
<br>
______________________________<u></u>_________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/lldb-commits</a><br>
</blockquote></div>