Add Python scripting to GDB.
[coreboot.git] / util / crossgcc / patches / gdb-7.3.1_pythonhome.patch
1 diff -ur gdb-7.3.1.orig/gdb/python/python.c gdb-7.3.1/gdb/python/python.c
2 --- gdb-7.3.1.orig/gdb/python/python.c  2011-07-02 21:33:10.000000000 +0200
3 +++ gdb-7.3.1/gdb/python/python.c       2011-11-01 21:07:25.000000000 +0100
4 @@ -33,6 +33,7 @@
5  #include "python.h"
6  
7  #include <ctype.h>
8 +#include <libgen.h>
9  
10  /* True if we should print the stack when catching a Python error,
11     false otherwise.  */
12 @@ -1010,6 +1011,15 @@
13                              SLASH_STRING, "python", NULL));
14  #endif
15  
16 +  char readlinkbuffer[BUFSIZ];
17 +  int readlinks = readlink("/proc/self/exe", readlinkbuffer, BUFSIZ - 1);
18 +  readlinkbuffer[readlinks] = 0;
19 +  char *executeablepath = dirname(readlinkbuffer);
20 +  char *pythonhome = malloc(strlen(executeablepath) + strlen("/../") + 2);
21 +  strcpy(pythonhome, executeablepath);
22 +  strcat(pythonhome, "/../");
23 +  setenv("PYTHONHOME", pythonhome, 1);
24 +
25    Py_Initialize ();
26    PyEval_InitThreads ();
27