2019-10-18 09:05:08 -04:00
|
|
|
#include "master.h"
|
2004-12-28 00:04:20 -05:00
|
|
|
|
2019-10-18 09:05:04 -04:00
|
|
|
void print_word(F_WORD* word, CELL nesting)
|
2004-12-28 00:04:20 -05:00
|
|
|
{
|
2005-08-29 02:34:04 -04:00
|
|
|
if(type_of(word->name) == STRING_TYPE)
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("%s",to_char_string(untag_string(word->name),true));
|
2004-12-28 00:04:20 -05:00
|
|
|
else
|
|
|
|
|
{
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("#<not a string: ");
|
2019-10-18 09:05:04 -04:00
|
|
|
print_nested_obj(word->name,nesting - 1);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(">");
|
2004-12-28 00:04:20 -05:00
|
|
|
}
|
|
|
|
|
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" (#%ld)",untag_fixnum_fast(word->primitive));
|
2004-12-28 00:04:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void print_string(F_STRING* str)
|
|
|
|
|
{
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("\"%s\"",to_char_string(str,true));
|
2004-12-28 00:04:20 -05:00
|
|
|
}
|
|
|
|
|
|
2019-10-18 09:05:04 -04:00
|
|
|
void print_array(F_ARRAY* array, CELL nesting)
|
2004-12-28 00:04:20 -05:00
|
|
|
{
|
2006-05-16 16:50:51 -04:00
|
|
|
CELL length = array_capacity(array);
|
|
|
|
|
CELL i;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < length; i++)
|
|
|
|
|
{
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" ");
|
2019-10-18 09:05:04 -04:00
|
|
|
print_nested_obj(get(AREF(array,i)),nesting - 1);
|
2006-05-16 16:50:51 -04:00
|
|
|
}
|
|
|
|
|
}
|
2005-07-24 22:44:33 -04:00
|
|
|
|
2019-10-18 09:05:04 -04:00
|
|
|
void print_nested_obj(CELL obj, CELL nesting)
|
2006-05-16 16:50:51 -04:00
|
|
|
{
|
2019-10-18 09:05:04 -04:00
|
|
|
if(nesting == 0)
|
|
|
|
|
{
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" ... ");
|
2019-10-18 09:05:04 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-28 00:04:20 -05:00
|
|
|
switch(type_of(obj))
|
|
|
|
|
{
|
2005-01-30 15:57:25 -05:00
|
|
|
case FIXNUM_TYPE:
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("%ld",untag_fixnum_fast(obj));
|
2005-01-30 15:57:25 -05:00
|
|
|
break;
|
2004-12-28 00:04:20 -05:00
|
|
|
case WORD_TYPE:
|
2019-10-18 09:05:04 -04:00
|
|
|
print_word(untag_word(obj),nesting - 1);
|
2004-12-28 00:04:20 -05:00
|
|
|
break;
|
|
|
|
|
case STRING_TYPE:
|
|
|
|
|
print_string(untag_string(obj));
|
|
|
|
|
break;
|
|
|
|
|
case F_TYPE:
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("f");
|
2004-12-28 00:04:20 -05:00
|
|
|
break;
|
2005-07-24 22:44:33 -04:00
|
|
|
case TUPLE_TYPE:
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("T{");
|
2019-10-18 09:05:04 -04:00
|
|
|
print_array((F_ARRAY*)UNTAG(obj),nesting - 1);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" }");
|
2006-05-16 16:50:51 -04:00
|
|
|
break;
|
|
|
|
|
case ARRAY_TYPE:
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("{");
|
2019-10-18 09:05:04 -04:00
|
|
|
print_array((F_ARRAY*)UNTAG(obj),nesting - 1);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" }");
|
2006-05-16 16:50:51 -04:00
|
|
|
break;
|
|
|
|
|
case QUOTATION_TYPE:
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("[");
|
2019-10-18 09:05:04 -04:00
|
|
|
print_array((F_ARRAY*)UNTAG(obj),nesting - 1);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" ]");
|
2005-07-24 22:44:33 -04:00
|
|
|
break;
|
2004-12-28 00:04:20 -05:00
|
|
|
default:
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("#<type %ld @ %lx>",type_of(obj),obj);
|
2004-12-28 00:04:20 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 09:05:04 -04:00
|
|
|
void print_obj(CELL obj)
|
|
|
|
|
{
|
|
|
|
|
print_nested_obj(obj,10);
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-12 01:02:39 -04:00
|
|
|
void print_objects(CELL start, CELL end)
|
2004-12-28 00:04:20 -05:00
|
|
|
{
|
2005-05-12 01:02:39 -04:00
|
|
|
for(; start <= end; start += CELLS)
|
2004-12-28 00:04:20 -05:00
|
|
|
{
|
2005-05-12 01:02:39 -04:00
|
|
|
print_obj(get(start));
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("\n");
|
2004-12-28 00:04:20 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 09:05:06 -04:00
|
|
|
void print_callstack(void)
|
|
|
|
|
{
|
|
|
|
|
F_INTERP_FRAME *frame;
|
|
|
|
|
for(frame = cs_bot; frame < cs; frame++)
|
|
|
|
|
{
|
|
|
|
|
print_obj(frame->quot);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("\n");
|
2019-10-18 09:05:06 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-12 01:02:39 -04:00
|
|
|
void dump_cell(CELL cell)
|
2004-12-28 00:04:20 -05:00
|
|
|
{
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("%08lx: ",cell);
|
2005-05-12 01:02:39 -04:00
|
|
|
|
|
|
|
|
cell = get(cell);
|
|
|
|
|
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("%08lx tag %ld",cell,TAG(cell));
|
2005-05-12 01:02:39 -04:00
|
|
|
|
|
|
|
|
switch(TAG(cell))
|
|
|
|
|
{
|
|
|
|
|
case OBJECT_TYPE:
|
|
|
|
|
case BIGNUM_TYPE:
|
|
|
|
|
case FLOAT_TYPE:
|
|
|
|
|
if(cell == F)
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" -- F");
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(cell < TYPE_COUNT<<TAG_BITS)
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" -- header: %ld",cell>>TAG_BITS);
|
2019-10-18 09:05:06 -04:00
|
|
|
else if(cell >= data_heap->segment->start
|
|
|
|
|
&& cell < data_heap->segment->end)
|
2005-05-12 01:02:39 -04:00
|
|
|
{
|
|
|
|
|
CELL header = get(UNTAG(cell));
|
|
|
|
|
CELL type = header>>TAG_BITS;
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" -- object; ");
|
2005-05-12 01:02:39 -04:00
|
|
|
if(TAG(header) == OBJECT_TYPE && type < TYPE_COUNT)
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" type %ld",type);
|
2005-05-12 01:02:39 -04:00
|
|
|
else
|
2019-10-18 09:05:11 -04:00
|
|
|
printf(" header corrupt");
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dump_memory(CELL from, CELL to)
|
|
|
|
|
{
|
2005-07-24 22:44:33 -04:00
|
|
|
from = UNTAG(from);
|
|
|
|
|
|
2005-05-12 01:02:39 -04:00
|
|
|
for(; from <= to; from += CELLS)
|
|
|
|
|
dump_cell(from);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 09:05:11 -04:00
|
|
|
void dump_zone(F_ZONE z)
|
2005-05-12 01:02:39 -04:00
|
|
|
{
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("start=%lx, size=%lx, end=%lx, here=%lx\n",
|
|
|
|
|
z.start,z.size,z.end,z.here - z.start);
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dump_generations(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2019-10-18 09:05:06 -04:00
|
|
|
for(i = 0; i < data_heap->gen_count; i++)
|
2005-05-12 01:02:39 -04:00
|
|
|
{
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("Generation %d: ",i);
|
|
|
|
|
dump_zone(data_heap->generations[i]);
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-18 09:05:11 -04:00
|
|
|
for(i = 0; i < data_heap->gen_count; i++)
|
|
|
|
|
{
|
|
|
|
|
printf("Semispace %d: ",i);
|
|
|
|
|
dump_zone(data_heap->semispaces[i]);
|
|
|
|
|
}
|
2005-05-12 01:02:39 -04:00
|
|
|
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("Cards: base=%lx, size=%lx\n",
|
2019-10-18 09:05:06 -04:00
|
|
|
(CELL)data_heap->cards,
|
|
|
|
|
(CELL)(data_heap->cards_end - data_heap->cards));
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void factorbug(void)
|
|
|
|
|
{
|
2006-07-07 00:07:18 -04:00
|
|
|
reset_stdio();
|
2005-05-14 00:23:00 -04:00
|
|
|
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("Starting low level debugger...\n");
|
|
|
|
|
printf(" Basic commands:\n");
|
|
|
|
|
printf("q -- continue executing Factor - NOT SAFE\n");
|
|
|
|
|
printf("im -- save image to fep.image\n");
|
|
|
|
|
printf("x -- exit Factor\n");
|
|
|
|
|
printf(" Advanced commands:\n");
|
|
|
|
|
printf("d <addr> <count> -- dump memory\n");
|
|
|
|
|
printf("u <addr> -- dump object at tagged <addr>\n");
|
|
|
|
|
printf(". <addr> -- print object at tagged <addr>\n");
|
|
|
|
|
printf("s r -- dump data, retain stacks\n");
|
|
|
|
|
printf(".s .r .c -- print data, retain, call stacks\n");
|
|
|
|
|
printf("i -- dump interpreter state\n");
|
|
|
|
|
printf("e -- dump environment\n");
|
|
|
|
|
printf("g -- dump generations\n");
|
|
|
|
|
printf("card <addr> -- print card containing address\n");
|
|
|
|
|
printf("addr <card> -- print address containing card\n");
|
|
|
|
|
printf("code -- code heap dump\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
char cmd[1024];
|
|
|
|
|
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("READY\n");
|
|
|
|
|
fflush(stdout);
|
2005-05-12 01:02:39 -04:00
|
|
|
|
2005-09-20 20:18:01 -04:00
|
|
|
if(scanf("%1000s",cmd) <= 0)
|
2005-05-12 01:02:39 -04:00
|
|
|
exit(1);
|
|
|
|
|
|
|
|
|
|
if(strcmp(cmd,"d") == 0)
|
|
|
|
|
{
|
|
|
|
|
CELL addr, count;
|
|
|
|
|
scanf("%lx %lx",&addr,&count);
|
|
|
|
|
dump_memory(addr,addr+count);
|
|
|
|
|
}
|
2005-09-20 20:18:01 -04:00
|
|
|
if(strcmp(cmd,"u") == 0)
|
2005-05-12 01:02:39 -04:00
|
|
|
{
|
2005-09-20 20:18:01 -04:00
|
|
|
CELL addr, count;
|
2005-05-12 01:02:39 -04:00
|
|
|
scanf("%lx",&addr);
|
2005-09-20 20:18:01 -04:00
|
|
|
count = object_size(addr);
|
|
|
|
|
dump_memory(addr,addr+count);
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
2005-09-20 20:18:01 -04:00
|
|
|
else if(strcmp(cmd,".") == 0)
|
2005-05-12 01:02:39 -04:00
|
|
|
{
|
|
|
|
|
CELL addr;
|
|
|
|
|
scanf("%lx",&addr);
|
2005-09-20 20:18:01 -04:00
|
|
|
print_obj(addr);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
else if(strcmp(cmd,"s") == 0)
|
2005-10-11 21:46:14 -04:00
|
|
|
dump_memory(ds_bot,ds);
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(strcmp(cmd,"r") == 0)
|
2006-05-14 23:09:47 -04:00
|
|
|
dump_memory(rs_bot,rs);
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(strcmp(cmd,".s") == 0)
|
2005-10-11 21:46:14 -04:00
|
|
|
print_objects(ds_bot,ds);
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(strcmp(cmd,".r") == 0)
|
2006-05-14 23:09:47 -04:00
|
|
|
print_objects(rs_bot,rs);
|
|
|
|
|
else if(strcmp(cmd,".c") == 0)
|
2019-10-18 09:05:06 -04:00
|
|
|
print_callstack();
|
2005-05-12 01:02:39 -04:00
|
|
|
else if(strcmp(cmd,"i") == 0)
|
|
|
|
|
{
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("Call frame:\n");
|
2019-10-18 09:05:06 -04:00
|
|
|
print_obj(callframe.quot);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
else if(strcmp(cmd,"e") == 0)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for(i = 0; i < USER_ENV; i++)
|
2005-10-11 21:46:14 -04:00
|
|
|
dump_cell((CELL)&userenv[i]);
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
else if(strcmp(cmd,"g") == 0)
|
|
|
|
|
dump_generations();
|
|
|
|
|
else if(strcmp(cmd,"card") == 0)
|
|
|
|
|
{
|
|
|
|
|
CELL addr;
|
|
|
|
|
scanf("%lx",&addr);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("%lx\n",(CELL)ADDR_TO_CARD(addr));
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
|
|
|
|
else if(strcmp(cmd,"addr") == 0)
|
|
|
|
|
{
|
|
|
|
|
CELL card;
|
|
|
|
|
scanf("%lx",&card);
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("%lx\n",(CELL)CARD_TO_ADDR(card));
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
2005-09-20 20:18:01 -04:00
|
|
|
else if(strcmp(cmd,"q") == 0)
|
2005-05-12 01:02:39 -04:00
|
|
|
return;
|
2005-09-20 20:18:01 -04:00
|
|
|
else if(strcmp(cmd,"x") == 0)
|
|
|
|
|
exit(1);
|
2005-06-12 20:55:30 -04:00
|
|
|
else if(strcmp(cmd,"im") == 0)
|
2019-10-18 09:05:08 -04:00
|
|
|
save_image(STR_FORMAT("fep.image"));
|
2006-09-27 20:53:54 -04:00
|
|
|
else if(strcmp(cmd,"code") == 0)
|
2019-10-18 09:05:06 -04:00
|
|
|
dump_heap(&code_heap);
|
2005-05-12 01:02:39 -04:00
|
|
|
else
|
2019-10-18 09:05:11 -04:00
|
|
|
printf("unknown command\n");
|
2005-05-12 01:02:39 -04:00
|
|
|
}
|
2004-12-28 00:04:20 -05:00
|
|
|
}
|