Skip to content

Commit

Permalink
WIP: add lldb launch configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrw committed Jan 26, 2025
1 parent 001a39f commit 13ba3e6
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 7 deletions.
12 changes: 12 additions & 0 deletions debugger/src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ impl From<LaunchConfiguration> for InitialiseArguments {
}),
other => todo!("{other}"),
},
LaunchConfiguration::LLDB(lldb) => match lldb.request.as_str() {
"launch" =>
{
#[allow(unreachable_code)]
InitialiseArguments::Launch(LaunchArguments {
working_directory: None,
language: crate::Language::DebugPy,
program: todo!(),
})
}
other => todo!("{other}"),
},
}
}
}
Expand Down
1 change: 1 addition & 0 deletions gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ impl DebuggerApp {
};
debugger
}
other => todo!("{other:?}"),
};

let events = debugger.events();
Expand Down
1 change: 1 addition & 0 deletions gui2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl DebuggerApp {
};
debugger
}
other => todo!("{other:?}"),
};

debugger.wait_for_event(|e| matches!(e, debugger::Event::Initialised));
Expand Down
24 changes: 24 additions & 0 deletions launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@
"remoteRoot": "/opt/code/localstack/localstack"
}
]
},
{
"name": "repl",
"type": "lldb",
"request": "launch",
"cwd": "${workspaceFolder}",
"cargo": {
"args": [
"build",
"-p",
"repl",
"--bin=repl"
],
"filter": {
"kind": "bin"
}
},
"args": [
"launch.json",
"-n",
"Launch",
"-b",
"test.py:4"
]
}
]
}
45 changes: 43 additions & 2 deletions launch_configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ struct Folder {
}

#[derive(Debug, Deserialize)]
#[serde(untagged)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum LaunchConfiguration {
Debugpy(Debugpy),
LLDB(LLDB),
}

impl LaunchConfiguration {
Expand All @@ -57,6 +58,7 @@ impl LaunchConfiguration {
LaunchConfiguration::Debugpy(debugpy) => {
debugpy.resolve(root);
}
LaunchConfiguration::LLDB(lldb) => lldb.resolve(root),
}
}
}
Expand Down Expand Up @@ -88,13 +90,17 @@ fn from_str(name: Option<&String>, contents: &str) -> eyre::Result<ChosenLaunchC
return Ok(ChosenLaunchConfiguration::Specific(configuration));
}
}
LaunchConfiguration::LLDB(LLDB { .. }) => {
todo!()
}
}
}
} else {
let configuration_names: Vec<_> = configurations
.iter()
.map(|c| match &c {
LaunchConfiguration::Debugpy(Debugpy { name, .. }) => name.clone(),
LaunchConfiguration::LLDB(LLDB { name, .. }) => name.clone(),
})
.collect();
return Ok(ChosenLaunchConfiguration::ToBeChosen(configuration_names));
Expand All @@ -114,13 +120,21 @@ fn from_str(name: Option<&String>, contents: &str) -> eyre::Result<ChosenLaunchC
return Ok(ChosenLaunchConfiguration::Specific(configuration));
}
}
LaunchConfiguration::LLDB(LLDB {
name: config_name, ..
}) => {
if config_name == name {
return Ok(ChosenLaunchConfiguration::Specific(configuration));
}
}
}
}
} else {
let configuration_names: Vec<_> = configurations
.iter()
.map(|c| match &c {
LaunchConfiguration::Debugpy(Debugpy { name, .. }) => name.clone(),
LaunchConfiguration::LLDB(LLDB { name, .. }) => name.clone(),
})
.collect();
return Ok(ChosenLaunchConfiguration::ToBeChosen(configuration_names));
Expand Down Expand Up @@ -155,14 +169,14 @@ pub fn load_from_path(
#[serde(rename_all = "camelCase")]
pub struct Debugpy {
pub name: String,
pub r#type: String,
pub request: String,
pub connect: Option<ConnectionDetails>,
pub program: Option<PathBuf>,
pub path_mappings: Option<Vec<PathMapping>>,
pub just_my_code: Option<bool>,
pub cwd: Option<PathBuf>,
}

impl Debugpy {
fn resolve(&mut self, root: impl AsRef<Path>) {
let root = root.as_ref();
Expand All @@ -174,8 +188,35 @@ impl Debugpy {
}
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LLDB {
pub name: String,
pub request: String,
pub connect: Option<ConnectionDetails>,
pub cargo: CargoConfig,
pub cwd: Option<String>,
}

impl LLDB {
fn resolve(&mut self, _root: impl AsRef<Path>) {}
}

#[derive(Debug, Clone, Deserialize)]
pub struct ConnectionDetails {
pub host: String,
pub port: u16,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CargoConfig {
pub args: Vec<String>,
pub filter: CargoFilter,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CargoFilter {
pub kind: String,
}
2 changes: 1 addition & 1 deletion launch_configuration/testdata/vscode/localstack-ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
Expand Down
1 change: 1 addition & 0 deletions pythondap/src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ impl Debugger {
};
debugger
}
other => todo!("{other:?}"),
};

tracing::trace!("waiting for initialised event");
Expand Down
7 changes: 3 additions & 4 deletions pythondap/src/launch_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pyo3::{exceptions::PyRuntimeError, prelude::*};

use launch_configuration::{load_from_path, ChosenLaunchConfiguration};
use launch_configuration::{load_from_path, ChosenLaunchConfiguration, LaunchConfiguration};

#[pyclass]
pub struct PyChosenLaunchConfiguration {
Expand All @@ -13,9 +13,8 @@ impl From<ChosenLaunchConfiguration> for PyChosenLaunchConfiguration {
match value {
ChosenLaunchConfiguration::Specific(launch_configuration) => match launch_configuration
{
launch_configuration::LaunchConfiguration::Debugpy(debugpy) => {
Self { name: debugpy.name }
}
LaunchConfiguration::Debugpy(debugpy) => Self { name: debugpy.name },
LaunchConfiguration::LLDB(lldb) => Self { name: lldb.name },
},
_ => todo!("unhandled case for chosen launch configuration",),
}
Expand Down

0 comments on commit 13ba3e6

Please sign in to comment.