Skip to content

Refactor...a lot #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
[package]
name = "minidump_writer_linux"
name = "minidump-writer"
version = "0.1.0"
authors = ["Martin Sirringhaus"]
edition = "2018"
edition = "2021"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tempfile = "3.1.0"
nix = "0.15"
libc = "0.2.74"
memoffset = "0.5.1"
byteorder = "1.3.2"
memmap2 = "0.2.2"
goblin = "0.1.2"
cfg-if = "1.0"
goblin = "0.5"
libc = "0.2.74"
memmap2 = "0.5"
memoffset = "0.6"
minidump-common = "0.10"
nix = "0.23"
scroll = "0.11"
tempfile = "3.1.0"
thiserror = "1.0.21"

[dependencies.crash-context]
#git = "https://github.com/EmbarkStudios/crash-handling"
#branch = "impl"
path = "../crash-handling/crash-context"
features = ["fill-minidump"]

[dev-dependencies]
minidump = {git = "https://github.com/luser/rust-minidump", rev="9652b3b" }
minidump-common = {git = "https://github.com/luser/rust-minidump", rev="9652b3b" }
debugid = "0.7.3"
minidump = "0.10"

[patch.crates-io]
minidump = { git = "https://github.com/EmbarkStudios/rust-minidump", branch = "master" }
minidump-common = { git = "https://github.com/EmbarkStudios/rust-minidump", branch = "master" }
29 changes: 15 additions & 14 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// This binary shouldn't be under /src, but under /tests, but that is
// currently not possible (https://github.com/rust-lang/cargo/issues/4356)
use minidump_writer_linux::linux_ptrace_dumper::{LinuxPtraceDumper, AT_SYSINFO_EHDR};
use minidump_writer_linux::{linux_ptrace_dumper, LINUX_GATE_LIBRARY_NAME};
use minidump_writer::{
ptrace_dumper::{PtraceDumper, AT_SYSINFO_EHDR},
LINUX_GATE_LIBRARY_NAME,
};
use nix::sys::mman::{mmap, MapFlags, ProtFlags};
use nix::unistd::getppid;
use std::convert::TryInto;
use std::env;
use std::error;
use std::result;
Expand All @@ -24,13 +25,13 @@ macro_rules! test {

fn test_setup() -> Result<()> {
let ppid = getppid();
linux_ptrace_dumper::LinuxPtraceDumper::new(ppid.as_raw())?;
PtraceDumper::new(ppid.as_raw())?;
Ok(())
}

fn test_thread_list() -> Result<()> {
let ppid = getppid();
let dumper = linux_ptrace_dumper::LinuxPtraceDumper::new(ppid.as_raw())?;
let dumper = PtraceDumper::new(ppid.as_raw())?;
test!(!dumper.threads.is_empty(), "No threads")?;
test!(
dumper
Expand All @@ -46,17 +47,17 @@ fn test_thread_list() -> Result<()> {

fn test_copy_from_process(stack_var: usize, heap_var: usize) -> Result<()> {
let ppid = getppid().as_raw();
let mut dumper = linux_ptrace_dumper::LinuxPtraceDumper::new(ppid)?;
let mut dumper = PtraceDumper::new(ppid)?;
dumper.suspend_threads()?;
let stack_res = LinuxPtraceDumper::copy_from_process(ppid, stack_var as *mut libc::c_void, 1)?;
let stack_res = PtraceDumper::copy_from_process(ppid, stack_var as *mut libc::c_void, 1)?;

let expected_stack: libc::c_long = 0x11223344;
test!(
stack_res == expected_stack.to_ne_bytes(),
"stack var not correct"
)?;

let heap_res = LinuxPtraceDumper::copy_from_process(ppid, heap_var as *mut libc::c_void, 1)?;
let heap_res = PtraceDumper::copy_from_process(ppid, heap_var as *mut libc::c_void, 1)?;
let expected_heap: libc::c_long = 0x55667788;
test!(
heap_res == expected_heap.to_ne_bytes(),
Expand All @@ -68,7 +69,7 @@ fn test_copy_from_process(stack_var: usize, heap_var: usize) -> Result<()> {

fn test_find_mappings(addr1: usize, addr2: usize) -> Result<()> {
let ppid = getppid();
let dumper = linux_ptrace_dumper::LinuxPtraceDumper::new(ppid.as_raw())?;
let dumper = PtraceDumper::new(ppid.as_raw())?;
dumper
.find_mapping(addr1)
.ok_or("No mapping for addr1 found")?;
Expand All @@ -85,7 +86,7 @@ fn test_file_id() -> Result<()> {
let ppid = getppid().as_raw();
let exe_link = format!("/proc/{}/exe", ppid);
let exe_name = std::fs::read_link(&exe_link)?.into_os_string();
let mut dumper = linux_ptrace_dumper::LinuxPtraceDumper::new(getppid().as_raw())?;
let mut dumper = PtraceDumper::new(getppid().as_raw())?;
let mut found_exe = None;
for (idx, mapping) in dumper.mappings.iter().enumerate() {
if mapping.name.as_ref().map(|x| x.into()).as_ref() == Some(&exe_name) {
Expand All @@ -102,7 +103,7 @@ fn test_file_id() -> Result<()> {

fn test_merged_mappings(path: String, mapped_mem: usize, mem_size: usize) -> Result<()> {
// Now check that LinuxPtraceDumper interpreted the mappings properly.
let dumper = linux_ptrace_dumper::LinuxPtraceDumper::new(getppid().as_raw())?;
let dumper = PtraceDumper::new(getppid().as_raw())?;
let mut mapping_count = 0;
for map in &dumper.mappings {
if map.name == Some(path.clone()) {
Expand All @@ -120,13 +121,13 @@ fn test_merged_mappings(path: String, mapped_mem: usize, mem_size: usize) -> Res

fn test_linux_gate_mapping_id() -> Result<()> {
let ppid = getppid().as_raw();
let mut dumper = linux_ptrace_dumper::LinuxPtraceDumper::new(ppid)?;
let mut dumper = PtraceDumper::new(ppid)?;
let mut found_linux_gate = false;
for mut mapping in dumper.mappings.clone() {
if mapping.name.as_deref() == Some(LINUX_GATE_LIBRARY_NAME) {
found_linux_gate = true;
dumper.suspend_threads()?;
let id = LinuxPtraceDumper::elf_identifier_for_mapping(&mut mapping, ppid)?;
let id = PtraceDumper::elf_identifier_for_mapping(&mut mapping, ppid)?;
test!(!id.is_empty(), "id-vec is empty")?;
test!(id.iter().any(|&x| x > 0), "all id elements are 0")?;
dumper.resume_threads()?;
Expand All @@ -139,7 +140,7 @@ fn test_linux_gate_mapping_id() -> Result<()> {

fn test_mappings_include_linux_gate() -> Result<()> {
let ppid = getppid().as_raw();
let dumper = linux_ptrace_dumper::LinuxPtraceDumper::new(ppid)?;
let dumper = PtraceDumper::new(ppid)?;
let linux_gate_loc = dumper.auxv[&AT_SYSINFO_EHDR];
test!(linux_gate_loc != 0, "linux_gate_loc == 0")?;
let mut found_linux_gate = false;
Expand Down
11 changes: 0 additions & 11 deletions src/crash_context/crash_context_aarch64.rs

This file was deleted.

50 changes: 0 additions & 50 deletions src/crash_context/crash_context_x86.rs

This file was deleted.

69 changes: 0 additions & 69 deletions src/crash_context/crash_context_x86_64.rs

This file was deleted.

65 changes: 0 additions & 65 deletions src/crash_context/mod.rs

This file was deleted.

Loading