<rdar://problem/12462048>

LLDB changes argv[0] when debugging a symlink. Now we have the notion of argv0 in the target settings:

target.arg0 (string) = 

There is also the program argument that are separate from the first argument that have existed for a while:

target.run-args (arguments) =

When running "target create <exe>", we will place the untouched "<exe>" into target.arg0 to ensure when we run, we run with what the user typed. This has been added to the ProcessLaunchInfo and all other needed places so we always carry around the:
- resolved executable path
- argv0
- program args

Some systems may not support separating argv0 from the resolved executable path and the ProcessLaunchInfo needs to carry all of this information along so that each platform can make that decision.




git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@166137 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectPlatform.cpp b/source/Commands/CommandObjectPlatform.cpp
index 64c05af..c97abf0 100644
--- a/source/Commands/CommandObjectPlatform.cpp
+++ b/source/Commands/CommandObjectPlatform.cpp
@@ -416,9 +416,7 @@
                     // We don't have any file yet, so the first argument is our
                     // executable, and the rest are program arguments
                     const bool first_arg_is_executable = true;
-                    m_options.launch_info.SetArguments (args, 
-                                                        first_arg_is_executable, 
-                                                        first_arg_is_executable);
+                    m_options.launch_info.SetArguments (args, first_arg_is_executable);
                 }
             }
             
diff --git a/source/Commands/CommandObjectProcess.cpp b/source/Commands/CommandObjectProcess.cpp
index 41e216e..441aee9 100644
--- a/source/Commands/CommandObjectProcess.cpp
+++ b/source/Commands/CommandObjectProcess.cpp
@@ -127,11 +127,6 @@
             return false;
         }
         
-        exe_module->GetFileSpec().GetPath (filename, sizeof(filename));
-
-        const bool add_exe_file_as_first_arg = true;
-        m_options.launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), add_exe_file_as_first_arg);
-        
         StateType state = eStateInvalid;
         Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
         if (process)
@@ -167,18 +162,32 @@
             }
         }
         
+        const char *target_settings_argv0 = target->GetArg0();
+        
+        exe_module->GetFileSpec().GetPath (filename, sizeof(filename));
+        
+        if (target_settings_argv0)
+        {
+            m_options.launch_info.GetArguments().AppendArgument (target_settings_argv0);
+            m_options.launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), false);
+        }
+        else
+        {
+            m_options.launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
+        }
+
         if (launch_args.GetArgumentCount() == 0)
         {
             Args target_setting_args;
-            if (target->GetRunArguments(target_setting_args) > 0)
+            if (target->GetRunArguments(target_setting_args))
                 m_options.launch_info.GetArguments().AppendArguments (target_setting_args);
         }
         else
         {
+            m_options.launch_info.GetArguments().AppendArguments (launch_args);
+
             // Save the arguments for subsequent runs in the current target.
             target->SetRunArguments (launch_args);
-
-            m_options.launch_info.GetArguments().AppendArguments (launch_args);
         }
         
         if (target->GetDisableASLR())
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 6f77106..8c46487 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -239,6 +239,13 @@
 
             if (target_sp)
             {
+                if (file_path)
+                {
+                    // Use exactly what the user typed as the first argument
+                    // when we exec or posix_spawn
+                    target_sp->SetArg0 (file_path);
+                }
+
                 debugger.GetTargetList().SetSelectedTarget(target_sp.get());
                 if (core_file)
                 {