Showing the changes to src/vm/thread.cpp (1 of 5 files). Show all
Unified · Split
| @@ -153,6 +153,27 @@ vm_registers_t::~vm_registers_t() · 152 unmodified lines | ||
| 153 | 153 | debug::assign_debug_pointer(&module_ref); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | +void disvm::runtime::walk_stack(const vm_registers_t &r, vm_stack_walk_callback_t callback) | |
| 157 | +{ | |
| 158 | + assert(callback != nullptr); | |
| 159 | + | |
| 160 | + auto current_pc = r.pc; | |
| 161 | + auto current_module = r.module_ref; | |
| 162 | + auto current_frame = r.stack.peek_frame(); | |
| 163 | + while (current_frame != nullptr) | |
| 164 | + { | |
| 165 | + if (!callback(current_frame->base(), current_pc, *current_module)) | |
| 166 | + break; | |
| 167 | + | |
| 168 | + current_pc = current_frame->prev_pc(); | |
| 169 | + auto prev_module_maybe = current_frame->prev_module_ref(); | |
| 170 | + if (prev_module_maybe != nullptr) | |
| 171 | + current_module = prev_module_maybe; | |
| 172 | + | |
| 173 | + current_frame = current_frame->prev_frame(); | |
| 174 | + } | |
| 175 | +} | |
| 176 | + | |
| 156 | 177 | std::shared_ptr<const type_descriptor_t> vm_thread_t::type_desc() |
| 157 | 178 | { |
| 158 | 179 | return intrinsic_type_desc::type<vm_thread_t>(); |
| @@ -252,17 +273,17 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t qua · 93 unmodified lines | ||
| 252 | 273 | catch (const unhandled_user_exception &uue) |
| 253 | 274 | { |
| 254 | 275 | // [TODO] Store the exception |
| 255 | − std::printf("%s - %s in %s at instruction %d\n", uue.what(), uue.exception_id, uue.module_name, uue.program_counter); | |
| 276 | + std::fprintf(stderr, "%s - %s in %s at instruction %d\n", uue.what(), uue.exception_id, uue.module_name, uue.program_counter); | |
| 256 | 277 | _registers.current_thread_state = vm_thread_state_t::broken; |
| 257 | 278 | } |
| 258 | 279 | catch (const index_out_of_range_memory &ioor) |
| 259 | 280 | { |
| 260 | − std::printf("%s - %d [%d,%d]\n", ioor.what(), ioor.invalid_value, ioor.valid_min, ioor.valid_max); | |
| 281 | + std::fprintf(stderr, "%s - %d [%d,%d]\n", ioor.what(), ioor.invalid_value, ioor.valid_min, ioor.valid_max); | |
| 261 | 282 | _registers.current_thread_state = vm_thread_state_t::broken; |
| 262 | 283 | } |
| 263 | 284 | catch (const vm_user_exception &ue) |
| 264 | 285 | { |
| 265 | − std::printf("%s\n", ue.what()); | |
| 286 | + std::fprintf(stderr, "%s\n", ue.what()); | |
| 266 | 287 | _registers.current_thread_state = vm_thread_state_t::broken; |
| 267 | 288 | } |
| 268 | 289 | |