# Porting Google Breakpad



## LeFroid (Sep 24, 2010)

Hello everyone.

Recently I decided to play the MMORPG PlaneShift, but I found out that it doesn't support FreeBSD. So I downloaded the source and followed the compile guide at https://planeshift.svn.sf.net/svnroot/planeshift/trunk/docs/compiling.html but there was a lot of errors when attempting to build it. I've been hacking around with google breakpad (included in the game) which is causing all these errors, but I'm unsure of how to port some linuxisms to freebsd. More specifically, how to deal with the procfs code and memory management.

Here is a diff file of everything I changed so far pertaining to google breakpad and the app I am trying to build that uses it.

```
Index: Jamrules
===================================================================
--- Jamrules	(revision 6212)
+++ Jamrules	(working copy)
@@ -12,7 +12,7 @@
 # and we have not yet included mk/jam/build.jam which provides an emulation
 # layer for Boost.  We can not include build.jam earlier because these flags
 # need to be defined before build.jam is included.  :-(
-COMPILER.CFLAGS.debug += -DCS_DEBUG -g3 ;
+COMPILER.CFLAGS.debug += -DCS_DEBUG -g3 -I/usr/local/include ;
 COMPILER.LFLAGS.debug += -g3 ;
 COMPILER.CFLAGS.profile += -g3 -pg ;
 COMPILER.LFLAGS.profile += -g3 -pg ;
Index: src/tools/wordnet/wnutil.c
===================================================================
--- src/tools/wordnet/wnutil.c	(revision 6212)
+++ src/tools/wordnet/wnutil.c	(working copy)
@@ -17,7 +17,7 @@
 
 #ifdef __unix__
 #ifndef __MACH__
-#include <malloc.h>
+#include <stdlib.h>
 #endif
 #endif
 
Index: src/tools/breakpad/common/linux/file_id.h
===================================================================
--- src/tools/breakpad/common/linux/file_id.h	(revision 6212)
+++ src/tools/breakpad/common/linux/file_id.h	(working copy)
@@ -37,6 +37,36 @@
 
 #include "common/linux/guid_creator.h"
 
+// BSD support
+#include <sys/stat.h>
+#include <errno.h>
+#include <dirent.h>
+#include <fnmatch.h>
+#include <unistd.h>
+#define O_LARGEFILE      0100000
+#define stat64 stat
+#define _stat stat
+#define _getcwd getcwd
+
+#ifndef ElfW
+# ifdef __FreeBSD__
+#  if __ELF_WORD_SIZE == 32
+#   define ElfW(type) Elf32_##type
+#  else
+#   define ElfW(type) Elf64_##type
+#  endif
+# else
+# ifdef __NetBSD__
+#  if ELFSIZE == 32
+#   define ElfW(type) Elf32_##type
+#  else
+#   define ElfW(type) Elf64_##type
+#  endif
+# endif
+# endif
+#endif
+
+
 namespace google_breakpad {
 
 static const size_t kMDGUIDSize = sizeof(MDGUID);
Index: src/tools/breakpad/common/linux/memory.h
===================================================================
--- src/tools/breakpad/common/linux/memory.h	(revision 6212)
+++ src/tools/breakpad/common/linux/memory.h	(working copy)
@@ -30,10 +30,14 @@
 #ifndef CLIENT_LINUX_HANDLER_MEMORY_H_
 #define CLIENT_LINUX_HANDLER_MEMORY_H_
 
+#include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
+
 #include <sys/mman.h>
+#include <sys/conf.h>
 
 #include "common/linux/linux_syscall_support.h"
 
Index: src/tools/breakpad/third_party/linux/src/utilities.cc
===================================================================
--- src/tools/breakpad/third_party/linux/src/utilities.cc	(revision 6212)
+++ src/tools/breakpad/third_party/linux/src/utilities.cc	(working copy)
@@ -40,7 +40,7 @@
 #endif
 #include <time.h>
 #if defined(HAVE_SYSCALL_H)
-#include <syscall.h>                 // for syscall()
+#include <sys/syscall.h>                 // for syscall()
 #elif defined(HAVE_SYS_SYSCALL_H)
 #include <sys/syscall.h>                 // for syscall()
 #endif
Index: src/tools/breakpad/client/linux/handler/exception_handler.cc
===================================================================
--- src/tools/breakpad/client/linux/handler/exception_handler.cc	(revision 6212)
+++ src/tools/breakpad/client/linux/handler/exception_handler.cc	(working copy)
@@ -67,10 +67,13 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <linux/limits.h>
+#include <limits.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
 #include <sys/mman.h>
 #include <sys/signal.h>
 #include <sys/syscall.h>
Index: src/tools/breakpad/client/linux/handler/exception_handler.h
===================================================================
--- src/tools/breakpad/client/linux/handler/exception_handler.h	(revision 6212)
+++ src/tools/breakpad/client/linux/handler/exception_handler.h	(working copy)
@@ -32,6 +32,7 @@
 
 #include <vector>
 #include <string>
+#include <sys/ucontext.h>
 
 #include <signal.h>
 
@@ -145,8 +146,8 @@
   struct CrashContext {
     siginfo_t siginfo;
     pid_t tid;  // the crashing thread.
-    struct ucontext context;
-    struct _libc_fpstate float_state;
+    struct ucontext* context;
+    struct _libc_fpstate* float_state;
   };
 
  private:
Index: Jamfile.in
===================================================================
--- Jamfile.in	(revision 6212)
+++ Jamfile.in	(working copy)
@@ -143,7 +143,7 @@
 
 MsvcGenConfig CURL.AVAILABLE : yes ;
 MsvcGenConfig CURL.DEFINES ;
-MsvcGenConfig CURL.CFLAGS ;
+MsvcGenConfig CURL.CFLAGS : "-I/usr/local/include" ;
 MsvcGenConfig CURL.LFLAGS ;
 MsvcGenConfig CURL.LIBS : libcurl.lib Wldap32.lib Winmm.lib ;
 MsvcGenConfig CURL.LIBS.DEBUG : libcurl.lib Wldap32.lib Winmm.lib ;
```


----------



## TedMielczarek (Oct 4, 2010)

Hey there,

I hack on Google Breakpad, and I can tell you that porting it to BSD is not going to be a simple affair. You're probably not going to be able to simply modify the Linux code and get something working. Breakpad is fairly low-level, and each platform's client implementation is very different. You could certainly write a BSD client implementation using the linux/mac/solaris implementations as a reference, but it's a non-trivial amount of work. If you're just porting this game, it'd probably be simpler to just ifdef out the Breakpad bits to make it compile. The whole purpose of Breakpad is for the original author to be able to receive crash reports from their own builds that they have distributed to users, so having it built in your own builds isn't going to be particularly useful anyway.


----------

