Skip to content
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

Make dir_section and mem_writer modules public #53

Merged
merged 2 commits into from Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 36 additions & 0 deletions examples/synthetic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Emits default minidump with no streams to specified path

use std::fs::File;

use minidump_writer::{
dir_section::DirSection,
mem_writer::{Buffer, MemoryWriter},
minidump_format::{MDRawHeader, MD_HEADER_SIGNATURE, MD_HEADER_VERSION},
};

// usage: `cargo run --example synthetic /tmp/micro-minidump.dmp`
fn main() {
let output_path = std::env::args()
.nth(1)
.expect("missing argument: output file path");

let num_writers = 0u32;
let buffer_capacity = 32;

let mut destination = File::create(output_path).expect("failed to create file");
let mut buffer = Buffer::with_capacity(buffer_capacity);
let mut header_section = MemoryWriter::<MDRawHeader>::alloc(&mut buffer).unwrap();
let mut dir_section = DirSection::new(&mut buffer, num_writers, &mut destination).unwrap();

let header = MDRawHeader {
signature: MD_HEADER_SIGNATURE,
version: MD_HEADER_VERSION,
stream_count: num_writers,
stream_directory_rva: dir_section.position(),
checksum: 0,
time_date_stamp: 0u32,
flags: 0,
};
header_section.set_value(&mut buffer, header).unwrap();
dir_section.write_to_file(&mut buffer, None).unwrap();
}
10 changes: 2 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,5 @@ cfg_if::cfg_if! {
pub mod minidump_cpu;
pub mod minidump_format;

// Non-windows platforms need additional code since they are essentially
// replicating functionality we get for free on Windows
cfg_if::cfg_if! {
if #[cfg(not(target_os = "windows"))] {
pub(crate) mod mem_writer;
pub(crate) mod dir_section;
}
}
pub mod dir_section;
pub mod mem_writer;