From 448e82f39c472c82620bb52e0644e258b363d562 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Fri, 15 Jun 2018 16:48:20 -0400
Subject: [PATCH] SL-821: Try to add SecondLife.log file to Mac BugSplat crash
 report.

Introduce new header file llappviewermacosx-for-objc.h to publish for
llappdelegate-objc.mm and other Objective-C++ consumers the free functions in
llappviewermacosx.cpp they consume. These were never before declared in any
header file. Apparently, to date, we've been trusting to luck that
Objective-C++ will infer the correct signature from calls -- and that the
calls are correct with respect to the function definitions.  :-P

This gives us a place to introduce a new getLogFilePathname() function to
query LLDir. (We don't simply #include "lldir.h" because of the pervasive use
of BOOL in viewer headers; BOOL means something very different in Objective-C++.)
---
 indra/newview/llappdelegate-objc.mm        | 17 +++++++----
 indra/newview/llappviewermacosx-for-objc.h | 34 ++++++++++++++++++++++
 indra/newview/llappviewermacosx.cpp        |  6 ++++
 3 files changed, 51 insertions(+), 6 deletions(-)
 create mode 100644 indra/newview/llappviewermacosx-for-objc.h

diff --git a/indra/newview/llappdelegate-objc.mm b/indra/newview/llappdelegate-objc.mm
index 8e1ad169c90..ad5398721be 100644
--- a/indra/newview/llappdelegate-objc.mm
+++ b/indra/newview/llappdelegate-objc.mm
@@ -29,6 +29,7 @@
 @import BugsplatMac;
 #endif
 #include "llwindowmacosx-objc.h"
+#include "llappviewermacosx-for-objc.h"
 #include <Carbon/Carbon.h> // Used for Text Input Services ("Safe" API - it's supported)
 
 @implementation LLAppDelegate
@@ -189,18 +190,22 @@
     return true;
 }
 
-#if 0 // defined(LL_BUGSPLAT)
+#if defined(LL_BUGSPLAT)
 
 @implementation BugsplatStartupManagerDelegate
 
 - (BugsplatAttachment *)attachmentForBugsplatStartupManager:(BugsplatStartupManager *)bugsplatStartupManager {
-    NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"example" withExtension:@"json"];
-    NSData *data = [NSData dataWithContentsOfURL:fileURL];
-    
+    std::string logfile = getLogFilePathname();
+    NSString *ns_logfile = [NSString stringWithCString:logfile->c_str()
+                                              encoding:NSUTF8StringEncoding];
+    NSData *data = [NSData dataWithContentsOfFile:ns_logfile];
+
+    // Apologies for the hard-coded log-file basename, but I do not know the
+    // incantation for "$(basename "$logfile")" in this language.
     BugsplatAttachment *attachment = 
-        [[BugsplatAttachment alloc] initWithFilename:@"example.json"
+        [[BugsplatAttachment alloc] initWithFilename:@"SecondLife.log"
                                       attachmentData:data
-                                         contentType:@"application/json"];
+                                         contentType:@"text/plain"];
     return attachment;
 }
 
diff --git a/indra/newview/llappviewermacosx-for-objc.h b/indra/newview/llappviewermacosx-for-objc.h
new file mode 100644
index 00000000000..ef5d90bfefd
--- /dev/null
+++ b/indra/newview/llappviewermacosx-for-objc.h
@@ -0,0 +1,34 @@
+/**
+ * @file   llappviewermacosx-for-objc.h
+ * @author Nat Goodspeed
+ * @date   2018-06-15
+ * @brief  llappviewermacosx.h publishes the C++ API for
+ *         llappviewermacosx.cpp, just as
+ *         llappviewermacosx-objc.h publishes the Objective-C++ API for
+ *         llappviewermacosx-objc.mm.
+ *
+ *         This header is intended to publish for Objective-C++ consumers a
+ *         subset of the C++ API presented by llappviewermacosx.cpp. It's a
+ *         subset because, if an Objective-C++ consumer were to #include
+ *         the full llappviewermacosx.h, we would almost surely run into
+ *         trouble due to the discrepancy between Objective-C++'s BOOL versus
+ *         classic Microsoft/Linden BOOL.
+ * 
+ * $LicenseInfo:firstyear=2018&license=viewerlgpl$
+ * Copyright (c) 2018, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+#if ! defined(LL_LLAPPVIEWERMACOSX_FOR_OBJC_H)
+#define LL_LLAPPVIEWERMACOSX_FOR_OBJC_H
+
+#include <string>
+
+bool initViewer();
+void handleUrl(const char* url_utf8);
+bool pumpMainLoop();
+void handleQuit();
+void cleanupViewer();
+std::string getLogFilePathname();
+
+#endif /* ! defined(LL_LLAPPVIEWERMACOSX_FOR_OBJC_H) */
diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp
index d472f8926b1..cdbdb23d9a8 100644
--- a/indra/newview/llappviewermacosx.cpp
+++ b/indra/newview/llappviewermacosx.cpp
@@ -36,6 +36,7 @@
 #include "llappviewermacosx-objc.h"
 
 #include "llappviewermacosx.h"
+#include "llappviewermacosx-for-objc.h"
 #include "llwindowmacosx-objc.h"
 #include "llcommandlineparser.h"
 
@@ -147,6 +148,11 @@ void cleanupViewer()
 	gViewerAppPtr = NULL;
 }
 
+std::string getLogFilePathname()
+{
+    return gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "SecondLife.log");
+}
+
 int main( int argc, char **argv ) 
 {
 	// Store off the command line args for use later.
-- 
GitLab