1#include <stdio.h>
2#include <unistd.h>
3#include <stdlib.h>
4#include <inttypes.h>
5#include <assert.h>
6#include "trace_reader.h"
7#include "armdis.h"
8#include "parse_options.h"
9
10typedef TraceReader<> TraceReaderType;
11
12#include "parse_options-inl.h"
13
14static const uint32_t kOffsetThreshold = 0x100000;
15
16void Usage(const char *program)
17{
18    fprintf(stderr, "Usage: %s [options] trace_file elf_file\n", program);
19    OptionsUsage();
20}
21
22int main(int argc, char **argv) {
23    // Parse the options
24    ParseOptions(argc, argv);
25    if (argc - optind != 2) {
26        Usage(argv[0]);
27        exit(1);
28    }
29
30    char *trace_filename = argv[optind++];
31    char *elf_file = argv[optind++];
32    TraceReader<> *trace = new TraceReader<>;
33    trace->Open(trace_filename);
34    trace->ReadKernelSymbols(elf_file);
35    trace->SetRoot(root);
36
37    while (1) {
38        symbol_type *sym;
39        BBEvent event;
40        BBEvent ignored;
41
42        if (GetNextValidEvent(trace, &event, &ignored, &sym))
43            break;
44        if (event.bb_num == 0)
45            break;
46        //printf("t%llu bb %lld %d\n", event.time, event.bb_num, event.num_insns);
47        uint64_t insn_time = trace->ReadInsnTime(event.time);
48        if (insn_time != event.time) {
49            printf("time: %llu insn time: %llu bb: %llu addr: 0x%x num_insns: %d, pid: %d\n",
50                   event.time, insn_time, event.bb_num, event.bb_addr,
51                   event.num_insns, event.pid);
52            exit(1);
53        }
54        for (int ii = 1; ii < event.num_insns; ++ii) {
55            trace->ReadInsnTime(event.time);
56        }
57    }
58
59    delete trace;
60    return 0;
61}
62