summaryrefslogtreecommitdiffstats
path: root/packages/Python/lldbsuite/test/crashinfo.c
blob: 19013468bb260e28c11ca72fad29aaf316b6d26f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);
}

OpenPOWER on IntegriCloud