[Lldb-commits] [lldb] r197095 - <rdar://problem/15640353>

Enrico Granata egranata at apple.com
Wed Dec 11 16:02:05 PST 2013


Author: enrico
Date: Wed Dec 11 18:02:05 2013
New Revision: 197095

URL: http://llvm.org/viewvc/llvm-project?rev=197095&view=rev
Log:
<rdar://problem/15640353>

Add an hook for the test suite into the OSX-only CrashReporter "App-specific info"

This allows the test suite to set the crash info to the name and file location of every test as the test gets executed
If the test suite crashes, the crash log will then report which test is the culprit, even when not using verbose mode

This only works on OSX, and defaults to not doing anything on other platforms, but OS/platform-specific invocations
can be devised by each individual platform


Added:
    lldb/trunk/test/crashinfo.c
    lldb/trunk/test/crashinfo.so   (with props)
Modified:
    lldb/trunk/test/dotest.py

Added: lldb/trunk/test/crashinfo.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/crashinfo.c?rev=197095&view=auto
==============================================================================
--- lldb/trunk/test/crashinfo.c (added)
+++ lldb/trunk/test/crashinfo.c Wed Dec 11 18:02:05 2013
@@ -0,0 +1,66 @@
+/******************************************************************************
+                     The LLVM Compiler Infrastructure
+
+  This file is distributed under the University of Illinois Open Source
+  License. See LICENSE.TXT for details.
+ ******************************************************************************
+
+* This C file vends a simple interface to set the Application Specific Info
+* on Mac OS X through Python. To use, compile as a dylib, import crashinfo
+* and call crashinfo.setCrashReporterDescription("hello world")
+* The testCrashReporterDescription() API is simply there to let you test that this
+* is doing what it is intended to do without having to actually cons up a crash
+*
+* WARNING: LLDB is using the prebuilt crashinfo.so rather than rebuilding this
+* from scratch each time - rebuild manually if you need to change this module
+******************************************************************************/
+
+#include <Python/Python.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+extern void *__crashreporter_info__;
+
+asm(".desc ___crashreporter_info__, 0x10");
+
+static PyObject* setCrashReporterDescription(PyObject* self, PyObject* string)
+{
+	if (__crashreporter_info__)
+	{
+		free(__crashreporter_info__);
+		__crashreporter_info__ = NULL;
+	}
+		
+	if (string && PyString_Check(string))
+	{
+		Py_ssize_t size = PyString_Size(string);
+		char* data = PyString_AsString(string);
+		if (size && data)
+		{
+			__crashreporter_info__ = malloc(size);
+			memcpy(__crashreporter_info__,data,size+1);
+			return Py_True;
+		}
+	}
+	return Py_False;
+}
+
+static PyObject* testCrashReporterDescription(PyObject*self, PyObject* arg)
+{
+	int* ptr = 0;
+	*ptr = 1;
+	return Py_None;
+}
+
+static PyMethodDef crashinfo_methods[] = {
+	{"setCrashReporterDescription", setCrashReporterDescription, METH_O},
+	{"testCrashReporterDescription", testCrashReporterDescription, METH_O},
+	{NULL, NULL}
+};
+
+void initcrashinfo()
+{
+	(void) Py_InitModule("crashinfo", crashinfo_methods);
+}
+

Added: lldb/trunk/test/crashinfo.so
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/crashinfo.so?rev=197095&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lldb/trunk/test/crashinfo.so
------------------------------------------------------------------------------
    svn:executable = *

Propchange: lldb/trunk/test/crashinfo.so
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: lldb/trunk/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=197095&r1=197094&r2=197095&view=diff
==============================================================================
--- lldb/trunk/test/dotest.py (original)
+++ lldb/trunk/test/dotest.py Wed Dec 11 18:02:05 2013
@@ -29,6 +29,7 @@ import subprocess
 import sys
 import textwrap
 import time
+import inspect
 import unittest2
 
 if sys.version_info >= (2, 7):
@@ -376,6 +377,17 @@ def validate_categories(categories):
         result.append(category)
     return result
 
+def setCrashInfoHook_Mac(text):
+    import crashinfo
+    crashinfo.setCrashReporterDescription(text)
+
+# implement this in some suitable way for your platform, and then bind it
+# to setCrashInfoHook
+def setCrashInfoHook_NonMac(text):
+    pass
+
+setCrashInfoHook = None
+
 def parseOptionsAndInitTestdirs():
     """Initialize the list of directories containing our unittest scripts.
 
@@ -422,6 +434,7 @@ def parseOptionsAndInitTestdirs():
     global lldb_platform_name
     global lldb_platform_url
     global lldb_platform_working_dir
+    global setCrashInfoHook
 
     do_help = False
 
@@ -535,6 +548,11 @@ def parseOptionsAndInitTestdirs():
         else:
             archs = [platform_machine]
 
+    if platform_system == 'Darwin':
+        setCrashInfoHook = setCrashInfoHook_Mac
+    else:
+        setCrashInfoHook = setCrashInfoHook_NonMac
+
     if args.categoriesList:
         categoriesList = set(validate_categories(args.categoriesList))
         useCategories = True
@@ -1558,6 +1576,8 @@ for ia in range(len(archs) if iterArchs
             def startTest(self, test):
                 if self.shouldSkipBecauseOfCategories(test):
                     self.hardMarkAsSkipped(test)
+                global setCrashInfoHook
+                setCrashInfoHook("%s at %s" % (str(test),inspect.getfile(test.__class__)))
                 self.counter += 1
                 test.test_number = self.counter
                 if self.showAll:





More information about the lldb-commits mailing list