Repository navigation
Fix subprocess patching for scripts run through a python shebang - #2106
TEJA P C (PCTEJA) wants to merge 6 commits into
Conversation
patch_args returned the arguments unchanged when the executable was a script whose first line is a shebang pointing at a python interpreter, so such subprocesses were never attached to the debugger. When the executable name is not a known python name, parse the file's shebang (the direct form, the /usr/bin/env form and the env -S form) and rewrite the args to run the script through that interpreter before the existing patching runs. The process creation hooks also replace the executable with the interpreter in that case, since they launch the executable separately from the args (for fork_exec, the executable list passed to it is replaced instead).
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Rich Chiodo (@rchiodo) opened this following your reply on #1929. The fix is isolated to the patching code, as discussed. Could you please review when you are free? |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Launch env shebang scripts through the env program instead of resolving the interpreter, reuse os.get_exec_path for child environment PATH handling, patch based on the executable actually selected for a launch when it differs from args[0], share one fork_exec patching helper between both hooks, and select the first viable entry of the fork_exec executable list.
|
Rich Chiodo (@rchiodo), I made a little correction to the changes you requested on 1, 4 & 5. pls review it when your free. |
|
Rich Chiodo (@rchiodo) wil drop the viability probing and make the shebang parsing follow the kernels bytelevel rules. |
|
Rich Chiodo (@rchiodo) could u pls review again? |
|
Sorry there's another problem I just realized. None of these tests actually run in the debugpy CI. You added tests for pydevd that only run in pydevd (we should probably change that in our CI, but I wouldn't recommend it here). Can you move/modify the tests to run for debugpy? |
|
Rich Chiodo (@rchiodo) sry for assuming but the existing pydev_monkey tests all live there, so I put mine there too. |
|
Yeah pydevd_monkey code would be tested by subprocess tests in debugpy. That's the sort of tests you'd need to write. |
|
Rich Chiodo (@rchiodo) moved it pls check now. |
Fixes #1929
Script subprocesses launched through a python shebang were not being debugged:
patch_argsreturned the arguments unchanged when the executable was a script rather than a known python name, so pydevd was never inserted.This change parses the shebang when the executable name is not a known python name, covering the direct form, the
/usr/bin/envform and theenv -Sform, and rewrites the args to run the script through that interpreter before the existing patching runs. The process creation hooks also replace the executable with the interpreter in that case, since they launch the executable separately from the args (forfork_exec, the executable list passed to it is replaced instead).This follows the narrower approach discussed on #1929 and stays isolated to the patching code in
pydev_monkey.py.Tests: 20 new regression tests in
test_pydev_monkey.py. The relevant test set passes twice with the same result (61 passed), and the new tests fail on the unmodified base.