Add some routines to wsutil to, at least on some platforms, add
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 15 Jan 2013 21:54:41 +0000 (21:54 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 15 Jan 2013 21:54:41 +0000 (21:54 +0000)
information to crash dumps and the like.  (Currently, we only handle OS
X's CrashReporter, but we should do this on other platforms where this
information can be added and would be helpful.)

White space tweaks.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@47104 f5534014-38df-0310-8fa8-9805f1628bb7

dumpcap.c
rawshark.c
tshark.c
wsutil/Makefile.common
wsutil/crash_info.c [new file with mode: 0644]
wsutil/crash_info.h [new file with mode: 0644]
wsutil/libwsutil.def

index 90571c47401fe83d8ead0145a1e8712bc9675a50..37834b63eaea8d00ba5b6a1bdd755aa57f36a1ab 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -65,6 +65,8 @@
 #include <signal.h>
 #include <errno.h>
 
+#include <wsutil/crash_info.h>
+
 #ifndef HAVE_GETOPT
 #include "wsutil/wsgetopt.h"
 #endif
@@ -510,7 +512,7 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
         "%s\n"
         "%s\n"
         "See http://www.wireshark.org for more information.\n",
-        wireshark_svnversion, get_copyright_info() ,comp_info_str->str, runtime_info_str->str);
+        wireshark_svnversion, get_copyright_info()comp_info_str->str, runtime_info_str->str);
 }
 
 /*
@@ -4125,6 +4127,8 @@ out:
 int
 main(int argc, char *argv[])
 {
+    GString          *comp_info_str;
+    GString          *runtime_info_str;
     int               opt;
     gboolean          arg_error             = FALSE;
 
@@ -4155,6 +4159,22 @@ main(int argc, char *argv[])
 #endif
     GString          *str;
 
+    /* Assemble the compile-time version information string */
+    comp_info_str = g_string_new("Compiled ");
+    get_compiled_version_info(comp_info_str, NULL, NULL);
+
+    /* Assemble the run-time version information string */
+    runtime_info_str = g_string_new("Running ");
+    get_runtime_version_info(runtime_info_str, NULL);
+
+    /* Add it to the information to be reported on a crash. */
+    ws_add_crash_info("Dumpcap " VERSION "%s\n"
+           "\n"
+           "%s"
+           "\n"
+           "%s",
+        wireshark_svnversion, comp_info_str->str, runtime_info_str->str);
+
 #ifdef _WIN32
     arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
