Skip to content

Commit

Permalink
Cli quick fix (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Blinningjr authored Oct 16, 2022
1 parent ba2fba6 commit a424f28
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
53 changes: 50 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <port>`.

## 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
Expand Down
6 changes: 3 additions & 3 deletions src/cli/cli_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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)))
Expand Down
11 changes: 11 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +16,11 @@ use probe_rs::CoreStatus;

pub async fn handle_input(stdin: &io::Stdin) -> Result<DebugRequest> {
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)? {
Expand All @@ -26,6 +32,11 @@ pub async fn handle_input(stdin: &io::Stdin) -> Result<DebugRequest> {

pub async fn simple_handle_input(stdin: &io::Stdin) -> Result<bool> {
// 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)
Expand Down
8 changes: 4 additions & 4 deletions src/debugger/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

pub struct Config {
pub elf_file_path: Option<PathBuf>,
pub binary_file_path: Option<PathBuf>,
pub chip: Option<String>,
pub work_directory: Option<String>,
pub probe_num: usize,
Expand All @@ -10,15 +10,15 @@ 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,
}
}

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 {
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/debugger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<R: Reader<Offset = usize>> NewDebugHandler<R> {
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 } => {
Expand All @@ -73,7 +73,7 @@ impl<R: Reader<Offset = usize>> NewDebugHandler<R> {
}
} 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!();
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
/// Absolute file path to binary/Elf file.
#[structopt(short = "bin", long = "binary-file-path")]
binary_file_path: Option<PathBuf>,

/// Current working directory
/// Current work directory absolute file path
#[structopt(short = "wd", long = "work-directory")]
work_directory: Option<String>,

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a424f28

Please sign in to comment.