Skip to content

Commit

Permalink
use pre-commit hooks for linting (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
benfred committed Jun 7, 2023
1 parent c01f264 commit 5d34f6f
Show file tree
Hide file tree
Showing 20 changed files with 814 additions and 449 deletions.
2 changes: 2 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[codespell]
ignore-words-list = crate
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ env:
CARGO_TERM_COLOR: always

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: pre-commit/action@v3.0.0

build-linux-armv7:
runs-on: [self-hosted, linux, arm]
needs: [lint]
steps:
- uses: actions/checkout@v2
- name: Build
Expand All @@ -21,6 +29,7 @@ jobs:

build-mac:
runs-on: macos-latest
needs: [lint]
steps:
- uses: actions/checkout@v2
- name: Build
Expand All @@ -30,6 +39,7 @@ jobs:

build:
runs-on: ${{ matrix.os }}
needs: [lint]
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
Expand All @@ -45,6 +55,7 @@ jobs:

build-linux-cross:
runs-on: ubuntu-latest
needs: [lint]
strategy:
matrix:
target: [i686-musl, x86_64-musl, armv7-musleabihf, aarch64-musl]
Expand Down
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
exclude: (?x)^(ci/testdata.*|images.*)$
ignore_words_list: create
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
- id: cargo-check
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ edition="2021"
[dependencies]
libc = "0.2"
log = "0.4"
proc-maps = "0.3.0"
read-process-memory = "0.1.5"
proc-maps = "0.3.1"
read-process-memory = "0.1.6"
goblin = "0.6.1"
memmap = "0.7.0"
regex = ">=1.6.0"
regex = ">=1.8.3"

[target.'cfg(target_os="macos")'.dependencies]
mach_o_sys = "0.1.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Features:
- Listing all the threads in the process
- Get all the child processes of the process
- Figure out if a thread is active or not
- Read memory from the other proceses (using read_proceses_memory crate)
- Read memory from the other processes (using read_proceses_memory crate)

By enabling the unwind feature you can also:

Expand Down
24 changes: 20 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,26 @@ fn main() {
println!("cargo:rustc-link-search=native=/usr/local/lib");

let out_dir = env::var("OUT_DIR").unwrap();
std::fs::copy(format!("/usr/local/musl/{}/lib/libunwind.a", target), format!("{}/libunwind-remoteprocess.a", out_dir)).unwrap();
std::fs::copy(format!("/usr/local/musl/{}/lib/libunwind-ptrace.a", target), format!("{}/libunwind-ptrace.a", out_dir)).unwrap();
std::fs::copy(format!("/usr/local/musl/{}/lib/libunwind-{}.a", target, target_arch), format!("{}/libunwind-{}.a", out_dir, target_arch)).unwrap();
std::fs::copy(format!("/usr/local/musl/{}/lib/libz.a", target), format!("{}/libz.a", out_dir)).unwrap();
std::fs::copy(
format!("/usr/local/musl/{}/lib/libunwind.a", target),
format!("{}/libunwind-remoteprocess.a", out_dir),
)
.unwrap();
std::fs::copy(
format!("/usr/local/musl/{}/lib/libunwind-ptrace.a", target),
format!("{}/libunwind-ptrace.a", out_dir),
)
.unwrap();
std::fs::copy(
format!("/usr/local/musl/{}/lib/libunwind-{}.a", target, target_arch),
format!("{}/libunwind-{}.a", out_dir, target_arch),
)
.unwrap();
std::fs::copy(
format!("/usr/local/musl/{}/lib/libz.a", target),
format!("{}/libz.a", out_dir),
)
.unwrap();
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=unwind-remoteprocess");
println!("cargo:rustc-link-lib=static=unwind-ptrace");
Expand Down
12 changes: 8 additions & 4 deletions examples/trace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature="unwind")]
#[cfg(feature = "unwind")]
fn get_backtrace(pid: remoteprocess::Pid) -> Result<(), remoteprocess::Error> {
// Create a new handle to the process
let process = remoteprocess::Process::new(pid)?;
Expand All @@ -8,7 +8,11 @@ fn get_backtrace(pid: remoteprocess::Pid) -> Result<(), remoteprocess::Error> {
let unwinder = process.unwinder()?;
let symbolicator = process.symbolicator()?;
for thread in process.threads()?.iter() {
println!("Thread {} - {}", thread.id()?, if thread.active()? { "running" } else { "idle" });
println!(
"Thread {} - {}",
thread.id()?,
if thread.active()? { "running" } else { "idle" }
);

// lock the thread to get a consistent snapshot (unwinding will fail otherwise)
// Note: the thread will appear idle when locked, so we are calling
Expand All @@ -29,7 +33,7 @@ fn get_backtrace(pid: remoteprocess::Pid) -> Result<(), remoteprocess::Error> {
Ok(())
}

#[cfg(feature="unwind")]
#[cfg(feature = "unwind")]
fn main() {
env_logger::init();

Expand All @@ -46,7 +50,7 @@ fn main() {
}
}

#[cfg(not(feature="unwind"))]
#[cfg(not(feature = "unwind"))]
fn main() {
panic!("unwind not supported!");
}
2 changes: 1 addition & 1 deletion src/freebsd/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use log::error;

use std::io::Error as IoError;

use super::Error;
use super::ptrace;
use super::Error;

#[derive(Debug)]
pub struct ProcessLock {
Expand Down
Loading

0 comments on commit 5d34f6f

Please sign in to comment.