added the ability to inspect the stack from the debugger
This commit is contained in:
+42
-1
@@ -267,7 +267,8 @@ _Bool Debug_Callback(Runtime *runtime, void *userp)
|
||||
"step .............. Run an instruction\n"
|
||||
"quit .............. Stop execution\n"
|
||||
"continue .......... Run until a breakpoint or the end of the code is reached\n"
|
||||
"breakpoint ........ Add a breakpoint\n");
|
||||
"breakpoint ........ Add a breakpoint\n"
|
||||
"stack ............. Show the contents of the stack\n");
|
||||
}
|
||||
else if(!strcmp(argv[1], "help"))
|
||||
{
|
||||
@@ -339,6 +340,17 @@ _Bool Debug_Callback(Runtime *runtime, void *userp)
|
||||
" | a line number, a character offset or an instruction index.\n"
|
||||
"\n");
|
||||
}
|
||||
else if(!strcmp(argv[1], "stack"))
|
||||
{
|
||||
fprintf(stderr,
|
||||
"\n"
|
||||
" Command | stack\n"
|
||||
" | \n"
|
||||
" Usage | > stack\n"
|
||||
" | \n"
|
||||
" Description | Show the contents of the stack.\n"
|
||||
"\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stdout, "Unknown command \"%s\".\n", argv[1]);
|
||||
@@ -436,6 +448,35 @@ _Bool Debug_Callback(Runtime *runtime, void *userp)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if(!strcmp(argv[0], "stack"))
|
||||
{
|
||||
Stack *stack = Runtime_GetStack(runtime);
|
||||
assert(stack != NULL);
|
||||
|
||||
Error error;
|
||||
Error_Init(&error);
|
||||
|
||||
if(Stack_Size(stack) == 0)
|
||||
fprintf(stderr, "The stack is empty.\n");
|
||||
|
||||
for(int i = 0; i < (int) Stack_Size(stack); i += 1)
|
||||
{
|
||||
Object *obj = Stack_Top(stack, -i);
|
||||
assert(obj != NULL);
|
||||
|
||||
fprintf(stderr, " %d | ", i);
|
||||
Object_Print(obj, stderr, &error);
|
||||
|
||||
if(error.occurred)
|
||||
{
|
||||
Error_Free(&error);
|
||||
Error_Init(&error);
|
||||
fprintf(stderr, "(unprintable)");
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
else if(!strcmp(argv[0], "quit"))
|
||||
{
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user