Skip to content

Commit

Permalink
Merge #1072
Browse files Browse the repository at this point in the history
1072: Debugger: Add SVD Peripherals and prep for multi-core r=Yatekii a=noppej

This PR is part of a trio of PR's that depend on each other:
- [Debugger in probe-rs](#1072)
  - Part I of preparing for multi-core support. This will require future PR's to complete.
  - Restructured source files - large files broken up into smaller units.
  - Support for loading CMSIS-SVD files and making peripheral values available to the VSCode extension.
- [VSCode extension](probe-rs/vscode#31)
  -  A draft version of the extension [probe-rs-debugger-0.4.0.vsix](https://github.com/probe-rs/vscode/releases/tag/v0.4.0) is available to facilitate testing of these PR's.
  -  Changes to `launch.json` configuration to support SVD Peripheral files and core specific configuration.
  - Updated various development dependencies.
  - Updated the Debug Adapter Protocol to version 1.55.1.
- [Documentation on probe.rs](probe-rs/webpage#47)
  -  Document changes to VSCode `launch.json`.
  - GIF to demonstrate how to navigate and monitor SVD Peripheral register values.

Note to reviewers: This PR started as simply adding SVD support. Then I realized it doesn't make sense to add all that functionality while disregarding that this is a core-specific capability. As a result I started adding essential logic to configure and handle core-specific settings. Then I realized that the source files were growing out of proportion, so I split them into smaller units. The result is this rather larger PR - I hope the new capability and cleaner source structure makes up for the pain of reviewing such a large PR.

Co-authored-by: JackN <noppej@hotmail.com>
  • Loading branch information
bors[bot] and noppej committed Apr 18, 2022
2 parents ae318f0 + 124529e commit 01e5c4e
Show file tree
Hide file tree
Showing 30 changed files with 1,929 additions and 1,182 deletions.
21 changes: 21 additions & 0 deletions .vscode/launch.json
Expand Up @@ -100,6 +100,27 @@
"help",
],
"cwd": "${workspaceFolder}/debugger"
},
{
"type": "lldb",
"request": "launch",
"name": "display debug subcommand help text",
"cargo": {
"args": [
"build",
"--bin=probe-rs-debugger",
"--package=probe-rs-debugger"
],
"filter": {
"name": "probe-rs-debugger",
"kind": "bin"
}
},
"args": [
"help",
"debug",
],
"cwd": "${workspaceFolder}/debugger"
}
]
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Debugger: Add support for DAP Requests (ReadMemory, WriteMemory, Evaluate & SetVariable) (#1035)
- Debugger: Add support for DAP Requests (Disassemble & SetInstructionBreakpoints) (#1049)
- Debugger: Add support for stepping at 'statement' level, plus 'step in', 'step out' (#1056)
- Debugger: Add support for navigating and monitoring SVD Peripheral Registers. (#1072)
- Added GD32F3x0 series support (#1079)

### Changed
Expand All @@ -44,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated STM32H7 series yaml to support newly released chips. (#1011)
- Debugger: Removed the CLI mode, in favour of `probe-rs-cli` which has richer functionality. (#1041)
- Renamed `Probe::speed` to `Probe::speed_khz`.
- Debugger: Changes to DAP Client `launch.json` to prepare for WIP multi-core support. (#1072)
- `ram_download` example now uses clap syntax.

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion cli/src/debugger.rs
Expand Up @@ -392,7 +392,7 @@ impl DebugCli {
println!(
"{}: {} = {}",
child.name,
child.type_name.display(),
child.type_name,
child.get_value(local_variable_cache)
);
}
Expand Down
2 changes: 2 additions & 0 deletions debugger/Cargo.toml
Expand Up @@ -39,6 +39,8 @@ schemafy = "^0.6"
chrono = { version = "0.4", features = ["serde"] }
goblin = "0.5.1"
base64 = "0.13"
svd-parser = "0.13.1"
svd-rs = { version = "0.13.1", features = ["derive-from"] }

[dev-dependencies]
insta = "1.8.0"

Large diffs are not rendered by default.

Expand Up @@ -7,7 +7,8 @@ use schemafy::schemafy;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

schemafy!(root: debugserver_types "src/debugProtocol.json");
// Convert the MSDAP `debugAdaptor.json` file, renamed here as `schema.json` into Rust types.
schemafy!(root: debugserver_types "src/debug_adapter/schema.json");

/// Custom 'quit' request, so that VSCode can tell the `probe-rs-debugger` to terminate its own process.
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
Expand Down
6 changes: 6 additions & 0 deletions debugger/src/debug_adapter/mod.rs
@@ -0,0 +1,6 @@
/// Implements the logic for each of the MS DAP types (events, requests, etc.)
pub(crate) mod dap_adapter;
/// The MS DAP api, and extensions, for communicating with the MS DAP client.
pub(crate) mod dap_types;
/// Communication interfaces to connect the DAP client and probe-rs-debugger.
pub(crate) mod protocol;
24 changes: 12 additions & 12 deletions debugger/src/protocol.rs → debugger/src/debug_adapter/protocol.rs
@@ -1,20 +1,20 @@
use crate::debugger::ConsoleLog;
use crate::DebuggerError;
use crate::{
debug_adapter::dap_types::{
Event, MessageSeverity, OutputEventBody, ProtocolMessage, Request, Response,
ShowMessageEventBody,
},
debugger::configuration::ConsoleLog,
DebuggerError,
};
use anyhow::anyhow;
use serde::Serialize;
use std::collections::HashMap;
use std::string::ToString;
use std::{
collections::HashMap,
io::{BufRead, BufReader, Read, Write},
str,
string::ToString,
};

use crate::dap_types::{
Event, MessageSeverity, OutputEventBody, ProtocolMessage, Request, Response,
ShowMessageEventBody,
};

use anyhow::anyhow;

pub trait ProtocolAdapter {
/// Listen for a request. This call should be non-blocking, and if not request is available, it should
/// return None.
Expand Down Expand Up @@ -404,7 +404,7 @@ fn get_content_len(header: &str) -> Option<usize> {
mod test {
use std::io::{self, ErrorKind, Read};

use crate::protocol::{get_content_len, ProtocolAdapter};
use crate::debug_adapter::protocol::{get_content_len, ProtocolAdapter};

use super::DapAdapter;

Expand Down
Expand Up @@ -1035,7 +1035,7 @@
"DisconnectRequest": {
"allOf": [ { "$ref": "#/definitions/Request" }, {
"type": "object",
"description": "The 'disconnect' request is sent from the client to the debug adapter in order to stop debugging.\nIt asks the debug adapter to disconnect from the debuggee and to terminate the debug adapter.\nIf the debuggee has been started with the 'launch' request, the 'disconnect' request terminates the debuggee.\nIf the 'attach' request was used to connect to the debuggee, 'disconnect' does not terminate the debuggee.\nThis behavior can be controlled with the 'terminateDebuggee' argument (if supported by the debug adapter).",
"description": "The 'disconnect' request asks the debug adapter to disconnect from the debuggee (thus ending the debug session) and then to shut down itself (the debug adapter).\nIn addition, the debug adapter must terminate the debuggee if it was started with the 'launch' request. If an 'attach' request was used to connect to the debuggee, then the debug adapter must not terminate the debuggee.\nThis implicit behavior of when to terminate the debuggee can be overridden with the optional argument 'terminateDebuggee' (which is only supported by a debug adapter if the corresponding capability 'supportTerminateDebuggee' is true).",
"properties": {
"command": {
"type": "string",
Expand Down Expand Up @@ -1076,7 +1076,7 @@
"TerminateRequest": {
"allOf": [ { "$ref": "#/definitions/Request" }, {
"type": "object",
"description": "The 'terminate' request is sent from the client to the debug adapter in order to give the debuggee a chance for terminating itself.\nClients should only call this request if the capability 'supportsTerminateRequest' is true.",
"description": "The 'terminate' request is sent from the client to the debug adapter in order to shut down the debuggee gracefully. Clients should only call this request if the capability 'supportsTerminateRequest' is true.\nTypically a debug adapter implements 'terminate' by sending a software signal which the debuggee intercepts in order to clean things up properly before terminating itself.\nPlease note that this request does not directly affect the state of the debug session: if the debuggee decides to veto the graceful shutdown for any reason by not terminating itself, then the debug session will just continue.\nClients can surface the 'terminate' request as an explicit command or they can integrate it into a two stage Stop command that first sends 'terminate' to request a graceful shutdown, and if that fails uses 'disconnect' for a forceful shutdown.",
"properties": {
"command": {
"type": "string",
Expand Down Expand Up @@ -1195,7 +1195,7 @@
"properties": {
"source": {
"$ref": "#/definitions/Source",
"description": "The source location of the breakpoints; either 'source.path' or 'source.reference' must be specified."
"description": "The source location of the breakpoints; either 'source.path' or 'source.sourceReference' must be specified."
},
"breakpoints": {
"type": "array",
Expand Down Expand Up @@ -2417,18 +2417,19 @@
},
"context": {
"type": "string",
"_enum": [ "watch", "repl", "hover", "clipboard" ],
"_enum": [ "variables", "watch", "repl", "hover", "clipboard" ],
"enumDescriptions": [
"evaluate is run in a watch.",
"evaluate is run from REPL console.",
"evaluate is run from a data hover.",
"evaluate is run to generate the value that will be stored in the clipboard.\nThe attribute is only honored by a debug adapter if the capability 'supportsClipboardContext' is true."
"evaluate is called from a variables view context.",
"evaluate is called from a watch view context.",
"evaluate is called from a REPL context.",
"evaluate is called to generate the debug hover contents.\nThis value should only be used if the capability 'supportsEvaluateForHovers' is true.",
"evaluate is called to generate clipboard contents.\nThis value should only be used if the capability 'supportsClipboardContext' is true."
],
"description": "The context in which the evaluate request is run."
"description": "The context in which the evaluate request is used."
},
"format": {
"$ref": "#/definitions/ValueFormat",
"description": "Specifies details on how to format the Evaluate result.\nThe attribute is only honored by a debug adapter if the capability 'supportsValueFormattingOptions' is true."
"description": "Specifies details on how to format the result.\nThe attribute is only honored by a debug adapter if the capability 'supportsValueFormattingOptions' is true."
}
},
"required": [ "expression" ]
Expand Down Expand Up @@ -3940,7 +3941,7 @@

"ExceptionFilterOptions": {
"type": "object",
"description": "An ExceptionFilterOptions is used to specify an exception filter together with a condition for the setExceptionsFilter request.",
"description": "An ExceptionFilterOptions is used to specify an exception filter together with a condition for the 'setExceptionBreakpoints' request.",
"properties": {
"filterId": {
"type": "string",
Expand Down
@@ -1,7 +1,6 @@
---
source: debugger/src/protocol.rs
source: debugger/src/debug_adapter/protocol.rs
expression: output_str

---
Content-Length: 156

Expand Down
@@ -1,7 +1,6 @@
---
source: debugger/src/protocol.rs
source: debugger/src/debug_adapter/protocol.rs
expression: output_str

---
Content-Length: 165

Expand Down
@@ -0,0 +1,5 @@
---
source: debugger/src/debug_adapter/protocol.rs
expression: output_str
---

@@ -1,7 +1,6 @@
---
source: debugger/src/debug_adapter.rs
source: debugger/src/debug_adapter/protocol.rs
expression: output_str

---
Content-Length: 151

Expand Down

0 comments on commit 01e5c4e

Please sign in to comment.