google / pyringe

Debugger capable of attaching to and injecting code into python processes.
Other
1.63k stars 78 forks source link

syntax error in libpython.py #22

Open sdharav opened 9 years ago

sdharav commented 9 years ago

I have installed pyringe in my Ubuntu 14.04 which has GDB 7.7.1. Everything installed fine but when start it and attach the process id I get the following error.

File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/pyringe/repl.py", line 161, in Attach self.inferior.Reinit(pid) File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 484, in Reinit self.init(pid, auto_symfile_loading, architecture=self.arch) File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 456, in init self.StartGdb() File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 503, in StartGdb self._gdb.Attach(self.position) File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 200, in return lambda _args, _kwargs: self._Execute(name, _args, _kwargs) File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 342, in _Execute result_string = self._Recv(timeout) File "/usr/local/lib/python2.7/dist-packages/pyringe/inferior.py", line 427, in _Recv raise ProxyError(exc_text) ProxyError: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/pyringe/payload/gdb_service.py", line 34, in

****here it gives the syntax error ******* in the libpython file import libpython File "/usr/local/lib/python2.7/dist-packages/pyringe/payload/libpython.py", line 58 Py_TPFLAGS_HEAPTYPE = (1L << 9)

Why am I getting that error ?

TehMillhouse commented 9 years ago

As a first piece of information: Though you've correctly installed the pyringe package (i.e. you've installed it as a python2.7 package), as the README states, this isn't the only thing that must be in python2.

I don't have a Ubuntu VM handy right now, but from looking at the current Ubuntu Trusty gdb 7.7.1 package I can tell it depends on libpython3.4, which means point 3 of that listing in the README is the pain point for you.

To get pyringe to work on that Ubuntu release, you'll need to find a version of gdb that still uses libpython2.x.

sdharav commented 9 years ago

if I dont the version of the gdb which uses libpython2.x then should I need to use python3.x ?

TehMillhouse commented 9 years ago

You can't use python3.x with pyringe either, since no part of it is written with python3 support in mind. Neither the part running in the local python process, nor the stubs running within gdb, nor the debugging library (libpython.py from the cpython project) in the version included with pyringe.

It's a shame, but it was only ever intended to debug python2 programs. If you can't find a suitable build of gdb, you're out of luck and can't use pyringe. :(

sdharav commented 9 years ago

is there any way to find a suitable gdb for that ??

TehMillhouse commented 9 years ago

You'll have to do that yourself. While the Ubuntu package listing usually lists dependencies for each package (you'll need one that depends on libpython2), I'm not sure whether they even list old versions of packages.

I found this listing by googling, but I don't know which one's the latest that still links to libpython2. Godspeed.

sdharav commented 9 years ago

Thank you, let me try it.

Mofef commented 5 years ago

In case someone runs into this nowadays:

Debian has a gdb-python2 package that is just gdb linked against python 2.7. On Ubuntu 16.04 I could install the jesse-backport version with dpkg and resolve dependencies afterwards by doing apt-get install -f. It might as well work on other Ubuntu versions. Otherwise, try a different version or install dependencies from the same debian source and try again apt-get install -f until it can resolve the rest for you.

Good luck!

nzjrs commented 5 years ago

If anyone finds this bug, and you want this to work with Python 2.7.15 then you should replace libpython.py in the source tree with the copy from https://github.com/python/cpython/blob/2.7/Tools/gdb/libpython.py

(tested Ubuntu 18.04.3)