google / pyringe

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

gdb: unrecognised option '--nh' #13

Closed andrewmichaelsmith closed 10 years ago

andrewmichaelsmith commented 10 years ago

I've received the following when trying to attach to a process:

For a list of debugger commands, try "help()". (python's help is available as pyhelp.)
==> pid:[None] #threads:[0] current thread:[None]
>>> attach(31043)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/repl.py", line 157, in Attach
    self.inferior.Reinit(pid)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 418, in Reinit
    self.__init__(pid, auto_symfile_loading)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 390, in __init__
    self.StartGdb()
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 437, in StartGdb
    self._gdb.Attach(self.position)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 181, in <lambda>
    return lambda *args, **kwargs: self._Execute(name, *args, **kwargs)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 277, in _Execute
    result_string = self._Recv(timeout)
  File "/home/asmith/.local/lib/python2.7/site-packages/pyringe/inferior.py", line 362, in _Recv
    raise ProxyError(exc_text)
ProxyError: gdb: unrecognised option '--nh'
Use `gdb --help' for a complete list of options.

I assume there's some gdb version mismatch:

GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.
TehMillhouse commented 10 years ago

Of all the flags that are given to gdb, I wouldn't have expected --nh to be a problem on other distros. For the time being, could you try the following for starting the debugger:

import pyringe
pyringe.inferior._GDB_ARGS.remove('--nh')
pyringe.interact()

I'll try to think of a generic way to get this to work, in the meantime, knowing which flags cause problems on some distros will help.

andrewmichaelsmith commented 10 years ago

Thanks, that workaround did the trick. I'll try it on some other distros and let you know if I come across any more.

mckelvin commented 10 years ago

I come across the same issue, but the trick does not works.

In [1]: import pyringe

In [2]: pyringe.inferior._GDB_ARGS
Out[2]: ['gdb', '--nh', '--nw', '--quiet', '--batch-silent']

In [3]: pyringe.inferior._GDB_ARGS.remove('--nh')

In [4]: pyringe.interact()
Pyringe (Python 2.7.5) on linux2
For a list of debugger commands, try "help()". (python's help is available as pyhelp.)
==> pid:[None] #threads:[0] current thread:[None]
In : attach(10987)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/repl.py", line 157, in Attach
    self.inferior.Reinit(pid)
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/inferior.py", line 418, in Reinit
    self.__init__(pid, auto_symfile_loading)
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/inferior.py", line 390, in __init__
    self.StartGdb()
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/inferior.py", line 437, in StartGdb
    self._gdb.Attach(self.position)
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/inferior.py", line 181, in <lambda>
    return lambda *args, **kwargs: self._Execute(name, *args, **kwargs)
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/inferior.py", line 277, in _Execute
    result_string = self._Recv(timeout)
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/inferior.py", line 362, in _Recv
    raise ProxyError(exc_text)
ProxyError:
-----------------------------------
Error occurred within GdbService:
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/payload/gdb_service.py", line 652, in <module>
    serv.EvalLoop()
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/payload/gdb_service.py", line 274, in EvalLoop
    while self._AcceptRPC():
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/payload/gdb_service.py", line 293, in _AcceptRPC
    rpc_result = getattr(self, request['func'])(*request['args'])
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/payload/gdb_service.py", line 429, in Attach
    self.selected_tstate = self._ThreadPtrs(pos)[0]
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/payload/gdb_service.py", line 454, in _ThreadPtrs
    self.EnsureGdbPosition(position[0], None, None)
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/payload/gdb_service.py", line 333, in EnsureGdbPosition
    if not self.IsAttached():
  File "/home/username/.local/lib64/python2.7/site-packages/pyringe/payload/gdb_service.py", line 366, in IsAttached
    inf = gdb.selected_inferior()
AttributeError: 'module' object has no attribute 'selected_inferior'

GNU gdb (Gentoo 7.3.1 p2) 7.3.1 Linux hostname 3.0.36-gentoo

TehMillhouse commented 10 years ago

@mckelvin Your issue seems to be a different one. Digging in the gdb release schedule and the gdb changelog (first copy I could find online, search for the patch "PR Python/12692"), it looks like while python scripting was introduced in gdb 7.3, significant portions of the python API were only added after its release.

I will bump the required version of gdb to 7.4. Try getting a more recent version of gdb, that should fix the issue you're seeing.

devunt commented 10 years ago

--nh flag was introduced in gdb 7.6.1 stable (actually 7.6-1 unstable), but Ubuntu precise's official repo have gdb 7.4

TehMillhouse commented 10 years ago

@devunt Thanks for tracking this change down. I finally got around to adding a quick version check. Shouldn't be an issue anymore since 8fce35c1915cd78743c8bf38ffa6d7028d9f82bc.