Python enabled gdb on Windows and relocation

Ruben Van Boxem
2011-05-12T16:20:41Z

(now in plain-text as required by gdb mailing list)

Hi,

I am currently trying to integrate Python support into my toolchain
build (including GDB of course). It is a sysrooted
binutils+GCC+GDB+mingw-w64 toolchain.

I currently have the basic setup working: I can link gdb with my
manually generated import lib to the python dll from the official
Windows install. If there is anything I am missing or a very easy
solution to the problems decsribed below, please just say so. I am
only suggesting what I would like to happen.

Now on to the problems I'd like to discuss:

1. gdb.exe won't start without me having set PYTHONPATH manually. I
understand the need for this, but as gdb requires Python 2, and users
of my toolchain may have installed Python 3 or a 32-bit version python
they want to use from the same environment (without changing their own
PYTHONPATH), there is no way to run python-enabled gdb. What I suggest
is perhaps a Windows only change: a kind of "sysroot"ed gdb+python, so
that the python used by gdb is truly built in. I cannot require
everyone using my toolchain to install the correct python version for
obvious reasons (Windows != Linux in this regard). However way this is
tackled, the gdb I want should look relative to it's current
(relocatable) directory for Python modules/*;py files in a
well-defined directory at build time. That would allow me to
distribute gdb in a very clear way:

<sysroot>
<sysroot>/bin
<sysroot>/bin/python27.dll
<sysroot>/bin/gdb.exe
<sysroot>/lib
<sysroot>/lib/python27
<sysroot>/lib/python27/<all *.py files from the official windows install>

Currently, this scheme only works if I manually set the PYTHONPATH
environment variable to <root>/lib/python27. This global environment
variable could conflict with existing Python installations, that may
have another bitness (I have 64- and 32-bit toolchains). I think you
can see there are problems enough with the current set up. I also read
this old discussion:
http://comments.gmane.org/gmane.comp.gdb.patches/62811 that might
imply that the PYTHONPATH check is something built-in to the python
dll. Can anyone shed some light on this?

2. With PYTHONPATH set as a temporary workaround, gdb starts, but
spits out a traceback:
Traceback (most recent call last):
File "<string>", line 35, in <module>
File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line
18, in <module>
gdb.command.pretty_printers.register_pretty_printer_commands()
File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py",
line 368, in register_pretty_printer_commands
InfoPrettyPrinter()
File "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py",
line 100, in __init__
gdb.COMMAND_DATA)
RuntimeError: Could not find command prefix info.

This is a minor problem I think, as "python import time" "python print
time.clock()" works as expected. What is wrong?

Thanks very much!

Ruben

PS: I've sent this to both the gdb and python mailing lists, as these
issues have a large overlap to both projects.
PS2: Please reply-to-all as I do not want daily mails from both
mailing lists on every issue brought up there. My apologies.