summaryrefslogtreecommitdiff
path: root/cad/src/gdb_help.c
blob: 8d7f9ed1e407a37b15e3dc83eca2c3f83c672a26 (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
// Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details.
/*
 * gcc -I/usr/include/python2.4 -g -Wall -c -o gdb_help.o gdb_help.c
 * gcc -shared -o gdb_help.so gdb_help.o
 */

static char const svnId[] = "$Id$";

#include <stdio.h>
#include <unistd.h>
#include "Python.h"


#define DEBUG 1

#if DEBUG
#define MARK()  \
  fprintf(stderr, __FILE__ ":%d\n", __LINE__); fflush(stderr)
#define DBGPRINTF(fmt)  \
  fprintf(stderr, __FILE__ ":%d " fmt, __LINE__); fflush(stderr)
#define DBGPRINTF1(fmt,a)  \
  fprintf(stderr, __FILE__ ":%d " fmt, __LINE__, a); fflush(stderr)
#define DBGPRINTF2(fmt,a,b)  \
  fprintf(stderr, __FILE__ ":%d " fmt, __LINE__, a, b); fflush(stderr)
#define DBGPRINTF3(fmt,a,b,c)  \
  fprintf(stderr, __FILE__ ":%d " fmt, __LINE__, a, b, c); fflush(stderr)
#else
#define MARK()
#define DBGPRINTF(fmt)
#define DBGPRINTF1(fmt,a)
#define DBGPRINTF2(fmt,a,b)
#define DBGPRINTF3(fmt,a,b,c)
#endif

static PyObject *
stop(PyObject *self, PyObject *args)
{
    int x = 0, y;
    if (!PyArg_ParseTuple(args, ""))
	return NULL;
    y = 1 / x;  // force a divide-by-zero error to make GDB stop
    Py_INCREF(Py_None);
    return Py_None;
}


static struct PyMethodDef gdb_help_methods[] = {
    {"stop",   stop, 1},
    {NULL,       NULL}
};

static char gdb_help_doc [] =
"This module has some handy functions for working with Python in GDB.\n\
\n\
stop()  ==> force a divide-by-zero to make GDB stop";

void
initgdb_help()
{
    /* Create the module and add the functions */
    Py_InitModule3("gdb_help", gdb_help_methods, gdb_help_doc);
}