Skip to content

Commit

Permalink
Move RTT init after breakpoint setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlamb-gh committed Sep 17, 2024
1 parent 38f78ca commit 466f240
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trace-recorder-rtt-proxy"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
authors = ["Jon Lamb <jon@auxon.io>"]
description = "Proxy debug-probe operations and trace recorder RTT data over the network"
Expand Down
82 changes: 43 additions & 39 deletions src/rtt_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,36 +180,6 @@ fn rtt_session_thread(cfg: Config) -> Result<(), Error> {
core.set_hw_breakpoint(bp_addr)?;
}

let rtt = if let Some(to) = rtt_cfg.attach_timeout_ms {
attach_retry_loop(
&mut core,
&rtt_scan_region,
&interruptor,
Duration::from_millis(to.into()),
)?
} else {
debug!("Attaching to RTT");
Rtt::attach_region(&mut core, &rtt_scan_region)?
};
debug!(
addr = format_args!("0x{:X}", rtt.ptr()),
"Found RTT control block"
);

let up_channel = rtt
.up_channel(rtt_cfg.up_channel as _)
.ok_or(Error::UpChannelInvalid(rtt_cfg.up_channel as _))?;
let up_channel_mode = up_channel.mode(&mut core)?;
debug!(channel = up_channel.number(), mode = ?up_channel_mode, buffer_size = up_channel.buffer_size(), "Opened up channel");
let down_channel = rtt
.down_channel(rtt_cfg.down_channel as _)
.ok_or(Error::DownChannelInvalid(rtt_cfg.down_channel as _))?;
debug!(
channel = down_channel.number(),
buffer_size = down_channel.buffer_size(),
"Opened down channel"
);

// Start the core if it's halted
if target_cfg.reset || !matches!(core_status, CoreStatus::Running) {
let sp_reg = core.stack_pointer();
Expand All @@ -220,26 +190,26 @@ fn rtt_session_thread(cfg: Config) -> Result<(), Error> {
core.run()?;
}

// We've done the initial setup, release the lock and switch over to on-demand sessions
std::mem::drop(core);
std::mem::drop(session);

if rtt_cfg.setup_on_breakpoint_address.is_some() {
debug!("Waiting for breakpoint");
'bp_loop: loop {
if interruptor.is_set() {
break;
}

let core_status = session_op(&session_mutex, |session| {
let mut core = session.core(target_cfg.core as _)?;
Ok(core.status()?)
})?;
let core_status = core.status()?;

match core_status {
CoreStatus::Running => (),
CoreStatus::Halted(halt_reason) => match halt_reason {
HaltReason::Breakpoint(_) => break 'bp_loop,
HaltReason::Breakpoint(_) => {
let sp_reg = core.stack_pointer();
let sp: RegisterValue = core.read_core_reg(sp_reg.id())?;
let pc_reg = core.program_counter();
let pc: RegisterValue = core.read_core_reg(pc_reg.id())?;
debug!(pc = %pc, sp = %sp, "Breakpoint hit");
break 'bp_loop;
}
_ => {
warn!(reason = ?halt_reason, "Unexpected halt reason");
break 'bp_loop;
Expand All @@ -257,6 +227,40 @@ fn rtt_session_thread(cfg: Config) -> Result<(), Error> {
// The core is run below
}

let rtt = if let Some(to) = rtt_cfg.attach_timeout_ms {
attach_retry_loop(
&mut core,
&rtt_scan_region,
&interruptor,
Duration::from_millis(to.into()),
)?
} else {
debug!("Attaching to RTT");
Rtt::attach_region(&mut core, &rtt_scan_region)?
};
debug!(
addr = format_args!("0x{:X}", rtt.ptr()),
"Found RTT control block"
);

let up_channel = rtt
.up_channel(rtt_cfg.up_channel as _)
.ok_or(Error::UpChannelInvalid(rtt_cfg.up_channel as _))?;
let up_channel_mode = up_channel.mode(&mut core)?;
debug!(channel = up_channel.number(), mode = ?up_channel_mode, buffer_size = up_channel.buffer_size(), "Opened up channel");
let down_channel = rtt
.down_channel(rtt_cfg.down_channel as _)
.ok_or(Error::DownChannelInvalid(rtt_cfg.down_channel as _))?;
debug!(
channel = down_channel.number(),
buffer_size = down_channel.buffer_size(),
"Opened down channel"
);

// We've done the initial setup, release the lock and switch over to on-demand sessions
std::mem::drop(core);
std::mem::drop(session);

session_op(&session_mutex, |session| {
let mut core = session.core(target_cfg.core as _)?;

Expand Down

0 comments on commit 466f240

Please sign in to comment.