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

Update arguments layout in debugpy/VSCode debugger port detection #2623

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+debugger-detection.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added new VSCode debugpy args layout to debugger port detection
24 changes: 17 additions & 7 deletions mirrord/layer/src/debugger_ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...`
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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(
Expand Down
Loading