82c02b6c87e6b40859ee351eaab7f9957c4aafc9
[riscv-isa-sim.git] / riscv / memtracer.h
1 #ifndef _MEMTRACER_H
2 #define _MEMTRACER_H
3
4 #include <stdint.h>
5 #include <string.h>
6 #include <vector>
7
8 class memtracer_t
9 {
10 public:
11 memtracer_t() {}
12 virtual ~memtracer_t() {}
13
14 virtual bool interested_in_range(uint64_t begin, uint64_t end, bool store, bool fetch) = 0;
15 virtual void trace(uint64_t addr, size_t bytes, bool store, bool fetch) = 0;
16 };
17
18 class memtracer_list_t : public memtracer_t
19 {
20 public:
21 bool interested_in_range(uint64_t begin, uint64_t end, bool store, bool fetch)
22 {
23 for (std::vector<memtracer_t*>::iterator it = list.begin(); it != list.end(); ++it)
24 if ((*it)->interested_in_range(begin, end, store, fetch))
25 return true;
26 return false;
27 }
28 void trace(uint64_t addr, size_t bytes, bool store, bool fetch)
29 {
30 for (std::vector<memtracer_t*>::iterator it = list.begin(); it != list.end(); ++it)
31 (*it)->trace(addr, bytes, store, fetch);
32 }
33 void hook(memtracer_t* h)
34 {
35 list.push_back(h);
36 }
37 private:
38 std::vector<memtracer_t*> list;
39 };
40
41 #endif