blob: 229919258ecc6bba1b179f9b370113dfe33e3723 [file] [log] [blame]
Enrico Granata2c3f1402013-12-12 00:02:05 +00001/******************************************************************************
2 The LLVM Compiler Infrastructure
3
4 This file is distributed under the University of Illinois Open Source
5 License. See LICENSE.TXT for details.
6 ******************************************************************************
7
8* This C file vends a simple interface to set the Application Specific Info
9* on Mac OS X through Python. To use, compile as a dylib, import crashinfo
10* and call crashinfo.setCrashReporterDescription("hello world")
11* The testCrashReporterDescription() API is simply there to let you test that this
12* is doing what it is intended to do without having to actually cons up a crash
13*
14* WARNING: LLDB is using the prebuilt crashinfo.so rather than rebuilding this
15* from scratch each time - rebuild manually if you need to change this module
16******************************************************************************/
17
18#include <Python/Python.h>
19#include <stdlib.h>
20#include <string.h>
21#include <stdio.h>
22
23extern void *__crashreporter_info__;
24
25asm(".desc ___crashreporter_info__, 0x10");
26
27static PyObject* setCrashReporterDescription(PyObject* self, PyObject* string)
28{
29 if (__crashreporter_info__)
30 {
31 free(__crashreporter_info__);
32 __crashreporter_info__ = NULL;
33 }
34
35 if (string && PyString_Check(string))
36 {
37 Py_ssize_t size = PyString_Size(string);
38 char* data = PyString_AsString(string);
39 if (size && data)
40 {
41 __crashreporter_info__ = malloc(size);
42 memcpy(__crashreporter_info__,data,size+1);
43 return Py_True;
44 }
45 }
46 return Py_False;
47}
48
49static PyObject* testCrashReporterDescription(PyObject*self, PyObject* arg)
50{
51 int* ptr = 0;
52 *ptr = 1;
53 return Py_None;
54}
55
56static PyMethodDef crashinfo_methods[] = {
57 {"setCrashReporterDescription", setCrashReporterDescription, METH_O},
58 {"testCrashReporterDescription", testCrashReporterDescription, METH_O},
59 {NULL, NULL}
60};
61
62void initcrashinfo()
63{
64 (void) Py_InitModule("crashinfo", crashinfo_methods);
65}
66