#debugging

dbgtools-hexdump

Hexdump functions for use in dbgtools

1 unstable release

0.1.0 May 5, 2021

#57 in #debugging


Used in dbgtools

0BSD license

5KB
65 lines


lib.rs:

A hex dumper which calls a closure to allow the application to choose how to output the dump.

Example: Dumping a struct

use dbgtools_hexdump::{Config, hexdump};

struct MyStruct {
  eight: u8,
  sixteen: u16,
  thirtytwo: u32
}

let data = MyStruct { eight: 8, sixteen: 16, thirtytwo: 32 };
hexdump(Config::default(), &data, |offs, hex, ascii| {
  println!("{:08x} {} {}", offs, hex, ascii);
});

Example: Dumping a struct with addresses

Sometimes it may be useful to include the real addresses in dumped buffers. This can be accomplished by adding a base offset to the configuration context.

use dbgtools_hexdump::{Config, hexdump};

struct MyStruct {
  eight: u8,
  sixteen: u16,
  thirtytwo: u32
}

let data = MyStruct { eight: 8, sixteen: 16, thirtytwo: 32 };
hexdump(Config {
   offs: &data as *const _ as usize,
   ..Default::default()
  }, &data, |offs, hex, ascii| {
  println!("{:08x} {} {}", offs, hex, ascii);
});

No runtime deps