History

Move instruction level printing to asm library

arr committed 10 years ago

Commit fe11a371 parent 8f296184 files · +115 −104Browse files

Showing the changes to src/exec/debugger.cpp (1 of 4 files). Show all

Unified · Split

src/exec/debugger.cpp+19−103
@@ -19,7 +19,7 @@ using namespace disvm::runtime; · 18 unmodified lines
19 19
20namespace20namespace
21{21{
22 std::string to_string_stack(vm_registers_t &r)22 std::string stack_to_string(const vm_registers_t &r)
23 {23 {
24 auto msg = std::stringstream{};24 auto msg = std::stringstream{};
25 walk_stack(r, [&msg](const pointer_t, const vm_pc_t pc, const vm_module_ref_t &module_ref)25 walk_stack(r, [&msg](const pointer_t, const vm_pc_t pc, const vm_module_ref_t &module_ref)
@@ -35,6 +35,20 @@ namespace · 9 unmodified lines
35 return msg.str();35 return msg.str();
36 }36 }
37 37
38 std::string registers_to_string(const vm_registers_t &r)
39 {
40 auto register_string = std::stringstream{};
41
42 register_string
43 << "Registers:\n"
44 << " Thread ID: " << r.thread.get_thread_id() << "\n"
45 << " Module: " << r.module_ref->module->module_name->str() << "\n"
46 << "Program counter: " << r.pc << "\n"
47 << " Opcode: " << r.module_ref->code_section[r.pc].op << "\n";
48
49 return register_string.str();
50 }
51
38 std::ostream& operator<<(std::ostream &ss, const vm_string_t *s)52 std::ostream& operator<<(std::ostream &ss, const vm_string_t *s)
39 {53 {
40 ss << "string\n"54 ss << "string\n"
@@ -76,81 +90,6 @@ namespace · 35 unmodified lines
76 return ss;90 return ss;
77 }91 }
78 92
79 std::ostream& operator<<(std::ostream &ss, const inst_data_generic_t &m)
80 {
81 switch (m.mode)
82 {
83 case address_mode_t::offset_indirect_mp:
84 ss << m.register1 << "(mp)";
85 break;
86 case address_mode_t::offset_indirect_fp:
87 ss << m.register1 << "(fp)";
88 break;
89 case address_mode_t::immediate:
90 ss << "$" << m.register1;
91 break;
92 case address_mode_t::none:
93 ss << "_";
94 break;
95 case address_mode_t::offset_double_indirect_mp:
96 ss << m.register2 << "(" << m.register1 << "(mp))";
97 break;
98 case address_mode_t::offset_double_indirect_fp:
99 ss << m.register2 << "(" << m.register1 << "(fp))";
100 break;
101
102 case address_mode_t::reserved_1:
103 case address_mode_t::reserved_2:
104 default:
105 ss << "??";
106 }
107
108 return ss;
109 }
110
111 std::ostream& operator<<(std::ostream &ss, const middle_data_t &m)
112 {
113 switch (m.mode)
114 {
115 case address_mode_middle_t::none:
116 ss << "_";
117 break;
118 case address_mode_middle_t::small_immediate:
119 ss << "$" << m.register1;
120 break;
121 case address_mode_middle_t::small_offset_indirect_fp:
122 ss << m.register1 << "(fp)";
123 break;
124 case address_mode_middle_t::small_offset_indirect_mp:
125 ss << m.register1 << "(mp)";
126 break;
127 default:
128 ss << "??";
129 }
130
131 return ss;
132 }
133
134 std::ostream& operator<<(std::ostream &ss, const vm_exec_op_t &m)
135 {
136 const auto print_d = m.destination.mode != address_mode_t::none;
137 const auto print_m = print_d || m.middle.mode != address_mode_middle_t::none;
138 const auto print_s = print_m || m.source.mode != address_mode_t::none;
139
140 ss << assembly::opcode_to_token(m.opcode);
141
142 if (print_s)
143 ss << " " << m.source;
144
145 if (print_m)
146 ss << " " << m.middle;
147
148 if (print_d)
149 ss << " " << m.destination;
150
151 return ss;
152 }
153
154 std::string to_string_frame_pointers(vm_registers_t &r)93 std::string to_string_frame_pointers(vm_registers_t &r)
155 {94 {
156 auto frame = r.stack.peek_frame();95 auto frame = r.stack.peek_frame();
@@ -178,20 +117,6 @@ namespace · 21 unmodified lines
178 return frame_string.str();117 return frame_string.str();
179 }118 }
180 119
181 std::string to_string_registers(const vm_registers_t &r)
182 {
183 auto register_string = std::stringstream{};
184
185 register_string
186 << "Registers:\n"
187 << " Thread ID: " << r.thread.get_thread_id() << "\n"
188 << " Module: " << r.module_ref->module->module_name->str() << "\n"
189 << "Program counter: " << r.pc << "\n"
190 << " Opcode: " << r.module_ref->code_section[r.pc].op << "\n";
191
192 return register_string.str();
193 }
194
195 namespace console_modifiers120 namespace console_modifiers
196 {121 {
197#define CSI "\33["122#define CSI "\33["
@@ -276,22 +201,13 @@ R"(Help: · 78 unmodified lines
276 auto c = std::toupper(cmd[0], loc);201 auto c = std::toupper(cmd[0], loc);
277 if (c == 'R')202 if (c == 'R')
278 {203 {
279 auto r_str = to_string_registers(r);204 auto str = registers_to_string(r);
280 debug_print_info(r_str);205 debug_print_info(str);
281 }206 }
282 else if (c == 'W')207 else if (c == 'W')
283 {208 {
284 auto msg = std::stringstream{};209 auto str = stack_to_string(r);
285 walk_stack(r, [&msg](const pointer_t, const vm_pc_t pc, const vm_module_ref_t &module_ref) {210 debug_print_info(str);
286 auto module_name = "<No Name>";
287 if (module_ref.module->module_name != nullptr)
288 module_name = module_ref.module->module_name->str();
289
290 msg << "\t" << module_name << "@" << pc << "\n";
291 return true;
292 });
293
294 debug_print_info(msg.str());
295 }211 }
296 else if (c == 'C')212 else if (c == 'C')
297 {213 {