GDB 7.2 - Patch proposal for the use of GDB/Python scripts on MinGW

Serge CHATROUX serge.chatroux@st.com
Fri Sep 10 13:58:00 GMT 2010


I compile gdb 7.2 using MINGW tools and I enable the Python scripting support by giving the path to a Python for Windows install directory.

    gdb/configure --with-x=no --with-python=/c/DATA/tmp/build/MINGW32_NT-5.1/install-python 

Python for windows
------------------

I get the python 2.6.x from http://www.python.org/download/

I have to make some modifications in Python distribution because header files and libraries directories are not the same between Linux and Windows Python distribution.
In order to fit gdb sources (Linux-based), I modify the Python distribution:

- Go to python windows install directory
- Create directory include\python2.6
- Move files from include to include\python2.6
- Copy file libs\libpython26.a to lib directory and rename it to libpython2.6.a

In the future, it could be useful that GDB sources (configure, Makefile.in) fit also Python  Windows-specific packaging.

GDB modifications
-----------------

I also modify the gdb/python sources to solve the following issues:

- Add some tests to disable Python scripting if Python is not available on the host at runtime. 
  I detect if the PYTHONHOME variable is set. This enhancement is maybe not useful for everybody.
- I have to modify some gdb python files because the files 'python-function.c', python-cmd.c (...) define some 'static PyTypeObject'.
  The field 'tp_new' of these static variables is statically initialized with the python 'PyType_GenericNew' function. 
  In Windows port of Python, this function is declared as a dllimport one and cannot be copied at compilation time in a static variable.
  For these files, I modified the source code
      - to initialize the 'tp_new' fields to '0' in the static variables and
      - to affect the proper 'PyType_GenericNew' value in the 'gdbpy_initialize_commands', 'gdbpy_initialize_frames' (...). 
- I also modified python-config.py to get python shared library path when Python is compiled in shared library mode. Otherwise the shared library is taken from Linux distribution, not from the Python given by --with-python flag.
- When sourcing a Python script using 'source file.py' command, we cannot use 'PyRun_SimpleFile' because Python may not be compiled using the same MSVCRT DLL than GDB, so the FILE* stream will not be known in this DLL.
  This generates an error when the MSVCRT will try to lock the file handle.

I hope that this patch will be useful and that I followed the gdb coding rules.

Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdb.python-for-mingw.diff
Type: application/octet-stream
Size: 15076 bytes
Desc: gdb.python-for-mingw.diff
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20100910/d7ac309a/attachment.obj>


More information about the Gdb-patches mailing list