6 void fatal_error(const char *msg, cell tagged)
8 std::cout << "fatal_error: " << msg;
9 std::cout << ": " << std::hex << tagged << std::dec;
10 std::cout << std::endl;
14 void critical_error(const char *msg, cell tagged)
16 std::cout << "You have triggered a bug in Factor. Please report.\n";
17 std::cout << "critical_error: " << msg;
18 std::cout << ": " << std::hex << tagged << std::dec;
19 std::cout << std::endl;
20 current_vm()->factorbug();
25 std::cout << "Out of memory\n\n";
26 current_vm()->dump_generations();
30 void factor_vm::general_error(vm_error_type error, cell arg1, cell arg2)
32 /* Reset local roots before allocating anything */
37 /* If we had an underflow or overflow, data or retain stack
38 pointers might be out of bounds, so fix them before allocating
42 /* If error was thrown during heap scan, we re-enable the GC */
45 /* If the error handler is set, we rewind any C stack frames and
46 pass the error to user-space. */
47 if(!current_gc && to_boolean(special_objects[ERROR_HANDLER_QUOT]))
50 /* Doing a GC here triggers all kinds of funny errors */
51 primitive_compact_gc();
54 /* Now its safe to allocate and GC */
55 cell error_object = allot_array_4(special_objects[OBJ_ERROR],
56 tag_fixnum(error),arg1,arg2);
58 ctx->push(error_object);
60 unwind_native_frames(special_objects[ERROR_HANDLER_QUOT],
63 /* Error was thrown in early startup before error handler is set, just
67 std::cout << "You have triggered a bug in Factor. Please report.\n";
68 std::cout << "error: " << error << std::endl;
69 std::cout << "arg 1: "; print_obj(arg1); std::cout << std::endl;
70 std::cout << "arg 2: "; print_obj(arg2); std::cout << std::endl;
75 void factor_vm::type_error(cell type, cell tagged)
77 general_error(ERROR_TYPE,tag_fixnum(type),tagged);
80 void factor_vm::not_implemented_error()
82 general_error(ERROR_NOT_IMPLEMENTED,false_object,false_object);
85 void factor_vm::memory_protection_error(cell addr)
87 if(code->safepoint_p(addr))
89 else if(ctx->datastack_seg->underflow_p(addr))
90 general_error(ERROR_DATASTACK_UNDERFLOW,false_object,false_object);
91 else if(ctx->datastack_seg->overflow_p(addr))
92 general_error(ERROR_DATASTACK_OVERFLOW,false_object,false_object);
93 else if(ctx->retainstack_seg->underflow_p(addr))
94 general_error(ERROR_RETAINSTACK_UNDERFLOW,false_object,false_object);
95 else if(ctx->retainstack_seg->overflow_p(addr))
96 general_error(ERROR_RETAINSTACK_OVERFLOW,false_object,false_object);
97 else if(ctx->callstack_seg->underflow_p(addr))
98 general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object);
99 else if(ctx->callstack_seg->overflow_p(addr))
100 general_error(ERROR_CALLSTACK_UNDERFLOW,false_object,false_object);
102 general_error(ERROR_MEMORY,from_unsigned_cell(addr),false_object);
105 void factor_vm::signal_error(cell signal)
107 general_error(ERROR_SIGNAL,from_unsigned_cell(signal),false_object);
110 void factor_vm::divide_by_zero_error()
112 general_error(ERROR_DIVIDE_BY_ZERO,false_object,false_object);
115 void factor_vm::fp_trap_error(unsigned int fpu_status)
117 general_error(ERROR_FP_TRAP,tag_fixnum(fpu_status),false_object);
120 /* For testing purposes */
121 void factor_vm::primitive_unimplemented()
123 not_implemented_error();
126 void factor_vm::memory_signal_handler_impl()
128 memory_protection_error(signal_fault_addr);
129 if (!signal_resumable)
131 /* In theory we should only get here if the callstack overflowed during a
133 general_error(ERROR_CALLSTACK_OVERFLOW,false_object,false_object);
137 void memory_signal_handler_impl()
139 current_vm()->memory_signal_handler_impl();
142 void factor_vm::synchronous_signal_handler_impl()
144 signal_error(signal_number);
147 void synchronous_signal_handler_impl()
149 current_vm()->synchronous_signal_handler_impl();
152 void factor_vm::fp_signal_handler_impl()
154 /* Clear pending exceptions to avoid getting stuck in a loop */
155 set_fpu_state(get_fpu_state());
157 fp_trap_error(signal_fpu_status);
160 void fp_signal_handler_impl()
162 current_vm()->fp_signal_handler_impl();
165 void factor_vm::enqueue_safepoint_fep()
168 fatal_error("Low-level debugger interrupted", 0);
169 safepoint_fep = true;
170 code->guard_safepoint();
173 void factor_vm::handle_safepoint()
175 code->unguard_safepoint();
178 if (sampling_profiler_p)
179 end_sampling_profiler();
180 std::cout << "Interrupted\n";
182 safepoint_fep = false;
184 else if (sampling_profiler_p)