Smarter fep

db4
Slava Pestov 2008-04-04 09:17:26 -05:00
parent 67c509db73
commit 5b5aaa344a
1 changed files with 32 additions and 2 deletions

View File

@ -146,6 +146,18 @@ void print_objects(CELL start, CELL end)
} }
} }
void print_datastack(void)
{
printf("==== DATA STACK:\n");
print_objects(ds_bot,ds);
}
void print_retainstack(void)
{
printf("==== RETAIN STACK:\n");
print_objects(rs_bot,rs);
}
void print_stack_frame(F_STACK_FRAME *frame) void print_stack_frame(F_STACK_FRAME *frame)
{ {
print_obj(frame_executing(frame)); print_obj(frame_executing(frame));
@ -158,6 +170,7 @@ void print_stack_frame(F_STACK_FRAME *frame)
void print_callstack(void) void print_callstack(void)
{ {
printf("==== CALL STACK:\n");
CELL bottom = (CELL)stack_chain->callstack_bottom; CELL bottom = (CELL)stack_chain->callstack_bottom;
CELL top = (CELL)stack_chain->callstack_top; CELL top = (CELL)stack_chain->callstack_top;
iterate_callstack(top,bottom,print_stack_frame); iterate_callstack(top,bottom,print_stack_frame);
@ -336,6 +349,8 @@ void factorbug(void)
printf("push <addr> -- push object on data stack - NOT SAFE\n"); printf("push <addr> -- push object on data stack - NOT SAFE\n");
printf("code -- code heap dump\n"); printf("code -- code heap dump\n");
bool seen_command = false;
for(;;) for(;;)
{ {
char cmd[1024]; char cmd[1024];
@ -344,7 +359,22 @@ void factorbug(void)
fflush(stdout); fflush(stdout);
if(scanf("%1000s",cmd) <= 0) 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 */
print_datastack();
print_retainstack();
print_callstack();
}
exit(1); exit(1);
}
seen_command = true;
if(strcmp(cmd,"d") == 0) if(strcmp(cmd,"d") == 0)
{ {
@ -371,9 +401,9 @@ void factorbug(void)
else if(strcmp(cmd,"r") == 0) else if(strcmp(cmd,"r") == 0)
dump_memory(rs_bot,rs); dump_memory(rs_bot,rs);
else if(strcmp(cmd,".s") == 0) else if(strcmp(cmd,".s") == 0)
print_objects(ds_bot,ds); print_datastack();
else if(strcmp(cmd,".r") == 0) else if(strcmp(cmd,".r") == 0)
print_objects(rs_bot,rs); print_retainstack();
else if(strcmp(cmd,".c") == 0) else if(strcmp(cmd,".c") == 0)
print_callstack(); print_callstack();
else if(strcmp(cmd,"e") == 0) else if(strcmp(cmd,"e") == 0)