From a424f289598abab8452318f17cfb0447db9432fe Mon Sep 17 00:00:00 2001 From: Niklas <26083646+Blinningjr@users.noreply.github.com> Date: Sun, 16 Oct 2022 10:20:58 +0200 Subject: [PATCH] Cli quick fix (#14) * Add `erdb>` pritn in front of input * Add startup message * Update CLI command help text * Add a useing section to README * Add server mode subsection in README --- Cargo.toml | 2 +- README.md | 53 ++++++++++++++++++++++++++++++++++++++--- src/cli/cli_commands.rs | 6 ++--- src/cli/mod.rs | 11 +++++++++ src/debugger/config.rs | 8 +++---- src/debugger/mod.rs | 4 ++-- src/main.rs | 9 +++---- 7 files changed, 76 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b8869c..4cc2df8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "erdb" -version = "0.2.0" +version = "0.2.1" authors = ["Niklas Lundberg"] license = "MIT OR Apache-2.0" edition = "2021" diff --git a/README.md b/README.md index 0f0e88b..a63f6a4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Embedded Rust Debugger (ERDB) +# Embedded Rust Debugger (erdb) A debugger for rust on embedded systems. -ERDB currently only work on Linux. +Erdb currently only work on Linux. It is only tested on a `STM32F411RETx` dev board. ## Features @@ -19,9 +19,56 @@ It is only tested on a `STM32F411RETx` dev board. cargo install --path . ``` +## Run + +Erdb has the two following modes: + +* CLI mode - Starts a TUI in the terminal. +* Server mode - Starts a DAP server. + +Erdb will start in CLI mode by default. +More information on the two modes in the subsections bellow. + +### CLI Mode + +Start erdb with the following command: + +```sh +erdb +``` + +Erdb requires the $3$ following configurations: + * `chip` - Type of chip, example `STM32F411RETx`. +* `work-directory` - The absolute path to the root of the project directory. +* `elf-file` - The absolute path to the compiled binary/elf file. + +Which can be set using the `config` command. + + +But, the easiest way to use erdb, is to make a shell script that starts erdb and sets all $3$ configurations. It would look something like this: + +```bash +#!/bin/bash +erdb --chip STM32F411RETx \ +--work-directory /home/niklas/exjobb/nucleo64-rtic-examples \ +--binary-file-path /home/niklas/exjobb/nucleo64-rtic-examples/target/thumbv7em-none-eabi/debug/nucleo-rtic-blinking-led +``` + +### Server Mode + +To start erdb as a DAP server use the following command: + +```sh +erdb -m server +``` + +It is recommended to use flag `-v` for more server logs. + +Erdb use port `8800` by default, however this can be changed with the flag `-p `. + ## Crate rust-debug -ERDB is built using the debug crate [rust-debug](https://github.com/Blinningjr/rust-debug). +Erdb is built using the debug crate [rust-debug](https://github.com/Blinningjr/rust-debug). Therefore, this is a great example of how to use that crate. ## License diff --git a/src/cli/cli_commands.rs b/src/cli/cli_commands.rs index 94b5397..5ae9c09 100644 --- a/src/cli/cli_commands.rs +++ b/src/cli/cli_commands.rs @@ -162,7 +162,7 @@ fn target_commands() -> Command { fn binary_command() -> Command { Command::new(BINARY_SUB_CMD) - .about("Set file path to binary") + .about("Set absolute file path to binary/Elf file") .alias("b") .arg( arg!([file] "Binary file path") @@ -173,7 +173,7 @@ fn binary_command() -> Command { fn chip_command() -> Command { Command::new(CHIP_SUB_CMD) - .about("Set chip model") + .about("Set type of chip") .alias("c") .arg( arg!([chip] "Chip name") @@ -196,7 +196,7 @@ fn probe_command() -> Command { fn work_directory_command() -> Command { Command::new(WORK_DIR_SUB_CMD) - .about("Specify source code work directory") + .about("Set current work directory absolute file path") .alias("wd") .arg_required_else_help(true) .arg(arg!([dir] "Work directory path").value_parser(value_parser!(String))) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index c7e0fea..010c0e3 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,4 +1,5 @@ mod cli_commands; +use async_std::io::WriteExt; use cli_commands::{parse_string_simple_cli, parse_string_to_erdb_request}; use async_std::io; @@ -15,6 +16,11 @@ use probe_rs::CoreStatus; pub async fn handle_input(stdin: &io::Stdin) -> Result { loop { + print!("erdb> "); + match io::stdout().flush().await { + Ok(_) => (), + Err(err) => error!("{}", err), + }; let mut line = "ERDB ".to_owned(); stdin.read_line(&mut line).await?; match parse_string_to_erdb_request(line)? { @@ -26,6 +32,11 @@ pub async fn handle_input(stdin: &io::Stdin) -> Result { pub async fn simple_handle_input(stdin: &io::Stdin) -> Result { // Read next line asynchronously + print!("erdb> "); + match io::stdout().flush().await { + Ok(_) => (), + Err(err) => error!("{}", err), + }; let mut line = "ERDB ".to_owned(); stdin.read_line(&mut line).await?; parse_string_simple_cli(line) diff --git a/src/debugger/config.rs b/src/debugger/config.rs index 779f316..3986f55 100644 --- a/src/debugger/config.rs +++ b/src/debugger/config.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; pub struct Config { - pub elf_file_path: Option, + pub binary_file_path: Option, pub chip: Option, pub work_directory: Option, pub probe_num: usize, @@ -10,7 +10,7 @@ pub struct Config { impl Config { pub fn new(opt: super::Opt) -> Config { Config { - elf_file_path: opt.elf_file_path, + binary_file_path: opt.binary_file_path, chip: opt.chip, work_directory: opt.work_directory, probe_num: 0, @@ -18,7 +18,7 @@ impl Config { } pub fn is_missing_config(&self) -> bool { - self.elf_file_path.is_none() || self.chip.is_none() || self.work_directory.is_none() + self.binary_file_path.is_none() || self.chip.is_none() || self.work_directory.is_none() } pub fn missing_config_message(&self) -> String { @@ -27,7 +27,7 @@ impl Config { } let mut error = "Missing required configurations:".to_owned(); - if self.elf_file_path.is_none() { + if self.binary_file_path.is_none() { error = format!("{}\n\t{}", error, "elf file path"); } if self.chip.is_none() { diff --git a/src/debugger/mod.rs b/src/debugger/mod.rs index 7fa89c1..3dd39db 100644 --- a/src/debugger/mod.rs +++ b/src/debugger/mod.rs @@ -49,7 +49,7 @@ impl> NewDebugHandler { Ok(match request { DebugRequest::Exit => DebugResponse::Exit, DebugRequest::SetBinary { path } => { - self.config.elf_file_path = Some(path); + self.config.binary_file_path = Some(path); DebugResponse::SetBinary } DebugRequest::SetProbeNumber { number } => { @@ -73,7 +73,7 @@ impl> NewDebugHandler { } } else { self.session = Some(DebugSession::new( - match self.config.elf_file_path.clone() { + match self.config.binary_file_path.clone() { Some(val) => val, None => { unreachable!(); diff --git a/src/main.rs b/src/main.rs index 3749ca5..7a98f0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,11 +71,11 @@ pub struct Opt { #[structopt(short = "v", long = "verbosity", default_value = "Off")] verbosity: LevelFilter, - /// Elf file path - #[structopt(short = "elf", long = "elf-file")] - elf_file_path: Option, + /// Absolute file path to binary/Elf file. + #[structopt(short = "bin", long = "binary-file-path")] + binary_file_path: Option, - /// Current working directory + /// Current work directory absolute file path #[structopt(short = "wd", long = "work-directory")] work_directory: Option, @@ -127,6 +127,7 @@ async fn async_main() -> Result<()> { .filter_module("probe_rs", probe_rs_log_level) .init(); + println!("Erdb is running, type \"help\" for information on commands"); match opt.mode { Mode::Debug => cli_mode(opt).await, Mode::DebugAdapter => server_mode(opt).await,