[Lldb-commits] [lldb] r116814 - in /lldb/trunk: lldb.xcodeproj/project.pbxproj source/Host/macosx/Host.mm tools/debugserver/debugserver.xcodeproj/project.pbxproj

Greg Clayton gclayton at apple.com
Tue Oct 19 10:03:58 PDT 2010


Author: gclayton
Date: Tue Oct 19 12:03:58 2010
New Revision: 116814

URL: http://llvm.org/viewvc/llvm-project?rev=116814&view=rev
Log:
Use AppleScript when lauching inferior in terminal so the command that
is being run is visible in the terminal as opposed to just seeing a path
to a .command file.


Modified:
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Host/macosx/Host.mm
    lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=116814&r1=116813&r2=116814&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Oct 19 12:03:58 2010
@@ -2490,7 +2490,6 @@
 			isa = PBXProject;
 			buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */;
 			compatibilityVersion = "Xcode 3.1";
-			developmentRegion = English;
 			hasScannedForEncodings = 1;
 			knownRegions = (
 				en,

Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=116814&r1=116813&r2=116814&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Tue Oct 19 12:03:58 2010
@@ -159,6 +159,8 @@
     error = ::GetProcessPID(&psn, &pid);
     return pid;
 }
+#define LLDB_HOST_USE_APPLESCRIPT
+#if defined (LLDB_HOST_USE_APPLESCRIPT)
 
 lldb::pid_t
 Host::LaunchInNewTerminal 
@@ -172,6 +174,93 @@
 {
     if (!argv || !argv[0])
         return LLDB_INVALID_PROCESS_ID;
+    
+    std::string unix_socket_name;
+
+    char temp_file_path[PATH_MAX] = "/tmp/XXXXXX";    
+    if (::mktemp (temp_file_path) == NULL)
+        return LLDB_INVALID_PROCESS_ID;
+
+    unix_socket_name.assign (temp_file_path);
+    
+    StreamString command;
+    
+    FileSpec darwin_debug_file_spec;
+    if (!Host::GetLLDBPath (ePathTypeSupportExecutableDir, darwin_debug_file_spec))
+        return LLDB_INVALID_PROCESS_ID;
+    darwin_debug_file_spec.GetFilename().SetCString("darwin-debug");
+        
+    if (!darwin_debug_file_spec.Exists())
+        return LLDB_INVALID_PROCESS_ID;
+    
+    char launcher_path[PATH_MAX];
+    darwin_debug_file_spec.GetPath(launcher_path, sizeof(launcher_path));
+    command.Printf ("tell application \"Terminal\"\n    do script \"'%s'", launcher_path);
+    
+    command.Printf(" --unix-socket=%s", unix_socket_name.c_str());
+
+    if (arch_spec && arch_spec->IsValid())
+    {
+        command.Printf(" --arch=%s", arch_spec->AsCString());
+    }
+
+    if (disable_aslr)
+    {
+        command.PutCString(" --disable-aslr");
+    }
+        
+    command.PutCString(" --");
+
+    if (argv)
+    {
+        for (size_t i=0; argv[i] != NULL; ++i)
+        {
+            command.Printf(" '%s'", argv[i]);
+        }
+    }
+    command.PutCString (" ; exit\"\nend tell\n");
+    const char *script_source = command.GetString().c_str();
+    NSAppleScript* applescript = [[NSAppleScript alloc] initWithSource:[NSString stringWithCString:script_source encoding:NSUTF8StringEncoding]];
+
+    lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
+
+    Error lldb_error;
+    // Sleep and wait a bit for debugserver to start to listen...
+    ConnectionFileDescriptor file_conn;
+    char connect_url[128];
+    ::snprintf (connect_url, sizeof(connect_url), "unix-accept://%s", unix_socket_name.c_str());
+
+    [applescript executeAndReturnError:nil];
+    if (file_conn.Connect(connect_url, &lldb_error) == eConnectionStatusSuccess)
+    {
+        char pid_str[256];
+        ::bzero (pid_str, sizeof(pid_str));
+        ConnectionStatus status;
+        const size_t pid_str_len = file_conn.Read (pid_str, sizeof(pid_str), status, NULL);
+        if (pid_str_len > 0)
+        {
+            pid = atoi (pid_str);
+            // Sleep for a bit to allow the process to exec and stop at the entry point...
+            sleep(1);
+        }
+    }
+    [applescript release];
+    return pid;
+}
+
+#else
+lldb::pid_t
+Host::LaunchInNewTerminal 
+(
+    const char **argv, 
+    const char **envp,
+    const ArchSpec *arch_spec,
+    bool stop_at_entry,
+    bool disable_aslr
+)
+{
+    if (!argv || !argv[0])
+        return LLDB_INVALID_PROCESS_ID;
 
     OSStatus error = 0;
     
@@ -300,6 +389,7 @@
     }
     return pid;
 }
+#endif
 
 bool
 Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)

Modified: lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj?rev=116814&r1=116813&r2=116814&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj Tue Oct 19 12:03:58 2010
@@ -369,7 +369,6 @@
 			isa = PBXProject;
 			buildConfigurationList = 1DEB914E08733D8E0010E9CD /* Build configuration list for PBXProject "debugserver" */;
 			compatibilityVersion = "Xcode 3.1";
-			developmentRegion = English;
 			hasScannedForEncodings = 1;
 			knownRegions = (
 				English,





More information about the lldb-commits mailing list