Repository navigation
Fix subprocess patching for scripts run through a python shebang - #2106
TEJA P C (PCTEJA) wants to merge 4 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. |
| return None | ||
| first_line = first_line.strip() | ||
|
|
||
| line = first_line[2:].decode("utf-8", "ignore").strip() |
There was a problem hiding this comment.
This decoding and split() can normalize malformed shebangs into valid Python launches. I verified that both #!/usr/bin/python3\xff and a vertical-tab-separated shebang fail natively on Linux, but are parsed and rewritten here. Could parsing follow the kernel's byte-level separator rules and reject bytes/whitespace it would not accept, with regression tests for those cases?
|
Rich Chiodo (@rchiodo) wil drop the viability probing and make the shebang parsing follow the kernels bytelevel rules. |
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.