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

Commit

Permalink
Merge #344
Browse files Browse the repository at this point in the history
344: Replace `pub(crate)` with `pub` r=Urhengulas a=Urhengulas

Since `probe-run` is a binary crate, `pub` has the same effect as `pub(crate)`.

Co-authored-by: Urhengulas <johann.hemmann@code.berlin>
  • Loading branch information
bors[bot] and Urhengulas committed Aug 10, 2022
2 parents 3fd56c3 + f50def2 commit 2fdd24a
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 120 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

- [#xxx] Mark `v0.3.4` as released in `CHANGELOG.md`
- [#344] Replace `pub(crate)` with `pub`
- [#343] Mark `v0.3.4` as released in `CHANGELOG.md`

[#xxx]: https://github.com/knurling-rs/probe-run/pull/xxx
[#344]: https://github.com/knurling-rs/probe-run/pull/344
[#343]: https://github.com/knurling-rs/probe-run/pull/343

## [v0.3.4] - 2022-08-10

Expand Down
22 changes: 11 additions & 11 deletions src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod symbolicate;
mod unwind;

#[derive(PartialEq, Eq)]
pub(crate) enum BacktraceOptions {
pub enum BacktraceOptions {
Auto,
Never,
Always,
Expand All @@ -27,17 +27,17 @@ impl From<&String> for BacktraceOptions {
}
}

pub(crate) struct Settings<'p> {
pub(crate) current_dir: &'p Path,
pub(crate) backtrace: BacktraceOptions,
pub(crate) panic_present: bool,
pub(crate) backtrace_limit: u32,
pub(crate) shorten_paths: bool,
pub(crate) include_addresses: bool,
pub struct Settings<'p> {
pub current_dir: &'p Path,
pub backtrace: BacktraceOptions,
pub panic_present: bool,
pub backtrace_limit: u32,
pub shorten_paths: bool,
pub include_addresses: bool,
}

/// (virtually) unwinds the target's program and prints its backtrace
pub(crate) fn print(
pub fn print(
core: &mut Core,
elf: &Elf,
active_ram_region: &Option<RamRegion>,
Expand Down Expand Up @@ -88,7 +88,7 @@ pub(crate) fn print(

/// Target program outcome
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) enum Outcome {
pub enum Outcome {
HardFault,
Ok,
StackOverflow,
Expand All @@ -97,7 +97,7 @@ pub(crate) enum Outcome {
}

impl Outcome {
pub(crate) fn log(&self) {
pub fn log(&self) {
match self {
Outcome::StackOverflow => log::error!("the program has overflowed its stack"),
Outcome::HardFault => log::error!("the program panicked"),
Expand Down
2 changes: 1 addition & 1 deletion src/backtrace/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::dep;
use super::{symbolicate::Frame, Settings};

/// Pretty prints processed backtrace frames up to `backtrace_limit`
pub(crate) fn backtrace(frames: &[Frame], settings: &Settings) -> io::Result<()> {
pub fn backtrace(frames: &[Frame], settings: &Settings) -> io::Result<()> {
let mut stderr = io::stderr().lock();
writeln!(stderr, "{}", "stack backtrace:".dimmed())?;

Expand Down
22 changes: 11 additions & 11 deletions src/backtrace/symbolicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{cortexm, elf::Elf};

use super::unwind::RawFrame;

pub(crate) fn frames(raw_frames: &[RawFrame], current_dir: &Path, elf: &Elf) -> Vec<Frame> {
pub fn frames(raw_frames: &[RawFrame], current_dir: &Path, elf: &Elf) -> Vec<Frame> {
let mut frames = vec![];

let symtab = elf.symbol_map();
Expand Down Expand Up @@ -43,17 +43,17 @@ pub(crate) fn frames(raw_frames: &[RawFrame], current_dir: &Path, elf: &Elf) ->

/// Processed frame
#[derive(Debug)]
pub(crate) enum Frame {
pub enum Frame {
Exception,
Subroutine(Subroutine),
}

/// "Symbolicated" and de-inlined subroutine frame
#[derive(Debug)]
pub(crate) struct Subroutine {
pub(crate) name: Option<String>,
pub(crate) pc: u32,
pub(crate) location: Option<Location>,
pub struct Subroutine {
pub name: Option<String>,
pub pc: u32,
pub location: Option<Location>,
}

type A2lContext = addr2line::Context<EndianReader<RunTimeEndian, Rc<[u8]>>>;
Expand Down Expand Up @@ -168,9 +168,9 @@ fn name_from_symtab(pc: u32, symtab: &SymbolMap<SymbolMapName>) -> Option<String
}

#[derive(Debug)]
pub(crate) struct Location {
pub(crate) column: Option<u32>,
pub(crate) path_is_relative: bool,
pub(crate) line: u32,
pub(crate) path: PathBuf,
pub struct Location {
pub column: Option<u32>,
pub path_is_relative: bool,
pub line: u32,
pub path: PathBuf,
}
14 changes: 7 additions & 7 deletions src/backtrace/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn missing_debug_info(pc: u32) -> String {
///
/// This returns as much info as could be collected, even if the collection is interrupted by an error.
/// If an error occurred during processing, it is stored in `Output::processing_error`.
pub(crate) fn target(core: &mut Core, elf: &Elf, active_ram_region: &Option<RamRegion>) -> Output {
pub fn target(core: &mut Core, elf: &Elf, active_ram_region: &Option<RamRegion>) -> Output {
let mut output = Output {
corrupted: true,
outcome: Outcome::Ok,
Expand Down Expand Up @@ -171,24 +171,24 @@ fn check_hard_fault(

#[derive(Debug)]
pub struct Output {
pub(crate) corrupted: bool,
pub(crate) outcome: Outcome,
pub(crate) raw_frames: Vec<RawFrame>,
pub corrupted: bool,
pub outcome: Outcome,
pub raw_frames: Vec<RawFrame>,
/// Will be `Some` if an error occured while putting together the output.
/// `outcome` and `raw_frames` will contain all info collected until the error occurred.
pub(crate) processing_error: Option<anyhow::Error>,
pub processing_error: Option<anyhow::Error>,
}

/// Backtrace frame prior to 'symbolication'
#[derive(Debug)]
pub(crate) enum RawFrame {
pub enum RawFrame {
Subroutine { pc: u32 },
Exception,
}

impl RawFrame {
/// Returns `true` if the raw_frame is [`Exception`].
pub(crate) fn is_exception(&self) -> bool {
pub fn is_exception(&self) -> bool {
matches!(self, Self::Exception)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/canary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const CANARY_U32: u32 = u32::from_le_bytes([CANARY_U8, CANARY_U8, CANARY_U8, CAN
/// "touched" (any of its bytes != `CANARY_U8`) then that is considered to be a *potential* stack
/// overflow.
#[derive(Clone, Copy)]
pub(crate) struct Canary {
pub struct Canary {
address: u32,
size: usize,
stack_available: u32,
Expand All @@ -49,7 +49,7 @@ pub(crate) struct Canary {

impl Canary {
/// Decide if and where to place the stack canary.
pub(crate) fn install(
pub fn install(
sess: &mut Session,
target_info: &TargetInfo,
elf: &Elf,
Expand Down Expand Up @@ -113,7 +113,7 @@ impl Canary {
}

/// Detect if the stack canary was touched.
pub(crate) fn touched(self, core: &mut probe_rs::Core, elf: &Elf) -> anyhow::Result<bool> {
pub fn touched(self, core: &mut probe_rs::Core, elf: &Elf) -> anyhow::Result<bool> {
let size_kb = self.size as f64 / 1024.0;
if self.measure_stack {
log::info!("reading {size_kb:.2} KiB of RAM for stack usage estimation");
Expand Down
28 changes: 14 additions & 14 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const EXIT_SUCCESS: i32 = 0;
/// A Cargo runner for microcontrollers.
#[derive(StructOpt)]
#[structopt(name = "probe-run", setting = AppSettings::TrailingVarArg)]
pub(crate) struct Opts {
pub struct Opts {
/// List supported chips and exit.
#[structopt(long)]
list_chips: bool,
Expand All @@ -29,65 +29,65 @@ pub(crate) struct Opts {

/// Path to chip description file, in YAML format.
#[structopt(long)]
pub(crate) chip_description_path: Option<PathBuf>,
pub chip_description_path: Option<PathBuf>,

/// The probe to use (eg. `VID:PID`, `VID:PID:Serial`, or just `Serial`).
#[structopt(long, env = "PROBE_RUN_PROBE")]
pub(crate) probe: Option<String>,
pub probe: Option<String>,

/// The probe clock frequency in kHz
#[structopt(long)]
pub(crate) speed: Option<u32>,
pub speed: Option<u32>,

/// Path to an ELF firmware file.
#[structopt(name = "ELF", parse(from_os_str), required_unless_one(&["list-chips", "list-probes", "version"]))]
elf: Option<PathBuf>,

/// Skip writing the application binary to flash.
#[structopt(long, conflicts_with = "defmt")]
pub(crate) no_flash: bool,
pub no_flash: bool,

/// Connect to device when NRST is pressed.
#[structopt(long)]
pub(crate) connect_under_reset: bool,
pub connect_under_reset: bool,

/// Enable more verbose output.
#[structopt(short, long, parse(from_occurrences))]
pub(crate) verbose: u32,
pub verbose: u32,

/// Prints version information
#[structopt(short = "V", long)]
version: bool,

/// Disable or enable backtrace (auto in case of panic or stack overflow).
#[structopt(long, default_value = "auto")]
pub(crate) backtrace: String,
pub backtrace: String,

/// Configure the number of lines to print before a backtrace gets cut off
#[structopt(long, default_value = "50")]
pub(crate) backtrace_limit: u32,
pub backtrace_limit: u32,

/// Whether to shorten paths (e.g. to crates.io dependencies) in backtraces and defmt logs
#[structopt(long)]
pub(crate) shorten_paths: bool,
pub shorten_paths: bool,

/// Whether to measure the program's stack consumption.
#[structopt(long)]
pub(crate) measure_stack: bool,
pub measure_stack: bool,

#[structopt(long)]
pub(crate) json: bool,
pub json: bool,

/// Disable use of double buffering while downloading flash
#[structopt(long = "disable-double-buffering")]
pub(crate) disable_double_buffering: bool,
pub disable_double_buffering: bool,

/// Arguments passed after the ELF file path are discarded
#[structopt(name = "REST")]
_rest: Vec<String>,
}

pub(crate) fn handle_arguments() -> anyhow::Result<i32> {
pub fn handle_arguments() -> anyhow::Result<i32> {
let opts: Opts = Opts::from_args();
let verbose = opts.verbose;

Expand Down
28 changes: 14 additions & 14 deletions src/cortexm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,50 @@ use std::{mem, ops::Range};

use gimli::LittleEndian;

pub(crate) const ADDRESS_SIZE: u8 = mem::size_of::<u32>() as u8;
pub const ADDRESS_SIZE: u8 = mem::size_of::<u32>() as u8;

/// According to Armv8-M Architecture Reference Manual, the most significant 8 bits are `0xFF` to
/// indicate `EXC_RETURN`, the rest is either reserved or contains data.
pub(crate) const EXC_RETURN_MARKER: u32 = 0xFF00_0000;
pub const EXC_RETURN_MARKER: u32 = 0xFF00_0000;

pub(crate) const EXC_RETURN_FTYPE_MASK: u32 = 1 << 4;
pub const EXC_RETURN_FTYPE_MASK: u32 = 1 << 4;

pub(crate) const ENDIANNESS: LittleEndian = LittleEndian;
pub(crate) type Endianness = LittleEndian;
pub const ENDIANNESS: LittleEndian = LittleEndian;
pub type Endianness = LittleEndian;

const THUMB_BIT: u32 = 1;
// According to the ARM Cortex-M Reference Manual RAM memory must be located in this address range
// (vendors still place e.g. Core-Coupled RAM outside this address range)
pub(crate) const VALID_RAM_ADDRESS: Range<u32> = 0x2000_0000..0x4000_0000;
pub const VALID_RAM_ADDRESS: Range<u32> = 0x2000_0000..0x4000_0000;

pub(crate) fn clear_thumb_bit(addr: u32) -> u32 {
pub fn clear_thumb_bit(addr: u32) -> u32 {
addr & !THUMB_BIT
}

/// Checks if PC is the HardFault handler
// XXX may want to relax this to cover the whole PC range of the `HardFault` handler
pub(crate) fn is_hard_fault(pc: u32, vector_table: &VectorTable) -> bool {
pub fn is_hard_fault(pc: u32, vector_table: &VectorTable) -> bool {
subroutine_eq(pc, vector_table.hard_fault)
}

pub(crate) fn is_thumb_bit_set(addr: u32) -> bool {
pub fn is_thumb_bit_set(addr: u32) -> bool {
addr & THUMB_BIT == THUMB_BIT
}

pub(crate) fn set_thumb_bit(addr: u32) -> u32 {
pub fn set_thumb_bit(addr: u32) -> u32 {
addr | THUMB_BIT
}

/// Checks if two subroutine addresses are equivalent by first clearing their `THUMB_BIT`
pub(crate) fn subroutine_eq(addr1: u32, addr2: u32) -> bool {
pub fn subroutine_eq(addr1: u32, addr2: u32) -> bool {
addr1 & !THUMB_BIT == addr2 & !THUMB_BIT
}

/// The contents of the vector table
#[derive(Debug)]
pub(crate) struct VectorTable {
pub struct VectorTable {
// entry 0
pub(crate) initial_stack_pointer: u32,
pub initial_stack_pointer: u32,
// entry 3: HardFault handler
pub(crate) hard_fault: u32,
pub hard_fault: u32,
}
8 changes: 4 additions & 4 deletions src/dep/cratesio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::path::{self, Component, Path as StdPath, PathBuf};
use colored::Colorize as _;

#[derive(Debug, PartialEq)]
pub(crate) struct Path<'p> {
pub struct Path<'p> {
registry_prefix: PathBuf,
crate_name_version: &'p str,
path: &'p StdPath,
}

impl<'p> Path<'p> {
pub(crate) fn from_std_path(path: &'p StdPath) -> Option<Self> {
pub fn from_std_path(path: &'p StdPath) -> Option<Self> {
if !path.is_absolute() {
return None;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<'p> Path<'p> {
})
}

pub(crate) fn format_short(&self) -> String {
pub fn format_short(&self) -> String {
format!(
"[{}]{}{}",
self.crate_name_version,
Expand All @@ -58,7 +58,7 @@ impl<'p> Path<'p> {
)
}

pub(crate) fn format_highlight(&self) -> String {
pub fn format_highlight(&self) -> String {
format!(
"{}{sep}{}{sep}{}",
self.registry_prefix.display().to_string().dimmed(),
Expand Down

0 comments on commit 2fdd24a

Please sign in to comment.