Skip to content

Commit

Permalink
Lib'ify, split reusable code in addr-symbolizer (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
0vercl0k authored Oct 17, 2024
1 parent 10e187e commit 130635c
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 2,051 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/symbolizer-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: cargo clippy
env:
RUSTFLAGS: "-Dwarnings"
run: cargo clippy
run: cargo clippy --workspace --tests --examples

doc:
name: doc
Expand Down Expand Up @@ -65,16 +65,16 @@ jobs:
run: rustup default stable

- name: cargo test
run: cargo test
run: cargo test --workspace

- name: cargo test release
run: cargo test --release
run: cargo test --release --workspace

- name: cargo check
run: cargo check
run: cargo check --workspace --examples --tests

- name: cargo build
run: cargo build --release
run: cargo build --release --workspace --examples --tests

- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
28 changes: 9 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
[package]
name = "symbolizer-rs"
version = "0.1.0"
edition = "2021"
authors = ["Axel '0vercl0k' Souchet"]
categories = ["command-line-utilities", "development-tools::debugging"]
description = "A fast execution trace symbolizer for Windows that runs on all major platforms and doesn't depend on any Microsoft libraries."
include = ["/Cargo.toml", "/LICENSE", "/src/**", "README.md"]
keywords = ["windows", "kernel", "crash-dump", "symbols", "pdb"]
version = "0.1.0"
authors = ["Axel '0vercl0k' Souchet"]
license = "MIT"
repository = "https://github.com/0vercl0k/symbolizer-rs"
rust-version = "1.70"
repository = "https://github.com/0vercl0k/symbolizer-rs"
keywords = ["windows", "kernel", "crash-dump", "symbols", "pdb"]
edition = "2021"

[dependencies]
anyhow = "1.0"
pdb = "0.8"
log = "0.4"
env_logger = "0.11"
clap = { version = "4.5", features = ["derive"] }
msvc-demangler = "0.10"
ureq = { version = "2.9", default-features = false, features = [
"tls",
"gzip",
] }
kdmp-parser = "0.2"
itoa = "1.0.11"
addr-symbolizer = { version = "0.1" }
env_logger = "0.11"
itoa = "1.0"
kdmp-parser = "0.5"

[profile.release]
debug = true
panic = "abort"

[[bin]]
name = "symbolizer-rs"
path = "src/main.rs"
42 changes: 0 additions & 42 deletions src/guid.rs

This file was deleted.

12 changes: 5 additions & 7 deletions src/hex_addrs_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn fast_hex_str_to_u32(hex: [u8; 8]) -> u32 {

/// Convert the `slice` of an hexadecimal string into an integer.
fn hex_slice(slice: &[u8]) -> Result<u64> {
let slice = slice.strip_prefix(&[b'0', b'x']).unwrap_or(slice);
let slice = slice.strip_prefix(b"0x").unwrap_or(slice);
if slice.len() > 16 {
bail!("{slice:?} has more digits than supported (16)");
}
Expand Down Expand Up @@ -165,7 +165,7 @@ where
if let Some(last_range) = self.last_range {
let last_slice = &self.buf[last_range];
// Be nice, and ignore a potential trailing end of line..
let last_slice = last_slice.strip_suffix(&[b'\n']).unwrap_or(last_slice);
let last_slice = last_slice.strip_suffix(b"\n").unwrap_or(last_slice);
// ..and if there's a carriage return right before, let's ignore this one as
// well.
let last_slice = last_slice
Expand Down Expand Up @@ -214,7 +214,7 @@ where
// what we return where the next slice starts at
Some(idx) => {
let without_lf = &parse_slice[..idx];
let without_cr = without_lf.strip_suffix(&[b'\r']);
let without_cr = without_lf.strip_suffix(b"\r");

(without_cr.unwrap_or(without_lf), idx + 1)
}
Expand All @@ -232,7 +232,7 @@ where
.with_context(|| anyhow!("failed to turn {addr_str:?} into an integer"))
{
Ok(o) => o,
Err(e) => return Some(Err(e)),
e => return Some(e),
};

// If we hit the EOF, let's record the last range of data we'll consume.
Expand Down Expand Up @@ -265,9 +265,7 @@ where
mod tests {
use std::io::BufReader;

use anyhow::Result;

use super::HexAddressesIterator;
use super::{HexAddressesIterator, Result};

#[test]
fn t1() {
Expand Down
10 changes: 5 additions & 5 deletions src/human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub trait ToHuman: Sized + Copy {
/// Blanket implementation for all the `T` that have what we need.
impl<T> ToHuman for T
where
T: Into<u64>,
T: TryInto<u64>,
T: Copy,
{
}
Expand All @@ -34,12 +34,12 @@ pub struct HumanTime<T>(T);

impl<T> Display for HumanTime<T>
where
T: Into<u64>,
T: TryInto<u64>,
T: Copy,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut unit = "s";
let mut time = self.0.into() as f64;
let mut time = self.0.try_into().map_err(|_| std::fmt::Error)? as f64;
let m = 60f64;
let h = m * m;
let d = h * 24.0;
Expand Down Expand Up @@ -92,12 +92,12 @@ pub struct HumanNumber<T>(T);

impl<T> Display for HumanNumber<T>
where
T: Into<u64>,
T: TryInto<u64>,
T: Copy,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut unit = "";
let mut size = self.0.into() as f64;
let mut size = self.0.try_into().map_err(|_| std::fmt::Error)? as f64;
let k = 1_000f64;
let m = k * k;
let b = m * k;
Expand Down
Loading

0 comments on commit 130635c

Please sign in to comment.