Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge #329
Browse files Browse the repository at this point in the history
329: Update probe-rs to version 0.13.0 r=Urhengulas a=jannic

This patch doesn't implement 64-bit support, but only inserts
conversions from u32 to u64 where necessary.

Co-authored-by: Jan Niehusmann <jan@gondor.com>
  • Loading branch information
bors[bot] and jannic committed Jul 14, 2022
2 parents e9e73a8 + 3763401 commit 88f0afc
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 71 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

- [#329] Update probe-rs to 0.13.0 (does not yet implement 64-bit support)
- [#328] Simplify, by capturing identifiers in logging macros
- [#326] Make use of i/o locking being static since rust `1.61`.
- [#321] CI: Add changelog-enforcer
Expand All @@ -15,6 +16,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- [#314] Clarify documentation in README
- [#293] Update snapshot tests to new TRACE output

[#329]: https://github.com/knurling-rs/probe-run/pull/329
[#328]: https://github.com/knurling-rs/probe-run/pull/328
[#326]: https://github.com/knurling-rs/probe-run/pull/326
[#321]: https://github.com/knurling-rs/probe-run/pull/321
Expand Down
79 changes: 44 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ gimli = { version = "0.26", default-features = false }
git-version = "0.3"
log = "0.4"
object = { version = "0.27", default-features = false }
probe-rs = "0.12"
probe-rs-rtt = "0.12"
probe-rs = "0.13"
probe-rs-rtt = "0.13"
signal-hook = "0.3"
structopt = "0.3"

Expand Down
7 changes: 5 additions & 2 deletions src/backtrace/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ pub(crate) fn target(core: &mut Core, elf: &Elf, active_ram_region: &Option<RamR
let sp = unwrap_or_return_output!(registers.get(registers::SP));
let ram_bounds = active_ram_region
.as_ref()
.map(|ram_region| ram_region.range.clone())
.map(|ram_region| {
ram_region.range.start.try_into().unwrap_or(u32::MAX)
..ram_region.range.end.try_into().unwrap_or(u32::MAX)
})
.unwrap_or(cortexm::VALID_RAM_ADDRESS);
let stacked = if let Some(stacked) =
unwrap_or_return_output!(Stacked::read(registers.core, sp, fpu, ram_bounds))
Expand Down Expand Up @@ -195,7 +198,7 @@ fn overflowed_stack(sp: u32, active_ram_region: &Option<RamRegion>) -> bool {
// NOTE stack is full descending; meaning the stack pointer can be
// `ORIGIN(RAM) + LENGTH(RAM)`
let range = active_ram_region.range.start..=active_ram_region.range.end;
!range.contains(&sp)
!range.contains(&sp.into())
} else {
log::warn!("no RAM region appears to contain the stack; probe-run can't determine if this was a stack overflow");
false
Expand Down
13 changes: 8 additions & 5 deletions src/canary.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Instant;

use probe_rs::{Core, MemoryInterface, Session};
use probe_rs::{Core, MemoryInterface, RegisterValue, Session};

use crate::{registers::PC, Elf, TargetInfo, TIMEOUT};

Expand Down Expand Up @@ -116,7 +116,7 @@ impl Canary {
}
let mut canary = vec![0; self.size];
let start = Instant::now();
core.read_8(self.address, &mut canary)?;
core.read_8(self.address.into(), &mut canary)?;
let seconds = start.elapsed().as_secs_f64();
log::trace!(
"reading canary took {seconds:.3}s ({:.2} KiB/s)",
Expand Down Expand Up @@ -195,18 +195,21 @@ fn paint_stack(core: &mut Core, start: u32, end: u32) -> Result<(), probe_rs::Er

// write subroutine to RAM
// NOTE: add `SUBROUTINE_LENGTH` to `start`, to avoid the subroutine overwriting itself
core.write_8(start, &subroutine(start + SUBROUTINE_LENGTH as u32, end))?;
core.write_8(
start.into(),
&subroutine(start + SUBROUTINE_LENGTH as u32, end),
)?;

// store current PC and set PC to beginning of subroutine
let previous_pc = core.read_core_reg(PC)?;
let previous_pc: RegisterValue = core.read_core_reg(PC)?;
core.write_core_reg(PC, start)?;

// execute the subroutine and wait for it to finish
core.run()?;
core.wait_for_core_halted(TIMEOUT)?;

// overwrite subroutine
core.write_8(start, &[CANARY_VALUE; SUBROUTINE_LENGTH])?;
core.write_8(start.into(), &[CANARY_VALUE; SUBROUTINE_LENGTH])?;

// reset PC to where it was before
core.write_core_reg(PC, previous_pc)?;
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use probe_rs::{
flashing::{self, Format},
Core,
DebugProbeError::ProbeSpecific,
MemoryInterface as _, Session,
MemoryInterface as _, Permissions, Session,
};
use probe_rs_rtt::{Rtt, ScanRegion, UpChannel};
use signal_hook::consts::signal;
Expand Down Expand Up @@ -63,9 +63,9 @@ fn run_target_program(elf_path: &Path, chip_name: &str, opts: &cli::Opts) -> any

let probe_target = target_info.probe_target.clone();
let mut sess = if opts.connect_under_reset {
probe.attach_under_reset(probe_target)?
probe.attach_under_reset(probe_target, Permissions::default())?
} else {
let probe_attach = probe.attach(probe_target);
let probe_attach = probe.attach(probe_target, Permissions::default());
if let Err(probe_rs::Error::Probe(ProbeSpecific(e))) = &probe_attach {
// FIXME Using `to_string().contains(...)` is a workaround as the concrete type
// of `e` is not public and therefore does not allow downcasting.
Expand Down Expand Up @@ -187,7 +187,7 @@ fn start_program(sess: &mut Session, elf: &Elf) -> anyhow::Result<()> {
let mut core = sess.core(0)?;

log::debug!("starting device");
if core.get_available_breakpoint_units()? == 0 {
if core.available_breakpoint_units()? == 0 {
if elf.rtt_buffer_address().is_some() {
bail!("RTT not supported on device without HW breakpoints");
} else {
Expand All @@ -199,7 +199,7 @@ fn start_program(sess: &mut Session, elf: &Elf) -> anyhow::Result<()> {
set_rtt_to_blocking(&mut core, elf.main_fn_address(), rtt_buffer_address)?
}

core.set_hw_breakpoint(cortexm::clear_thumb_bit(elf.vector_table.hard_fault))?;
core.set_hw_breakpoint(cortexm::clear_thumb_bit(elf.vector_table.hard_fault).into())?;
core.run()?;

Ok(())
Expand All @@ -212,7 +212,7 @@ fn set_rtt_to_blocking(
rtt_buffer_address: u32,
) -> anyhow::Result<()> {
// set and wait for a hardware breakpoint at the beginning of `fn main()`
core.set_hw_breakpoint(main_fn_address)?;
core.set_hw_breakpoint(main_fn_address.into())?;
core.run()?;
core.wait_for_core_halted(Duration::from_secs(5))?;

Expand All @@ -222,16 +222,16 @@ fn set_rtt_to_blocking(

// read flags
let channel_flags = &mut [0];
core.read_32(rtt_buffer_address, channel_flags)?;
core.read_32(rtt_buffer_address.into(), channel_flags)?;
// modify flags to blocking
const MODE_MASK: u32 = 0b11;
const MODE_BLOCK_IF_FULL: u32 = 0b10;
let modified_channel_flags = (channel_flags[0] & !MODE_MASK) | MODE_BLOCK_IF_FULL;
// write flags back
core.write_word_32(rtt_buffer_address, modified_channel_flags)?;
core.write_word_32(rtt_buffer_address.into(), modified_channel_flags)?;

// clear the breakpoint we set before
core.clear_hw_breakpoint(main_fn_address)?;
core.clear_hw_breakpoint(main_fn_address.into())?;

Ok(())
}
Expand Down
Loading

0 comments on commit 88f0afc

Please sign in to comment.