diff --git a/changelog.d/+debugger-detection.fixed.md b/changelog.d/+debugger-detection.fixed.md new file mode 100644 index 00000000000..28e1a579d0c --- /dev/null +++ b/changelog.d/+debugger-detection.fixed.md @@ -0,0 +1 @@ +Added new VSCode debugpy args layout to debugger port detection \ No newline at end of file diff --git a/mirrord/layer/src/debugger_ports.rs b/mirrord/layer/src/debugger_ports.rs index 668bc2f1a60..2b2feb0aed6 100644 --- a/mirrord/layer/src/debugger_ports.rs +++ b/mirrord/layer/src/debugger_ports.rs @@ -32,9 +32,14 @@ pub enum DebuggerType { /// An implementation of the [Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/) for Python 3. /// Used in VS Code. /// - /// Command used to invoke this debugger looked like - /// `/path/to/python /path/to/vscode/extensions/debugpy --connect 127.0.0.1:57141 - /// --configure-qt none --adapter-access-token + /// Command used to invoke this debugger looked like either: + /// `/path/to/python -X frozen_modules=off /path/to/vscode/extensions/debugpy --connect + /// 127.0.0.1:57141 --configure-qt none --adapter-access-token + /// c2d745556a5a571d09dbf9c14af2898b3d6c174597d6b7198d9d30c105d5ab24 /path/to/script.py` + /// + /// or in older versions: + /// `/path/to/python /path/to/vscode/extensions/debugpy --connect + /// 127.0.0.1:57141 --configure-qt none --adapter-access-token /// c2d745556a5a571d09dbf9c14af2898b3d6c174597d6b7198d9d30c105d5ab24 /path/to/script.py` /// /// Port would not be extracted from a command like `/path/to/python /path/to/script.py ...` @@ -97,7 +102,11 @@ impl DebuggerType { match self { Self::DebugPy => { let is_python = args.first()?.rsplit('/').next()?.starts_with("py"); - let runs_debugpy = args.get(1)?.ends_with("debugpy"); + let runs_debugpy = if args.get(1)?.starts_with("-X") { + args.get(3)?.ends_with("debugpy") // newer args layout + } else { + args.get(1)?.ends_with("debugpy") // older args layout + }; if !is_python || !runs_debugpy { None? @@ -259,10 +268,11 @@ mod test { use rstest::rstest; use super::*; - #[test] - fn detect_debugpy_port() { + #[rstest] + #[case("/home/user/path/to/venv/bin/python /home/user/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy --connect 127.0.0.1:57141 --configure-qt none --adapter-access-token c2d745556a5a571d09dbf9c14af2898b3d6c174597d6b7198d9d30c105d5ab24 /home/user/path/to/script.py")] + #[case("/home/user/path/to/venv/bin/python -X frozen_modules=off /home/user/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy --connect 127.0.0.1:57141 --configure-qt none --adapter-access-token c2d745556a5a571d09dbf9c14af2898b3d6c174597d6b7198d9d30c105d5ab24 /home/user/path/to/script.py")] + fn detect_debugpy_port(#[case] command: &str) { let debugger = DebuggerType::DebugPy; - let command = "/home/user/path/to/venv/bin/python /home/user/.vscode/extensions/ms-python.python-2023.6.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy --connect 127.0.0.1:57141 --configure-qt none --adapter-access-token c2d745556a5a571d09dbf9c14af2898b3d6c174597d6b7198d9d30c105d5ab24 /home/user/path/to/script.py"; assert_eq!( debugger.get_port(