libmicroemu 0.2.0
ARM Microcontroller Emulator Library
Loading...
Searching...
No Matches
memory_viewer.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "libmicroemu/types.h"
8#include <ctype.h>
9
10namespace libmicroemu::internal {
11
12template <typename TCpuAccessor, typename TBus> class MemoryViewer {
13public:
22 static void Print(TCpuAccessor &cpua, const TBus &mem, const me_offset_t vadr,
23 const me_size_t size, const u32 indent = 0U) {
24 const me_adr_t vadr_end = vadr + size;
25 const auto alignment = 16U;
26
27 const me_size_t no_filler_bytes = vadr % alignment;
28 const me_adr_t vadr_filler = vadr - no_filler_bytes;
29
30 // in case of addresses which do not fit into the alignment print
31 // out the address and filler spaces
32 if (no_filler_bytes > 0U) {
33
34 PrintSection(cpua, mem, vadr_filler, vadr_filler + no_filler_bytes, alignment, indent, true);
35 }
36
37 PrintSection(cpua, mem, vadr, vadr_end, alignment, indent, false);
38 printf("\n");
39 }
40
41private:
42 MemoryViewer() = delete;
43
44 ~MemoryViewer() = delete;
45
50 MemoryViewer(const MemoryViewer &r_src) = delete;
51
56 MemoryViewer &operator=(const MemoryViewer &r_src) = delete;
57
62 MemoryViewer(MemoryViewer &&r_src) = delete;
63
68 MemoryViewer &operator=(MemoryViewer &&r_src) = delete;
69
70 static void PrintSection(TCpuAccessor &cpua, const TBus &mem, const me_adr_t vadr_begin,
71 const me_adr_t vadr_end, const u32 alignment, u32 indent,
72 bool skip_read) {
73
74 for (me_adr_t ivadr = vadr_begin; ivadr < vadr_end; ivadr++) {
75 // Print address first
76 if (ivadr % alignment == 0U) {
77 for (u32 spaces = 0U; spaces < indent; ++spaces) {
78 printf(" ");
79 }
80 printf("%08x|", ivadr);
81 }
82
83 // Then the byte
84 if (!skip_read) {
85 auto res = mem.template Read<u8>(cpua, ivadr);
86 if (res.IsErr()) {
87 printf("xx");
88 } else {
89 printf("%02x", res.content);
90 }
91 } else {
92 printf(" ");
93 }
94
95 // Following by an delimiter
96 printf(" ");
97
98 // After x bytes add a newline
99 // ... special condition do not add newline at the end
100 if ((ivadr % alignment == alignment - 1) && (ivadr != vadr_end - 1)) {
101 printf("\n");
102 }
103 }
104 }
105};
106
107} // namespace libmicroemu::internal
Definition memory_viewer.h:12
static void Print(TCpuAccessor &cpua, const TBus &mem, const me_offset_t vadr, const me_size_t size, const u32 indent=0U)
Print memory content to the console.
Definition memory_viewer.h:22
The libmicroemu::internal namespace contains all classes and functions of libmicroemu which are priva...
Definition bkpt_flags.h:6