memzap

replay memory writes
git clone git://git.2f30.org/memzap
Log | Files | Refs | README | LICENSE

mdiffdump.c (1324B)


      1 /* See LICENSE file for copyright and license details. */
      2 
      3 #include "proto.h"
      4 
      5 int
      6 main(int argc, char *argv[])
      7 {
      8 	int fd;
      9 	struct mdiff_hdr *hdr;
     10 	struct mdiff_region *mdiff;
     11 	uint32_t i, j;
     12 	char *p;
     13 
     14 	if (argc != 2) {
     15 		fprintf(stderr, "usage: %s <mdiff-file>\n", *argv);
     16 		return 1;
     17 	}
     18 
     19 	fd = open_mdiff(argv[1]);
     20 	hdr = parse_mdiff_hdr(fd);
     21 	if (!hdr)
     22 		errx(1, "%s: failed to parse mdiff", argv[1]);
     23 
     24 	printf("MDIFF header:\n");
     25 	printf("  endianness: %s\n",
     26 	       hdr->endianness ? "big endian" : "little endian");
     27 	printf("  version: %hhu\n", hdr->version);
     28 	printf("  nregions: %lu\n", (unsigned long)hdr->nregions);
     29 	printf("  rsize: %lu\n", (unsigned long)hdr->rsize);
     30 	printf("  blksize: %lu\n", (unsigned long)hdr->blksize);
     31 
     32 	printf("\nDiff sections:\n");
     33 	for (i = 0; i < hdr->nregions; i++) {
     34 		mdiff = mdiff_read_diff(fd, hdr, i);
     35 		printf("  [%lu]: cycle: %llu\n", (unsigned long)i,
     36 		       (unsigned long long)mdiff->cycle);
     37 		printf("  [%lu]: offset: %lu\n", (unsigned long)i,
     38 		       (unsigned long)mdiff->offset);
     39 		printf("  [%lu]: len: %lu\n", (unsigned long)i,
     40 		       (unsigned long)mdiff->len);
     41 		printf("  [%lu]: buf: ", (unsigned long)i);
     42 		p = mdiff->buf;
     43 		for (j = 0; j < mdiff->len; j++)
     44 			putchar(p[j]);
     45 		putchar('\n');
     46 		free_mdiff_region(mdiff);
     47 	}
     48 
     49 	close_mdiff(fd);
     50 	return 0;
     51 }