Add a "lldb host" logging channel, and put logging in the Host::OpenInExternalEditor...
authorJim Ingham <jingham@apple.com>
Tue, 31 Aug 2010 18:05:13 +0000 (18:05 +0000)
committerJim Ingham <jingham@apple.com>
Tue, 31 Aug 2010 18:05:13 +0000 (18:05 +0000)
llvm-svn: 112614

lldb/include/lldb/lldb-private-log.h
lldb/source/Host/macosx/Host.mm
lldb/source/lldb-log.cpp

index 7fc3c01441b74249329c1e31cfbe548080a09c7b..c03da5a26b5f5934b58f6a338dc493f92c59e4ee 100644 (file)
@@ -33,6 +33,7 @@
 #define LIBLLDB_LOG_OBJECT              (1u << 11)
 #define LIBLLDB_LOG_COMMUNICATION       (1u << 12)
 #define LIBLLDB_LOG_CONNECTION          (1u << 13)
+#define LIBLLDB_LOG_HOST                (1u << 14)
 #define LIBLLDB_LOG_ALL                 (UINT32_MAX)
 #define LIBLLDB_LOG_DEFAULT             (LIBLLDB_LOG_PROCESS     |\
                                          LIBLLDB_LOG_THREAD      |\
index f32f92992e9a141aace58b1dd9527504d7e8c928..70f2886e0936bb8a02ea234bc0fabf0ea07864f2 100644 (file)
@@ -795,6 +795,7 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
         uint32_t  reserved2;  // must be zero
     } BabelAESelInfo;
     
+    Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_HOST);
     char file_path[PATH_MAX];
     file_spec.GetPath(file_path, PATH_MAX);
     CFCString file_cfstr (file_path, kCFStringEncodingUTF8);
@@ -802,6 +803,9 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
                                                                      file_cfstr.get(), 
                                                                      kCFURLPOSIXPathStyle, 
                                                                      false));
+                                                                     
+    if (log)
+        log->Printf("Sending source file: \"%s\" and line: %d to external editor.\n", file_path, line_no);
     
     OSStatus error;    
     BabelAESelInfo file_and_line_info = 
@@ -823,6 +827,8 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
     
     if (error != noErr)
     {
+        if (log)
+            log->Printf("Error creating AEDesc: %d.\n", error);
         return false;
     }
     
@@ -841,6 +847,9 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
     if (external_editor != NULL)
     {
         bool calculate_fsref = true;
+        if (log)
+            log->Printf("Looking for external editor \"%s\".\n", external_editor);
+
         if (app_name.empty() || strcmp (app_name.c_str(), external_editor) != 0)
         {
             calculate_fsref = true;
@@ -857,7 +866,11 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
             if (error == noErr)
                 app_name.assign (external_editor);
             else
+            {
+                if (log)
+                    log->Printf("Could not find External Editor application, error: %d.\n", error);
                 return false;
+            }
                 
         }
         
@@ -879,6 +892,9 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
 
     if (error != noErr)
     {
+        if (log)
+            log->Printf("LSOpenURLsWithRole failed, error: %d.\n", error);
+
         return false;
     }
     
@@ -888,7 +904,15 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
     which_process.processName = ap_name;
     error = ::GetProcessInformation (&psn, &which_process);
     
-    bool using_xcode = strncmp((char *) ap_name+1, "Xcode", 5) == 0;
+    bool using_xcode;
+    if (error != noErr)
+    {
+        if (log)
+            log->Printf("GetProcessInformation failed, error: %d.\n", error);
+        using_xcode = false;
+    }
+    else
+        using_xcode = strncmp((char *) ap_name+1, "Xcode", (int) ap_name[0]) == 0;
     
     // Xcode doesn't obey the line number in the Open Apple Event.  So I have to send
     // it an AppleScript to focus on the right line.
@@ -916,6 +940,8 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
         
         if (osa_component == NULL)
         {
+            if (log)
+                log->Printf("Could not get default AppleScript component.\n");
             return false;
         }
 
@@ -937,7 +963,11 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
         ::free (as_str);
 
         if (error != noErr)
+        {
+            if (log)
+                log->Printf("Failed to create AEDesc for Xcode AppleEvent: %d.\n", error);
             return false;
+        }
             
         OSAID ret_OSAID;
         error = ::OSACompileExecute (osa_component, 
@@ -951,7 +981,11 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
         ::AEDisposeDesc (&as_desc);
 
         if (error != noErr)
+        {
+            if (log)
+                log->Printf("Sending AppleEvent to Xcode failed, error: %d.\n", error);
             return false;
+        }
     }
       
     return true;
index 57a207220e95df9d39543729b036d26ffe73d129..4e291fab4abd71da161f6a974184687ed5995864 100644 (file)
@@ -151,6 +151,7 @@ lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &ar
             else if (strcasestr(arg, "temp")   == arg)  flag_bits |= LIBLLDB_LOG_TEMPORARY;
             else if (strcasestr(arg, "comm")   == arg)  flag_bits |= LIBLLDB_LOG_COMMUNICATION;
             else if (strcasestr(arg, "conn")   == arg)  flag_bits |= LIBLLDB_LOG_CONNECTION;
+            else if (strcasestr(arg, "host")   == arg)  flag_bits |= LIBLLDB_LOG_HOST;
             else
             {
                 feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);