Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote debugger hangs if ptrace is not allowed #142

Open
antocuni opened this issue Apr 28, 2021 · 1 comment
Open

Remote debugger hangs if ptrace is not allowed #142

antocuni opened this issue Apr 28, 2021 · 1 comment
Assignees
Milestone

Comments

@antocuni
Copy link
Contributor

antocuni commented Apr 28, 2021

This is problem which I ran into while trying to reproduce #131:

(venv) homer tmp $ py -d 2503089

^C^C^C

i.e., the py script just hangs indefinitely while trying to attach a debugger:

If I try to run gdb -p manually, this is what happens:

(venv) homer tmp $ gdb -p 2503089
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
[...]
Attaching to process 2503089
ptrace: No such process.
(gdb) 

So, I think that what happens under the hood is the following:

  1. attach_debugger spawns gdb
  2. the spawned gdb waits forever for user input (which will never happen)
  3. the watchdog process waits forever for gdb to exit (which will never happen)

The solution is to enable ptrace globally. After running the following command, py -d works again:

(venv) homer tmp $ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

I think that the proper behavior for attach_debugger should be to detect this case and warn the user. E.g.:

  1. read the value of /proc/sys/kernel/yama/ptrace_scope and emit a clear error message, with links to the relevant documentation and maybe suggest to run the command above
  2. try to detect whether the spawned gdb works correctly or not. This is harder because it would mean to modify _dbg.inject() to read and parse the output of the gdb commands
@ericdatakelly ericdatakelly added this to the April 2021 milestone Apr 30, 2021
@ericdatakelly ericdatakelly modified the milestones: April 2021, May 2021 May 10, 2021
@ericdatakelly ericdatakelly modified the milestones: May 2021, June 2021 Jun 7, 2021
@ericdatakelly ericdatakelly modified the milestones: June 2021, July 2021 Jul 8, 2021
@ericdatakelly ericdatakelly modified the milestones: July 2021, August 2021 Aug 12, 2021
@ericdatakelly ericdatakelly modified the milestones: August 2021, September 2021 Sep 29, 2021
@magsol magsol modified the milestones: February 2022, March 2022 Mar 23, 2022
@umairanis03
Copy link
Contributor

Is this issue tracking debugger attachment hanging?

Reproducer

from pyflyby import debugger

def test():
    x = 1
    y = '123'
    debugger(wait_for_attach=True)
    return x + y

test()

Attaching a debugger hangs:

$ ssh -t <hostname> /usr/local/python/python-3.10/std/bin/py -d 4157723

Entering debugger.  Use 'n' to step, 'c' to continue running, 'q' to quit Python completely.

<HANGS>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants