[Lldb-commits] [lldb] r190381 - Changing the default shell to /bin/sh brought up a long-standing bug on OS X,

Jim Ingham jingham at apple.com
Mon Sep 9 19:09:47 PDT 2013


Author: jingham
Date: Mon Sep  9 21:09:47 2013
New Revision: 190381

URL: http://llvm.org/viewvc/llvm-project?rev=190381&view=rev
Log:
Changing the default shell to /bin/sh brought up a long-standing bug on OS X,
that /bin/sh re-exec's itself to /bin/bash, so it needs one more resume when you
are using it as the shell than /bin/bash did or you will stop at the start of your
program, rather than running it.

So I added a Platform API to get the number of resumes needed when launching with
a particular shell, and set the right values for Mac OS X.

<rdar://problem/14935282>

Modified:
    lldb/trunk/include/lldb/Target/Platform.h
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h
    lldb/trunk/source/Target/Platform.cpp
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=190381&r1=190380&r2=190381&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Mon Sep  9 21:09:47 2013
@@ -726,6 +726,12 @@ namespace lldb_private {
         CalculateMD5 (const FileSpec& file_spec,
                       uint64_t &low,
                       uint64_t &high);
+        
+        virtual int32_t
+        GetResumeCountForShell (const char *shell)
+        {
+            return 1;
+        }
                 
     protected:
         bool m_is_host;

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=190381&r1=190380&r2=190381&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Mon Sep  9 21:09:47 2013
@@ -786,7 +786,8 @@ public:
     ConvertArgumentsForLaunchingInShell (Error &error,
                                          bool localhost,
                                          bool will_debug,
-                                         bool first_arg_is_full_shell_command);
+                                         bool first_arg_is_full_shell_command,
+                                         int32_t num_resumes);
     
     void
     SetMonitorProcessCallback (Host::MonitorChildProcessCallback callback, 

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=190381&r1=190380&r2=190381&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Mon Sep  9 21:09:47 2013
@@ -1432,7 +1432,8 @@ Host::RunShellCommand (const char *comma
         launch_info.ConvertArgumentsForLaunchingInShell (error,
                                                          localhost,
                                                          will_debug,
-                                                         first_arg_is_full_shell_command);
+                                                         first_arg_is_full_shell_command,
+                                                         0);
     }
     else
     {

Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp?rev=190381&r1=190380&r2=190381&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Mon Sep  9 21:09:47 2013
@@ -415,10 +415,12 @@ PlatformLinux::LaunchProcess (ProcessLau
             const bool is_localhost = true;
             const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
             const bool first_arg_is_full_shell_command = false;
+            uint32_t num_resumes = GetResumeCountForShell (launch_info.GetShell());
             if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
                                                                   is_localhost,
                                                                   will_debug,
-                                                                  first_arg_is_full_shell_command))
+                                                                  first_arg_is_full_shell_command,
+                                                                  num_resumes))
                 return error;
         }
         error = Platform::LaunchProcess (launch_info);

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=190381&r1=190380&r2=190381&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Mon Sep  9 21:09:47 2013
@@ -1224,3 +1224,28 @@ PlatformDarwin::GetEnvironment (StringLi
     }
     return Host::GetEnvironment(env);
 }
+
+int32_t
+PlatformDarwin::GetResumeCountForShell (const char *shell)
+{
+    const char *shell_name = strrchr (shell, '/');
+    if (shell_name == NULL)
+        shell_name = shell;
+    else
+        shell_name++;
+    
+    if (strcmp (shell_name, "sh") == 0)
+    {
+        // /bin/sh re-exec's itself as /bin/bash requiring another resume.
+        return 2;
+    }
+    else if (strcmp (shell_name, "csh") == 0
+            || strcmp (shell_name, "tcsh") == 0
+            || strcmp (shell_name, "zsh") == 0)
+    {
+        // csh and tcsh always seem to re-exec themselves.
+        return 2;
+    }
+    else
+        return 1;
+}

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h?rev=190381&r1=190380&r2=190381&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h Mon Sep  9 21:09:47 2013
@@ -116,6 +116,9 @@ public:
     
     bool 
     x86GetSupportedArchitectureAtIndex (uint32_t idx, lldb_private::ArchSpec &arch);
+    
+    virtual int32_t
+    GetResumeCountForShell (const char *shell);
 
 protected:
     virtual lldb_private::Error

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=190381&r1=190380&r2=190381&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Mon Sep  9 21:09:47 2013
@@ -664,10 +664,12 @@ Platform::LaunchProcess (ProcessLaunchIn
             const bool is_localhost = true;
             const bool will_debug = launch_info.GetFlags().Test(eLaunchFlagDebug);
             const bool first_arg_is_full_shell_command = false;
+            uint32_t num_resumes = GetResumeCountForShell (launch_info.GetShell());
             if (!launch_info.ConvertArgumentsForLaunchingInShell (error,
                                                                   is_localhost,
                                                                   will_debug,
-                                                                  first_arg_is_full_shell_command))
+                                                                  first_arg_is_full_shell_command,
+                                                                  num_resumes))
                 return error;
         }
 

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=190381&r1=190380&r2=190381&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Mon Sep  9 21:09:47 2013
@@ -489,7 +489,8 @@ bool
 ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell (Error &error,
                                                         bool localhost,
                                                         bool will_debug,
-                                                        bool first_arg_is_full_shell_command)
+                                                        bool first_arg_is_full_shell_command,
+                                                        int32_t num_resumes)
 {
     error.Clear();
 
@@ -571,14 +572,14 @@ ProcessLaunchInfo::ConvertArgumentsForLa
                     // 1 - stop in shell
                     // 2 - stop in /usr/bin/arch
                     // 3 - then we will stop in our program
-                    SetResumeCount(2);
+                    SetResumeCount(num_resumes + 1);
                 }
                 else
                 {
                     // Set the resume count to 1:
                     // 1 - stop in shell
                     // 2 - then we will stop in our program
-                    SetResumeCount(1);
+                    SetResumeCount(num_resumes);
                 }
             }
         





More information about the lldb-commits mailing list