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
1919
2020 namespace
2121 {
22− std::string to_string_stack(vm_registers_t &r)
22+ std::string stack_to_string(const vm_registers_t &r)
2323 {
2424 auto msg = std::stringstream{};
2525 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
3535 return msg.str();
3636 }
3737
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+
3852 std::ostream& operator<<(std::ostream &ss, const vm_string_t *s)
3953 {
4054 ss << "string\n"
@@ -76,81 +90,6 @@ namespace · 35 unmodified lines
7690 return ss;
7791 }
7892
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−
15493 std::string to_string_frame_pointers(vm_registers_t &r)
15594 {
15695 auto frame = r.stack.peek_frame();
@@ -178,20 +117,6 @@ namespace · 21 unmodified lines
178117 return frame_string.str();
179118 }
180119
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−
195120 namespace console_modifiers
196121 {
197122 #define CSI "\33["
@@ -276,22 +201,13 @@ R"(Help: · 78 unmodified lines
276201 auto c = std::toupper(cmd[0], loc);
277202 if (c == 'R')
278203 {
279− auto r_str = to_string_registers(r);
280− debug_print_info(r_str);
204+ auto str = registers_to_string(r);
205+ debug_print_info(str);
281206 }
282207 else if (c == 'W')
283208 {
284− auto msg = std::stringstream{};
285− walk_stack(r, [&msg](const pointer_t, const vm_pc_t pc, const vm_module_ref_t &module_ref) {
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());
209+ auto str = stack_to_string(r);
210+ debug_print_info(str);
295211 }
296212 else if (c == 'C')
297213 {