diff options
author | dim <dim@FreeBSD.org> | 2016-01-06 20:12:03 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2016-01-06 20:12:03 +0000 |
commit | 78b9749c0a4ea980a8b934645da6ae98fcc665e8 (patch) | |
tree | dd2a1ddf0476664c2b823409c36cbccd52662ca7 /packages/Python/lldbsuite/test/crashinfo.c | |
parent | 60cb593f9d55fa5ca7a5372b731f2330345b4b9a (diff) | |
download | FreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.zip FreeBSD-src-78b9749c0a4ea980a8b934645da6ae98fcc665e8.tar.gz |
Vendor import of lldb trunk r256945:
https://llvm.org/svn/llvm-project/lldb/trunk@256945
Diffstat (limited to 'packages/Python/lldbsuite/test/crashinfo.c')
-rw-r--r-- | packages/Python/lldbsuite/test/crashinfo.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/crashinfo.c b/packages/Python/lldbsuite/test/crashinfo.c new file mode 100644 index 0000000..1901346 --- /dev/null +++ b/packages/Python/lldbsuite/test/crashinfo.c @@ -0,0 +1,64 @@ +/****************************************************************************** + 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 +******************************************************************************/ + +#include <Python/Python.h> +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +void *__crashreporter_info__ = NULL; + +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 > 0 && data) + { + ++size; // Include the NULL terminateor in allocation and memcpy() + __crashreporter_info__ = malloc(size); + memcpy(__crashreporter_info__, data, size); + 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); +} + |