@@ -4458,15 +4478,6 @@ main(int argc, char *argv[])
             break;
         case 'v':        /* Show version and exit */
         {
-            GString *comp_info_str;
-            GString *runtime_info_str;
-            /* Assemble the compile-time version information string */
-            comp_info_str = g_string_new("Compiled ");
-            get_compiled_version_info(comp_info_str, NULL, NULL);
-
-            /* Assemble the run-time version information string */
-            runtime_info_str = g_string_new("Running ");
-            get_runtime_version_info(runtime_info_str, NULL);
             show_version(comp_info_str, runtime_info_str);
             g_string_free(comp_info_str, TRUE);
             g_string_free(runtime_info_str, TRUE);
index 67bd6998e3c4c2726634900a3511cfdf79d48995..28275f23b86fd45b1eb43c368fe91b3246a05a07 100644 (file)
@@ -66,6 +66,7 @@
 #include <glib.h>
 #include <epan/epan.h>
 #include <epan/filesystem.h>
+#include <wsutil/crash_info.h>
 #include <wsutil/privileges.h>
 #include <wsutil/file_util.h>
 
@@ -423,6 +424,8 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
 int
 main(int argc, char *argv[])
 {
+    GString             *comp_info_str;
+    GString             *runtime_info_str;
     char                *init_progfile_dir_error;
     int                  opt, i;
     gboolean             arg_error = FALSE;
@@ -451,6 +454,22 @@ main(int argc, char *argv[])
 
     static const char    optstring[] = OPTSTRING_INIT;
 
+    /* Assemble the compile-time version information string */
+    comp_info_str = g_string_new("Compiled ");
+    get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info);
+
+    /* Assemble the run-time version information string */
+    runtime_info_str = g_string_new("Running ");
+    get_runtime_version_info(runtime_info_str, NULL);
+
+    /* Add it to the information to be reported on a crash. */
+    ws_add_crash_info("Rawshark " VERSION "%s\n"
+           "\n"
+           "%s"
+           "\n"
+           "%s",
+        wireshark_svnversion, comp_info_str->str, runtime_info_str->str);
+
 #ifdef _WIN32
     arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
@@ -697,15 +716,6 @@ main(int argc, char *argv[])
                 break;
             case 'v':        /* Show version and exit */
             {
-                GString             *comp_info_str;
-                GString             *runtime_info_str;
-                /* Assemble the compile-time version information string */
-                comp_info_str = g_string_new("Compiled ");
-                get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info);
-
-                /* Assemble the run-time version information string */
-                runtime_info_str = g_string_new("Running ");
-                get_runtime_version_info(runtime_info_str, NULL);
                 show_version(comp_info_str, runtime_info_str);
                 g_string_free(comp_info_str, TRUE);
                 g_string_free(runtime_info_str, TRUE);
index e5748ef21796ca7f2b5bee8306fa7ed225eed994..5890013a932d47123ab9bdc7c9d7f901a0d7fe77 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -56,6 +56,7 @@
 #include <glib.h>
 #include <epan/epan.h>
 #include <epan/filesystem.h>
+#include <wsutil/crash_info.h>
 #include <wsutil/privileges.h>
 #include <wsutil/file_util.h>
 
@@ -860,6 +861,8 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
 int
 main(int argc, char *argv[])
 {
+  GString             *comp_info_str;
+  GString             *runtime_info_str;
   char                *init_progfile_dir_error;
   int                  opt;
   gboolean             arg_error = FALSE;
@@ -929,6 +932,22 @@ main(int argc, char *argv[])
 
   static const char    optstring[] = OPTSTRING;
 
+  /* Assemble the compile-time version information string */
+  comp_info_str = g_string_new("Compiled ");
+  get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info);
+
+  /* Assemble the run-time version information string */
+  runtime_info_str = g_string_new("Running ");
+  get_runtime_version_info(runtime_info_str, NULL);
+
+  /* Add it to the information to be reported on a crash. */
+  ws_add_crash_info("TShark " VERSION "%s\n"
+         "\n"
+         "%s"
+         "\n"
+         "%s",
+      wireshark_svnversion, comp_info_str->str, runtime_info_str->str);
+
 #ifdef _WIN32
   arg_list_utf_16to8(argc, argv);
 #if !GLIB_CHECK_VERSION(2,31,0)
@@ -1430,15 +1449,6 @@ main(int argc, char *argv[])
       break;
     case 'v':         /* Show version and exit */
     {
-      GString             *comp_info_str;
-      GString             *runtime_info_str;
-      /* Assemble the compile-time version information string */
-      comp_info_str = g_string_new("Compiled ");
-      get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info);
-
-      /* Assemble the run-time version information string */
-      runtime_info_str = g_string_new("Running ");
-      get_runtime_version_info(runtime_info_str, NULL);
       show_version(comp_info_str, runtime_info_str);
       g_string_free(comp_info_str, TRUE);
       g_string_free(runtime_info_str, TRUE);
index 9462bffbcd28f4be5adfe39327b5a50a4134236d..570dbe60daa0eea125a0b6e1682fd38852de1da3 100644 (file)
@@ -30,6 +30,7 @@
 # _SOURCES variables).
 LIBWSUTIL_SRC =        \
        airpdcap_wep.c  \
+       crash_info.c    \
        crc6.c          \
        crc7.c          \
        crc8.c          \
@@ -46,6 +47,7 @@ LIBWSUTIL_SRC =       \
 
 # Header files that are not generated from other files
 LIBWSUTIL_INCLUDES =   \
+       crash_info.h    \
        crc6.h          \
        crc7.h          \
        crc8.h          \
diff --git a/wsutil/crash_info.c b/wsutil/crash_info.c
new file mode 100644 (file)
index 0000000..e8fab55
--- /dev/null
@@ -0,0 +1,166 @@
+/* crash_info.c
+ * Routines to try to provide more useful information in crash dumps.
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2006 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <glib.h>
+
+#include "crash_info.h"
+
+#ifdef __APPLE__
+/*
+ * Copyright 2005-2012 Apple Inc. All rights reserved.
+ *
+ * IMPORTANT:  This Apple software is supplied to you by Apple Computer,
+ * Inc. ("Apple") in consideration of your agreement to the following
+ * terms, and your use, installation, modification or redistribution of
+ * this Apple software constitutes acceptance of these terms.  If you do
+ * not agree with these terms, please do not use, install, modify or
+ * redistribute this Apple software.
+ *
+ * In consideration of your agreement to abide by the following terms, and
+ * subject to these terms, Apple grants you a personal, non-exclusive
+ * license, under Apple's copyrights in this original Apple software (the
+ * "Apple Software"), to use, reproduce, modify and redistribute the Apple
+ * Software, with or without modifications, in source and/or binary forms;
+ * provided that if you redistribute the Apple Software in its entirety and
+ * without modifications, you must retain this notice and the following
+ * text and disclaimers in all such redistributions of the Apple Software.
+ * Neither the name, trademarks, service marks or logos of Apple Computer,
+ * Inc. may be used to endorse or promote products derived from the Apple
+ * Software without specific prior written permission from Apple.  Except
+ * as expressly stated in this notice, no other rights or licenses, express
+ * or implied, are granted by Apple herein, including but not limited to
+ * any patent rights that may be infringed by your derivative works or by
+ * other works in which the Apple Software may be incorporated.
+ *
+ * The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
+ * MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
+ * OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
+ *
+ * IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
+ * MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
+ * AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
+ * STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+/*
+ * This used to be the way to add an application-specific string to
+ * crash dumps; see
+ *
+ *     http://www.allocinit.net/blog/2008/01/04/application-specific-information-in-leopard-crash-reports/
+ *
+ * It still appears to work as of OS X 10.8 (Mountain Lion).
+ */
+__private_extern__ char *__crashreporter_info__ = NULL;
+
+#if 0
+/*
+ * And this appears to be the new way to do it, as of Lion.
+ * However, if we do both, we get the message twice, so we're
+ * not doing this one, for now.
+ *
+ * This code was lifted from SVN trunk CUPS.
+ */
+#define _crc_make_getter(attr, type) (type)(gCRAnnotations.attr)
+#define _crc_make_setter(attr, arg) (gCRAnnotations.attr = (uint64_t)(unsigned long)(arg))
+#define CRASH_REPORTER_CLIENT_HIDDEN __attribute__((visibility("hidden")))
+#define CRASHREPORTER_ANNOTATIONS_VERSION 4
+#define CRASHREPORTER_ANNOTATIONS_SECTION "__crash_info"
+
+/*
+ * Yes, these are all 64-bit, even on 32-bit platforms.
+ *
+ * version is presumably the version of this structure.
+ *
+ * message and message2 are reported, one after the other,
+ * under "Application Specific Information".
+ *
+ * signature_string is reported under "Application Specific
+ * Signatures".
+ *
+ * backtrace is reported under "Application Specific Backtrace".
+ *
+ * Dunno which versions are supported by which versions of OS X.
+ */
+struct crashreporter_annotations_t {
+       uint64_t version;               // unsigned long
+       uint64_t message;               // char *
+       uint64_t signature_string;      // char *
+       uint64_t backtrace;             // char *
+       uint64_t message2;              // char *
+       uint64_t thread;                // uint64_t
+       uint64_t dialog_mode;           // unsigned int
+};
+
+CRASH_REPORTER_CLIENT_HIDDEN
+struct crashreporter_annotations_t gCRAnnotations
+    __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) = {
+       CRASHREPORTER_ANNOTATIONS_VERSION,      /* version */
+       0,                                      /* message */
+       0,                                      /* signature_string */
+       0,                                      /* backtrace */
+       0,                                      /* message2 */
+       0,                                      /* thread */
+       0                                       /* dialog_mode */
+};
+
+#define CRSetCrashLogMessage(m) _crc_make_setter(message, m)
+#endif
+
+void
+ws_add_crash_info(const char *fmt, ...)
+{
+       va_list ap;
+       char *m, *old_info, *new_info;
+
+       va_start(ap, fmt);
+       vasprintf(&m, fmt, ap);
+       va_end(ap);
+       if (__crashreporter_info__ == NULL)
+               __crashreporter_info__ = m;
+       else {
+               old_info = __crashreporter_info__;
+               asprintf(&new_info, "%s\n%s", old_info, m);
+               free(m);
+               __crashreporter_info__ = new_info;
+               free(old_info);
+       }
+}
+
+#else
+void
+ws_add_crash_info(const char *fmt _U_, ...)
+{
+}
+#endif
diff --git a/wsutil/crash_info.h b/wsutil/crash_info.h
new file mode 100644 (file)
index 0000000..43ccc5c
--- /dev/null
@@ -0,0 +1,39 @@
+/* crash_info.h
+ * Routines to try to provide more useful information in crash dumps.
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2006 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __CRASH_INFO_H__
+#define __CRASH_INFO_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void ws_add_crash_info(const char *fmt, ...)
+    G_GNUC_PRINTF(1,2);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CRASH_INFO_H__ */
index 568885685a3e66649a158f0cafd46e85bdc14a08..49b9a39286da9769dba76558c2e7b925761fa9e7 100644 (file)
@@ -11,6 +11,9 @@ EXPORTS
 ; airpdcap.c
 AirPDcapWepDecrypt
 
+; crash_info.c
+ws_add_crash_info
+
 ; crc6.c
 update_crc6_by_bytes