Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
bts_dump.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <getopt.h>
4 
5 #include <bts.h>
6 
7 static void bts_show(const char *fname);
8 
9 struct symmap symmap[] = {
10  /* user space */
11  {
12  .symfile = NULL,
13  .prefix = "User:",
14  .loaddr = 0x08000000,
15  .hiaddr = 0xBFFFFFFF
16  },
17  /* Linux kernel */
18  {
19  .symfile = "/boot/vmlinux-syms-2.6.18-xenU",
20  .prefix = "",
21  .loaddr = 0xC0000000,
22  .hiaddr = 0xF67FFFFF
23  },
24  /* Xen */
25  {
26  .symfile = "/boot/xen-syms-3.0-unstable",
27  .prefix = "Xen:",
28  .loaddr = 0xF6800000,
29  .hiaddr = 0xFFFFFFFF
30  }
31 };
32 
33 int debug = 0;
34 int symbolic = 0;
35 int gdbstyle = 0;
36 char *userbin = NULL;
37 
38 int main(int argc, char **argv)
39 {
40  char ch;
41 
42  while ((ch = getopt(argc, argv, "dSGU:")) != -1) {
43  switch(ch) {
44  case 'd':
45  debug++;
46  break;
47  case 'S':
48  symbolic++;
49  break;
50  case 'G':
51  gdbstyle++;
52  break;
53  case 'U':
54  userbin = optarg;
55  break;
56  }
57  }
58  argc -= optind;
59  argv += optind;
60 
61  if (argc < 1) {
62  fprintf(stderr, "Usage: bts-dump [-dS] filename ...\n");
63  exit(1);
64  }
65 
66  if (userbin)
67  symmap[0].symfile = userbin;
68 
69  /*
70  * Open symbol files.
71  */
72  if (symbolic && symlist_init(symmap, sizeof(symmap)/sizeof(symmap[0])))
73  exit(1);
74 
75  while (argc) {
76  bts_show(*argv);
77  argc--, argv++;
78  }
79 
80  exit(0);
81 }
82 
83 static void bts_show(const char *fname)
84 {
85  struct bts_rec recs[1024];
86  int n, i, extended = 0;
87  long long tot = 0;
88 
89  BTSFD fd = bts_open(fname);
90  if (fd == 0) {
91  fprintf(stderr, "Could not open stream\n");
92  return;
93  }
94 
95  while (1) {
96  n = bts_read(fd, recs, 1024);
97  if (n == 0)
98  break;
99 
100  i = 0;
101 
102  /* see if this is extended format */
103  if (tot == 0 && recs[0].from == UINT64_MAX &&
104  recs[0].to == UINT64_MAX && recs[0].format == UINT64_MAX) {
105  if (debug)
106  fprintf(stderr, "Dump file in extended format\n");
107  extended++;
108  i++;
109  }
110 
111  while (i < n) {
112  if (extended)
113  printf("%012lld: ", recs[i].format);
114  else
115  printf("%lld: ", tot+i);
116  if (symbolic) {
117  char s1[256], s2[256];
118  if (gdbstyle) {
119  symlist_gdb_string(recs[i].from, s1, sizeof(s1));
120  symlist_gdb_string(recs[i].to, s2, sizeof(s2));
121  } else {
122  symlist_string(recs[i].from, s1, sizeof(s1));
123  symlist_string(recs[i].to, s2, sizeof(s2));
124  }
125  printf("%s -> %s\n", s1, s2);
126  } else {
127  printf("0x%08llx -> 0x%08llx\n", recs[i].from, recs[i].to);
128  }
129  i++;
130  }
131  tot += n;
132  }
133 
134  bts_close(fd);
135 }
136 
137 /*
138  * Local variables:
139  * mode: C
140  * c-set-style: "BSD"
141  * c-basic-offset: 4
142  * End:
143  */
void bts_close(BTSFD)
Definition: io.c:113
void symlist_string(uint32_t, char *, int)
Definition: symbol.c:332
char * optarg
Definition: bts.h:23
int optind
int symbolic
Definition: bts_dump.c:34
int extended
Definition: bts_extract.c:24
void * BTSFD
Definition: bts.h:29
static uint64_t unsigned int i
void symlist_gdb_string(uint32_t, char *, int)
Definition: symbol.c:326
int gdbstyle
Definition: bts_dump.c:35
int bts_read(BTSFD, struct bts_rec *, int)
Definition: io.c:73
char * symfile
Definition: bts.h:8
uint64_t from
Definition: bts.h:24
char * userbin
Definition: bts_dump.c:36
int16_t s2
int debug
Definition: bts_dump.c:33
BTSFD bts_open(const char *)
Definition: io.c:19
uint64_t format
Definition: bts.h:26
uint64_t to
Definition: bts.h:25
int symlist_init(struct symmap[], int)
Definition: symbol.c:20
Definition: bts.h:7
int main(int argc, char **argv)
Definition: bts_dump.c:38