hawkeye001 / google-breakpad

Automatically exported from code.google.com/p/google-breakpad
0 stars 0 forks source link

Breakpad/mac uses try/catch in two files, which doesn't build with -fno-exceptions if libstdc++ isn't used #509

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
client/mac/Framework/Breakpad.mm and client/mac/handler/exception_handler.cc 
use try/catch. When building with clang and -fno-exceptions, clang will point 
out that try and catch can't be used with -fno-exceptions.

However, libstdc++'s exception_defines.h 
(/usr/include/c++/4.2.1/exception_defines.h) defines try to "if (true)" and 
catch(X) to "if (false)", so this issue is only visible when not building with 
libstdc++. (gcc4.4+ removes these defines too, so building with a newer 
libstdc++ would show this issue too).

I'm not sure what the best fix is; the patch below preserves the status quo 
(also note the unrelated additional "import <pthread.h>", which is also 
necessary with libc++):

Index: client/mac/Framework/Breakpad.mm
===================================================================
--- client/mac/Framework/Breakpad.mm    (revision 1082)
+++ client/mac/Framework/Breakpad.mm    (working copy)
@@ -42,6 +42,7 @@
 #import "client/mac/Framework/Breakpad.h"

 #import <Foundation/Foundation.h>
+#import <pthread.h>
 #import <sys/stat.h>
 #import <sys/sysctl.h>

@@ -53,6 +54,22 @@
 #import "common/mac/MachIPC.h"
 #import "common/mac/SimpleStringDictionary.h"

+// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25191
+#ifndef __EXCEPTIONS
+
+#ifdef try
+#undef try
+#endif
+
+#ifdef catch
+#undef catch
+#endif
+
+// Iff -fno-exceptions, transform error handling code to work without it.
+# define try      if (true)
+# define catch(X) if (false)
+#endif
+
 using google_breakpad::KeyValueEntry;
 using google_breakpad::MachPortSender;
 using google_breakpad::MachReceiveMessage;
Index: client/mac/handler/exception_handler.cc
===================================================================
--- client/mac/handler/exception_handler.cc (revision 1082)
+++ client/mac/handler/exception_handler.cc (working copy)
@@ -57,6 +57,22 @@
   extern ProtectedMemoryAllocator *gBreakpadAllocator;
 #endif

+// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25191
+#ifndef __EXCEPTIONS
+
+#ifdef try
+#undef try
+#endif
+
+#ifdef catch
+#undef catch
+#endif
+
+// Iff -fno-exceptions, transform error handling code to work without it.
+# define try      if (true)
+# define catch(X) if (false)
+#endif
+
 namespace google_breakpad {

 static union {

Original issue reported on code.google.com by thakis@chromium.org on 10 Dec 2012 at 7:20

GoogleCodeExporter commented 9 years ago
https://breakpad.appspot.com/503002/

Original comment by mark@chromium.org on 10 Dec 2012 at 7:50

GoogleCodeExporter commented 9 years ago
r1089

Original comment by mark@chromium.org on 11 Dec 2012 at 1:47