| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | #include "master.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-05 23:20:29 -05:00
										 |  |  | static bool full_output; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | void print_chars(F_STRING* str) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CELL i; | 
					
						
							|  |  |  | 	for(i = 0; i < string_capacity(str); i++) | 
					
						
							| 
									
										
										
										
											2008-01-31 21:11:46 -05:00
										 |  |  | 		putchar(string_nth(str,i)); | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | void print_word(F_WORD* word, CELL nesting) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(type_of(word->vocabulary) == STRING_TYPE) | 
					
						
							| 
									
										
										
										
											2007-09-26 00:26:19 -04:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 		print_chars(untag_string(word->vocabulary)); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string(":"); | 
					
						
							| 
									
										
										
										
											2007-09-26 00:26:19 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if(type_of(word->name) == STRING_TYPE) | 
					
						
							|  |  |  | 		print_chars(untag_string(word->name)); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("#<not a string: "); | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 		print_nested_obj(word->name,nesting); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string(">"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | void print_factor_string(F_STRING* str) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-26 00:26:19 -04:00
										 |  |  | 	putchar('"'); | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 	print_chars(str); | 
					
						
							| 
									
										
										
										
											2007-09-26 00:26:19 -04:00
										 |  |  | 	putchar('"'); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void print_array(F_ARRAY* array, CELL nesting) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CELL length = array_capacity(array); | 
					
						
							|  |  |  | 	CELL i; | 
					
						
							| 
									
										
										
										
											2008-02-21 18:07:05 -05:00
										 |  |  | 	bool trimmed; | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-05 23:20:29 -05:00
										 |  |  | 	if(length > 10 && !full_output) | 
					
						
							| 
									
										
										
										
											2008-02-21 18:07:05 -05:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		trimmed = true; | 
					
						
							| 
									
										
										
										
											2008-02-09 03:19:26 -05:00
										 |  |  | 		length = 10; | 
					
						
							| 
									
										
										
										
											2008-02-21 18:07:05 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		trimmed = false; | 
					
						
							| 
									
										
										
										
											2008-02-09 03:19:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	for(i = 0; i < length; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string(" "); | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 		print_nested_obj(array_nth(array,i),nesting); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-02-21 18:07:05 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(trimmed) | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("..."); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-26 04:57:48 -04:00
										 |  |  | void print_tuple(F_TUPLE* tuple, CELL nesting) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	F_TUPLE_LAYOUT *layout = untag_object(tuple->layout); | 
					
						
							|  |  |  | 	CELL length = to_fixnum(layout->size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_string(" "); | 
					
						
							| 
									
										
										
										
											2008-03-26 04:57:48 -04:00
										 |  |  | 	print_nested_obj(layout->class,nesting); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CELL i; | 
					
						
							|  |  |  | 	bool trimmed; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-05 23:20:29 -05:00
										 |  |  | 	if(length > 10 && !full_output) | 
					
						
							| 
									
										
										
										
											2008-03-26 04:57:48 -04:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		trimmed = true; | 
					
						
							|  |  |  | 		length = 10; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		trimmed = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(i = 0; i < length; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string(" "); | 
					
						
							| 
									
										
										
										
											2008-03-26 04:57:48 -04:00
										 |  |  | 		print_nested_obj(tuple_nth(tuple,i),nesting); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(trimmed) | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("..."); | 
					
						
							| 
									
										
										
										
											2008-03-26 04:57:48 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | void print_nested_obj(CELL obj, F_FIXNUM nesting) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-05 23:20:29 -05:00
										 |  |  | 	if(nesting <= 0 && !full_output) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string(" ... "); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	F_QUOTATION *quot; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch(type_of(obj)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case FIXNUM_TYPE: | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_fixnum(untag_fixnum_fast(obj)); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case WORD_TYPE: | 
					
						
							|  |  |  | 		print_word(untag_word(obj),nesting - 1); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case STRING_TYPE: | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_factor_string(untag_string(obj)); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case F_TYPE: | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("f"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case TUPLE_TYPE: | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("T{"); | 
					
						
							| 
									
										
										
										
											2008-03-26 04:57:48 -04:00
										 |  |  | 		print_tuple(untag_object(obj),nesting - 1); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string(" }"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case ARRAY_TYPE: | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("{"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		print_array(untag_object(obj),nesting - 1); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string(" }"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case QUOTATION_TYPE: | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("["); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		quot = untag_object(obj); | 
					
						
							|  |  |  | 		print_array(untag_object(quot->array),nesting - 1); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string(" ]"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2008-11-28 01:48:20 -05:00
										 |  |  | 		print_string("#<type "); print_cell(type_of(obj)); print_string(" @ "); print_cell_hex(obj); print_string(">"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void print_obj(CELL obj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	print_nested_obj(obj,10); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void print_objects(CELL start, CELL end) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for(; start <= end; start += CELLS) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		print_obj(get(start)); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		nl(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | void print_datastack(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_string("==== DATA STACK:\n"); | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | 	print_objects(ds_bot,ds); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void print_retainstack(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_string("==== RETAIN STACK:\n"); | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | 	print_objects(rs_bot,rs); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | void print_stack_frame(F_STACK_FRAME *frame) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	print_obj(frame_executing(frame)); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_string("\n"); | 
					
						
							| 
									
										
										
										
											2007-10-06 20:58:33 -04:00
										 |  |  | 	print_obj(frame_scan(frame)); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_string("\n"); | 
					
						
							|  |  |  | 	print_cell_hex((CELL)frame_executing(frame)); | 
					
						
							| 
									
										
										
										
											2008-11-22 20:57:06 -05:00
										 |  |  | 	print_string(" "); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_cell_hex((CELL)frame->xt); | 
					
						
							| 
									
										
										
										
											2008-11-22 20:57:06 -05:00
										 |  |  | 	print_string("\n"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void print_callstack(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_string("==== CALL STACK:\n"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	CELL bottom = (CELL)stack_chain->callstack_bottom; | 
					
						
							|  |  |  | 	CELL top = (CELL)stack_chain->callstack_top; | 
					
						
							| 
									
										
										
										
											2007-10-05 17:30:10 -04:00
										 |  |  | 	iterate_callstack(top,bottom,print_stack_frame); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dump_cell(CELL cell) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_cell_hex_pad(cell); print_string(": "); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cell = get(cell); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_cell_hex_pad(cell); print_string(" tag "); print_cell(TAG(cell)); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch(TAG(cell)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case OBJECT_TYPE: | 
					
						
							|  |  |  | 	case BIGNUM_TYPE: | 
					
						
							|  |  |  | 	case FLOAT_TYPE: | 
					
						
							|  |  |  | 		if(cell == F) | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			print_string(" -- F"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		else if(cell < TYPE_COUNT<<TAG_BITS) | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			print_string(" -- possible header: "); | 
					
						
							|  |  |  | 			print_cell(cell>>TAG_BITS); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		else if(cell >= data_heap->segment->start | 
					
						
							|  |  |  | 			&& cell < data_heap->segment->end) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			CELL header = get(UNTAG(cell)); | 
					
						
							|  |  |  | 			CELL type = header>>TAG_BITS; | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			print_string(" -- object; "); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 			if(TAG(header) == 0 && type < TYPE_COUNT) | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				print_string(" type "); print_cell(type); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 				print_string(" header corrupt"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	nl(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dump_memory(CELL from, CELL to) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	from = UNTAG(from); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(; from <= to; from += CELLS) | 
					
						
							|  |  |  | 		dump_cell(from); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-04 22:44:39 -04:00
										 |  |  | void dump_zone(F_ZONE *z) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05: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(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dump_generations(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	CELL i; | 
					
						
							| 
									
										
										
										
											2008-04-19 05:52:34 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_string("Nursery: "); | 
					
						
							| 
									
										
										
										
											2008-04-19 05:52:34 -04:00
										 |  |  | 	dump_zone(&nursery); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for(i = 1; i < data_heap->gen_count; i++) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("Generation "); print_cell(i); print_string(": "); | 
					
						
							| 
									
										
										
										
											2008-04-04 22:44:39 -04:00
										 |  |  | 		dump_zone(&data_heap->generations[i]); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(i = 0; i < data_heap->gen_count; i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("Semispace "); print_cell(i); print_string(": "); | 
					
						
							| 
									
										
										
										
											2008-04-04 22:44:39 -04:00
										 |  |  | 		dump_zone(&data_heap->semispaces[i]); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	print_string("Cards: base="); | 
					
						
							|  |  |  | 	print_cell((CELL)data_heap->cards); | 
					
						
							|  |  |  | 	print_string(", size="); | 
					
						
							|  |  |  | 	print_cell((CELL)(data_heap->cards_end - data_heap->cards)); | 
					
						
							|  |  |  | 	nl(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | void dump_objects(F_FIXNUM type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-04-05 05:01:46 -04:00
										 |  |  | 	gc(); | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 	begin_scan(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CELL obj; | 
					
						
							|  |  |  | 	while((obj = next_object()) != F) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if(type == -1 || type_of(obj) == type) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			print_cell_hex_pad(obj); | 
					
						
							|  |  |  | 			print_string(" "); | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 			print_nested_obj(obj,2); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			nl(); | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* end scan */ | 
					
						
							|  |  |  | 	gc_off = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-11 01:41:58 -05:00
										 |  |  | CELL look_for; | 
					
						
							|  |  |  | CELL obj; | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-11 01:41:58 -05:00
										 |  |  | void find_data_references_step(CELL *scan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(look_for == *scan) | 
					
						
							| 
									
										
										
										
											2008-02-09 03:19:26 -05:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_cell_hex_pad(obj); | 
					
						
							|  |  |  | 		print_string(" "); | 
					
						
							| 
									
										
										
										
											2008-02-11 01:41:58 -05:00
										 |  |  | 		print_nested_obj(obj,2); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		nl(); | 
					
						
							| 
									
										
										
										
											2008-02-09 03:19:26 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-02-11 01:41:58 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void find_data_references(CELL look_for_) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	look_for = look_for_; | 
					
						
							| 
									
										
										
										
											2008-02-09 03:19:26 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	begin_scan(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 	while((obj = next_object()) != F) | 
					
						
							| 
									
										
										
										
											2008-02-11 01:41:58 -05:00
										 |  |  | 		do_slots(UNTAG(obj),find_data_references_step); | 
					
						
							| 
									
										
										
										
											2008-02-09 03:19:26 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* end scan */ | 
					
						
							|  |  |  | 	gc_off = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-24 21:13:17 -05:00
										 |  |  | /* Dump all code blocks for debugging */ | 
					
						
							|  |  |  | void dump_code_heap(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CELL size = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	F_BLOCK *scan = first_block(&code_heap); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(scan) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		char *status; | 
					
						
							|  |  |  | 		switch(scan->status) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		case B_FREE: | 
					
						
							|  |  |  | 			status = "free"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case B_ALLOCATED: | 
					
						
							|  |  |  | 			size += object_size(block_to_compiled(scan)->relocation); | 
					
						
							|  |  |  | 			status = "allocated"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case B_MARKED: | 
					
						
							|  |  |  | 			size += object_size(block_to_compiled(scan)->relocation); | 
					
						
							|  |  |  | 			status = "marked"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			status = "invalid"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		print_cell_hex((CELL)scan); print_string(" "); | 
					
						
							|  |  |  | 		print_cell_hex(scan->size); print_string(" "); | 
					
						
							|  |  |  | 		print_string(status); print_string("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		scan = next_block(&code_heap,scan); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	print_cell(size); print_string(" bytes of relocation data\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | void factorbug(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-10-09 01:13:04 -04:00
										 |  |  | 	if(fep_disabled) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("Low level debugger disabled\n"); | 
					
						
							| 
									
										
										
										
											2008-10-09 01:13:04 -04:00
										 |  |  | 		exit(1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 	/* 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"); | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | 	bool seen_command = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	for(;;) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		char cmd[1024]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		print_string("READY\n"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		fflush(stdout); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(scanf("%1000s",cmd) <= 0) | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			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 */ | 
					
						
							| 
									
										
										
										
											2008-10-09 01:13:04 -04:00
										 |  |  | 				fep_disabled = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | 				print_datastack(); | 
					
						
							|  |  |  | 				print_retainstack(); | 
					
						
							|  |  |  | 				print_callstack(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 			exit(1); | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		seen_command = true; | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(strcmp(cmd,"d") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			CELL addr = read_cell_hex(); | 
					
						
							|  |  |  | 			scanf(" "); | 
					
						
							|  |  |  | 			CELL count = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 			dump_memory(addr,addr+count); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 		else if(strcmp(cmd,"u") == 0) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			CELL addr = read_cell_hex(); | 
					
						
							|  |  |  | 			CELL count = object_size(addr); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 			dump_memory(addr,addr+count); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,".") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			CELL addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 			print_obj(addr); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			print_string("\n"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-11-05 23:20:29 -05:00
										 |  |  | 		else if(strcmp(cmd,"t") == 0) | 
					
						
							|  |  |  | 			full_output = !full_output; | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		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) | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | 			print_datastack(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		else if(strcmp(cmd,".r") == 0) | 
					
						
							| 
									
										
										
										
											2008-04-04 10:17:26 -04:00
										 |  |  | 			print_retainstack(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		else if(strcmp(cmd,".c") == 0) | 
					
						
							|  |  |  | 			print_callstack(); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"e") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			int i; | 
					
						
							|  |  |  | 			for(i = 0; i < USER_ENV; i++) | 
					
						
							|  |  |  | 				dump_cell((CELL)&userenv[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"g") == 0) | 
					
						
							|  |  |  | 			dump_generations(); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"card") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			CELL addr = read_cell_hex(); | 
					
						
							|  |  |  | 			print_cell_hex((CELL)ADDR_TO_CARD(addr)); | 
					
						
							|  |  |  | 			nl(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"addr") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			CELL card = read_cell_hex(); | 
					
						
							|  |  |  | 			print_cell_hex((CELL)CARD_TO_ADDR(card)); | 
					
						
							|  |  |  | 			nl(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"q") == 0) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"x") == 0) | 
					
						
							|  |  |  | 			exit(1); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"im") == 0) | 
					
						
							| 
									
										
										
										
											2009-01-14 19:40:23 -05:00
										 |  |  | 			save_image(STRING_LITERAL("fep.image")); | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 		else if(strcmp(cmd,"data") == 0) | 
					
						
							|  |  |  | 			dump_objects(-1); | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 		else if(strcmp(cmd,"refs") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			CELL addr = read_cell_hex(); | 
					
						
							|  |  |  | 			print_string("Data heap references:\n"); | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 			find_data_references(addr); | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			nl(); | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-10-09 02:08:20 -04:00
										 |  |  | 		else if(strcmp(cmd,"words") == 0) | 
					
						
							|  |  |  | 			dump_objects(WORD_TYPE); | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 		else if(strcmp(cmd,"tuples") == 0) | 
					
						
							|  |  |  | 			dump_objects(TUPLE_TYPE); | 
					
						
							|  |  |  | 		else if(strcmp(cmd,"push") == 0) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			CELL addr = read_cell_hex(); | 
					
						
							| 
									
										
										
										
											2008-02-10 02:40:51 -05:00
										 |  |  | 			dpush(addr); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		else if(strcmp(cmd,"code") == 0) | 
					
						
							| 
									
										
										
										
											2009-01-24 21:13:17 -05:00
										 |  |  | 			dump_code_heap(); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05:00
										 |  |  | 			print_string("unknown command\n"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-13 04:20:34 -05:00
										 |  |  | void primitive_die(void) | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-18 19:21:42 -05: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"); | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 	factorbug(); | 
					
						
							|  |  |  | } |