| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | #include "master.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | static bool fep_disabled; | 
					
						
							|  |  |  | static bool full_output; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_chars(string* str) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell i; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	for(i = 0; i < string_capacity(str); i++) | 
					
						
							|  |  |  | 		putchar(string_nth(str,i)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_word(word* word, cell nesting) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	if(tagged<object>(word->vocabulary).type_p(STRING_TYPE)) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		print_chars(untag<string>(word->vocabulary)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		print_string(":"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	if(tagged<object>(word->name).type_p(STRING_TYPE)) | 
					
						
							|  |  |  | 		print_chars(untag<string>(word->name)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		print_string("#<not a string: "); | 
					
						
							|  |  |  | 		print_nested_obj(word->name,nesting); | 
					
						
							|  |  |  | 		print_string(">"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_factor_string(string* str) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	putchar('"'); | 
					
						
							|  |  |  | 	print_chars(str); | 
					
						
							|  |  |  | 	putchar('"'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_array(array* array, cell nesting) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell length = array_capacity(array); | 
					
						
							|  |  |  | 	cell i; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	bool trimmed; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(length > 10 && !full_output) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		trimmed = true; | 
					
						
							|  |  |  | 		length = 10; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		trimmed = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(i = 0; i < length; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		print_string(" "); | 
					
						
							|  |  |  | 		print_nested_obj(array_nth(array,i),nesting); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(trimmed) | 
					
						
							|  |  |  | 		print_string("..."); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_tuple(tuple *tuple, cell nesting) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	tuple_layout *layout = untag<tuple_layout>(tuple->layout); | 
					
						
							|  |  |  | 	cell length = to_fixnum(layout->size); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	print_string(" "); | 
					
						
							|  |  |  | 	print_nested_obj(layout->klass,nesting); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell i; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	bool trimmed; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(length > 10 && !full_output) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		trimmed = true; | 
					
						
							|  |  |  | 		length = 10; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		trimmed = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(i = 0; i < length; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		print_string(" "); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		print_nested_obj(tuple->data()[i],nesting); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(trimmed) | 
					
						
							|  |  |  | 		print_string("..."); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_nested_obj(cell obj, fixnum nesting) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	if(nesting <= 0 && !full_output) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		print_string(" ... "); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	quotation *quot; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	switch(tagged<object>(obj).type()) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 	case FIXNUM_TYPE: | 
					
						
							| 
									
										
										
										
											2009-05-02 21:47:29 -04:00
										 |  |  | 		print_fixnum(untag_fixnum(obj)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case WORD_TYPE: | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		print_word(untag<word>(obj),nesting - 1); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case STRING_TYPE: | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		print_factor_string(untag<string>(obj)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case F_TYPE: | 
					
						
							|  |  |  | 		print_string("f"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case TUPLE_TYPE: | 
					
						
							|  |  |  | 		print_string("T{"); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		print_tuple(untag<tuple>(obj),nesting - 1); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		print_string(" }"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ARRAY_TYPE: | 
					
						
							|  |  |  | 		print_string("{"); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		print_array(untag<array>(obj),nesting - 1); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		print_string(" }"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case QUOTATION_TYPE: | 
					
						
							|  |  |  | 		print_string("["); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		quot = untag<quotation>(obj); | 
					
						
							|  |  |  | 		print_array(untag<array>(quot->array),nesting - 1); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		print_string(" ]"); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 		print_string("#<type "); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		print_cell(tagged<object>(obj).type()); | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 		print_string(" @ "); | 
					
						
							|  |  |  | 		print_cell_hex(obj); | 
					
						
							|  |  |  | 		print_string(">"); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_obj(cell obj) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	print_nested_obj(obj,10); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_objects(cell *start, cell *end) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 	for(; start <= end; start++) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | 		print_obj(*start); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		nl(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | void print_datastack() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	print_string("==== DATA STACK:\n"); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	print_objects((cell *)ds_bot,(cell *)ds); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | void print_retainstack() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	print_string("==== RETAIN STACK:\n"); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	print_objects((cell *)rs_bot,(cell *)rs); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void print_stack_frame(stack_frame *frame) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	print_obj(frame_executing(frame)); | 
					
						
							|  |  |  | 	print_string("\n"); | 
					
						
							|  |  |  | 	print_obj(frame_scan(frame)); | 
					
						
							|  |  |  | 	print_string("\n"); | 
					
						
							| 
									
										
										
										
											2009-07-29 20:28:58 -04:00
										 |  |  | 	print_string("word/quot addr: "); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	print_cell_hex((cell)frame_executing(frame)); | 
					
						
							| 
									
										
										
										
											2009-07-29 20:28:58 -04:00
										 |  |  | 	print_string("\n"); | 
					
						
							|  |  |  | 	print_string("word/quot xt: "); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	print_cell_hex((cell)frame->xt); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	print_string("\n"); | 
					
						
							| 
									
										
										
										
											2009-07-29 20:28:58 -04:00
										 |  |  | 	print_string("return address: "); | 
					
						
							|  |  |  | 	print_cell_hex((cell)FRAME_RETURN_ADDRESS(frame)); | 
					
						
							|  |  |  | 	print_string("\n"); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | void print_callstack() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	print_string("==== CALL STACK:\n"); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell bottom = (cell)stack_chain->callstack_bottom; | 
					
						
							|  |  |  | 	cell top = (cell)stack_chain->callstack_top; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	iterate_callstack(top,bottom,print_stack_frame); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void dump_cell(cell x) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	print_cell_hex_pad(x); print_string(": "); | 
					
						
							|  |  |  | 	x = *(cell *)x; | 
					
						
							|  |  |  | 	print_cell_hex_pad(x); print_string(" tag "); print_cell(TAG(x)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	nl(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void dump_memory(cell from, cell to) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	from = UNTAG(from); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	for(; from <= to; from += sizeof(cell)) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		dump_cell(from); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void dump_zone(zone *z) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	print_string("Start="); print_cell(z->start); | 
					
						
							|  |  |  | 	print_string(", size="); print_cell(z->size); | 
					
						
							|  |  |  | 	print_string(", here="); print_cell(z->here - z->start); nl(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | void dump_generations() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell i; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	print_string("Nursery: "); | 
					
						
							|  |  |  | 	dump_zone(&nursery); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	for(i = 1; i < data->gen_count; i++) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		print_string("Generation "); print_cell(i); print_string(": "); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		dump_zone(&data->generations[i]); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	for(i = 0; i < data->gen_count; i++) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		print_string("Semispace "); print_cell(i); print_string(": "); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		dump_zone(&data->semispaces[i]); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	print_string("Cards: base="); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	print_cell((cell)data->cards); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	print_string(", size="); | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	print_cell((cell)(data->cards_end - data->cards)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	nl(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void dump_objects(cell type) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	gc(); | 
					
						
							|  |  |  | 	begin_scan(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell obj; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	while((obj = next_object()) != F) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		if(type == TYPE_COUNT || tagged<object>(obj).type_p(type)) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			print_cell_hex_pad(obj); | 
					
						
							|  |  |  | 			print_string(" "); | 
					
						
							|  |  |  | 			print_nested_obj(obj,2); | 
					
						
							|  |  |  | 			nl(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-13 01:58:54 -04:00
										 |  |  | 	end_scan(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | cell look_for; | 
					
						
							|  |  |  | cell obj; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void find_data_references_step(cell *scan) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	if(look_for == *scan) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		print_cell_hex_pad(obj); | 
					
						
							|  |  |  | 		print_string(" "); | 
					
						
							|  |  |  | 		print_nested_obj(obj,2); | 
					
						
							|  |  |  | 		nl(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | void find_data_references(cell look_for_) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	look_for = look_for_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	begin_scan(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while((obj = next_object()) != F) | 
					
						
							|  |  |  | 		do_slots(UNTAG(obj),find_data_references_step); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-13 01:58:54 -04:00
										 |  |  | 	end_scan(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Dump all code blocks for debugging */ | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | void dump_code_heap() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	cell reloc_size = 0, literal_size = 0; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 	heap_block *scan = first_block(&code); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while(scan) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-05-04 08:00:06 -04:00
										 |  |  | 		const char *status; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		switch(scan->status) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		case B_FREE: | 
					
						
							|  |  |  | 			status = "free"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case B_ALLOCATED: | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			reloc_size += object_size(((code_block *)scan)->relocation); | 
					
						
							|  |  |  | 			literal_size += object_size(((code_block *)scan)->literals); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			status = "allocated"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case B_MARKED: | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			reloc_size += object_size(((code_block *)scan)->relocation); | 
					
						
							|  |  |  | 			literal_size += object_size(((code_block *)scan)->literals); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			status = "marked"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			status = "invalid"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		print_cell_hex((cell)scan); print_string(" "); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		print_cell_hex(scan->size); print_string(" "); | 
					
						
							|  |  |  | 		print_string(status); print_string("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 		scan = next_block(&code,scan); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	print_cell(reloc_size); print_string(" bytes of relocation data\n"); | 
					
						
							|  |  |  | 	print_cell(literal_size); print_string(" bytes of literal data\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-05 12:33:35 -04:00
										 |  |  | void factorbug() | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	if(fep_disabled) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		print_string("Low level debugger disabled\n"); | 
					
						
							|  |  |  | 		exit(1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* open_console(); */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	print_string("Starting low level debugger...\n"); | 
					
						
							|  |  |  | 	print_string("  Basic commands:\n"); | 
					
						
							|  |  |  | 	print_string("q                -- continue executing Factor - NOT SAFE\n"); | 
					
						
							|  |  |  | 	print_string("im               -- save image to fep.image\n"); | 
					
						
							|  |  |  | 	print_string("x                -- exit Factor\n"); | 
					
						
							|  |  |  | 	print_string("  Advanced commands:\n"); | 
					
						
							|  |  |  | 	print_string("d <addr> <count> -- dump memory\n"); | 
					
						
							|  |  |  | 	print_string("u <addr>         -- dump object at tagged <addr>\n"); | 
					
						
							|  |  |  | 	print_string(". <addr>         -- print object at tagged <addr>\n"); | 
					
						
							|  |  |  | 	print_string("t                -- toggle output trimming\n"); | 
					
						
							|  |  |  | 	print_string("s r              -- dump data, retain stacks\n"); | 
					
						
							|  |  |  | 	print_string(".s .r .c         -- print data, retain, call stacks\n"); | 
					
						
							|  |  |  | 	print_string("e                -- dump environment\n"); | 
					
						
							|  |  |  | 	print_string("g                -- dump generations\n"); | 
					
						
							|  |  |  | 	print_string("card <addr>      -- print card containing address\n"); | 
					
						
							|  |  |  | 	print_string("addr <card>      -- print address containing card\n"); | 
					
						
							|  |  |  | 	print_string("data             -- data heap dump\n"); | 
					
						
							|  |  |  | 	print_string("words            -- words dump\n"); | 
					
						
							|  |  |  | 	print_string("tuples           -- tuples dump\n"); | 
					
						
							|  |  |  | 	print_string("refs <addr>      -- find data heap references to object\n"); | 
					
						
							|  |  |  | 	print_string("push <addr>      -- push object on data stack - NOT SAFE\n"); | 
					
						
							|  |  |  | 	print_string("code             -- code heap dump\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool seen_command = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(;;) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		char cmd[1024]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		print_string("READY\n"); | 
					
						
							|  |  |  | 		fflush(stdout); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(scanf("%1000s",cmd) <= 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if(!seen_command) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				/* If we exit with an EOF immediately, then
 | 
					
						
							|  |  |  | 				dump stacks. This is useful for builder and | 
					
						
							|  |  |  | 				other cases where Factor is run with stdin | 
					
						
							|  |  |  | 				redirected to /dev/null */ | 
					
						
							|  |  |  | 				fep_disabled = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				print_datastack(); | 
					
						
							|  |  |  | 				print_retainstack(); | 
					
						
							|  |  |  | 				print_callstack(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			exit(1); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		seen_command = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(strcmp(cmd,"d") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			cell addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			if(scanf(" ") < 0) break; | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			cell count = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			dump_memory(addr,addr+count); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"u") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			cell addr = read_cell_hex(); | 
					
						
							|  |  |  | 			cell count = object_size(addr); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			dump_memory(addr,addr+count); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,".") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			cell addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			print_obj(addr); | 
					
						
							|  |  |  | 			print_string("\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"t") == 0) | 
					
						
							|  |  |  | 			full_output = !full_output; | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"s") == 0) | 
					
						
							|  |  |  | 			dump_memory(ds_bot,ds); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"r") == 0) | 
					
						
							|  |  |  | 			dump_memory(rs_bot,rs); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,".s") == 0) | 
					
						
							|  |  |  | 			print_datastack(); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,".r") == 0) | 
					
						
							|  |  |  | 			print_retainstack(); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,".c") == 0) | 
					
						
							|  |  |  | 			print_callstack(); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"e") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			int i; | 
					
						
							|  |  |  | 			for(i = 0; i < USER_ENV; i++) | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 				dump_cell((cell)&userenv[i]); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"g") == 0) | 
					
						
							|  |  |  | 			dump_generations(); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"card") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			cell addr = read_cell_hex(); | 
					
						
							|  |  |  | 			print_cell_hex((cell)addr_to_card(addr)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			nl(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"addr") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			card *ptr = (card *)read_cell_hex(); | 
					
						
							|  |  |  | 			print_cell_hex(card_to_addr(ptr)); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			nl(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"q") == 0) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"x") == 0) | 
					
						
							|  |  |  | 			exit(1); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"im") == 0) | 
					
						
							|  |  |  | 			save_image(STRING_LITERAL("fep.image")); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"data") == 0) | 
					
						
							|  |  |  | 			dump_objects(TYPE_COUNT); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"refs") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			cell addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			print_string("Data heap references:\n"); | 
					
						
							|  |  |  | 			find_data_references(addr); | 
					
						
							|  |  |  | 			nl(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"words") == 0) | 
					
						
							|  |  |  | 			dump_objects(WORD_TYPE); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"tuples") == 0) | 
					
						
							|  |  |  | 			dump_objects(TUPLE_TYPE); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"push") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | 			cell addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 			dpush(addr); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"code") == 0) | 
					
						
							|  |  |  | 			dump_code_heap(); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			print_string("unknown command\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:00:30 -04:00
										 |  |  | PRIMITIVE(die) | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | { | 
					
						
							|  |  |  | 	print_string("The die word was called by the library. Unless you called it yourself,\n"); | 
					
						
							|  |  |  | 	print_string("you have triggered a bug in Factor. Please report.\n"); | 
					
						
							|  |  |  | 	factorbug(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |