Verified Commit c79aeef0 authored by Camil Staps's avatar Camil Staps 🚀

Several fixes to display thunks and static nodes correctly in the debugger

parent 6e2653e0
......@@ -133,16 +133,22 @@ struct host_symbol *add_extra_host_symbol(struct program *pgm) {
}
# endif
int print_plain_label(char *s, size_t size, BC_WORD *label,
int print_address(char *s, size_t size, BC_WORD *addr,
struct program *pgm, BC_WORD *heap, size_t heap_size) {
if (pgm->code <= label && label < pgm->code + pgm->code_size)
return snprintf(s, size, "<%d>", (int) (label - pgm->code));
else if (pgm->data <= label && label < pgm->data + pgm->data_size)
return snprintf(s, size, "[%d]", (int) (label - pgm->data));
else if (heap != NULL && heap <= label && label < heap + heap_size)
return snprintf(s, size, "{%d}", (int) (label - heap));
if (pgm->code <= addr && addr < pgm->code + pgm->code_size)
return snprintf(s, size, "<%d>", (int) (addr - pgm->code));
else if (pgm->data <= addr && addr < pgm->data + pgm->data_size)
return snprintf(s, size, "[%d]", (int) (addr - pgm->data));
else if (heap != NULL && heap <= addr && addr < heap + heap_size)
return snprintf(s, size, "{%d}", (int) (addr - heap));
else if (small_integers <= addr && addr < small_integers+sizeof(small_integers))
return snprintf(s, size, BC_WORD_S_FMT, addr[1]);
else if (static_characters <= addr && addr < static_characters+sizeof(static_characters))
return snprintf(s, size, "'%s'", escape(addr[1]));
else if (static_booleans <= addr && addr < static_booleans+sizeof(static_booleans))
return snprintf(s, size, "%s", addr[1] ? "True" : "False");
else
return snprintf(s, size, "0x" BC_WORD_FMT_HEX, (BC_WORD) label);
return snprintf(s, size, "0x" BC_WORD_FMT_HEX, (BC_WORD) addr);
}
int print_label_name(char *s, size_t size, char *label) {
......@@ -250,7 +256,7 @@ init_symbols_matching(struct program *pgm) {
# endif
}
int print_label(char *s, size_t size, int include_plain_address, BC_WORD *label,
int print_label(char *s, size_t size, int include_address, BC_WORD *label,
struct program *pgm, BC_WORD *heap, size_t heap_size) {
if (((BC_WORD)label&-4) == (BC_WORD)&INT)
return snprintf(s, size, "INT");
......@@ -267,11 +273,11 @@ int print_label(char *s, size_t size, int include_plain_address, BC_WORD *label,
else if (&Fjmp_ap[0] <= label && label <= &Fjmp_ap[31])
return snprintf(s, size, "{jmp_ap %d}", (int)(label-Fjmp_ap)+1);
else if (heap != NULL && heap <= label && label < heap + heap_size)
return print_plain_label(s, size, label, pgm, heap, heap_size);
return print_address(s, size, label, pgm, heap, heap_size);
int used = 0;
if (include_plain_address) {
used = print_plain_label(s, size, label, pgm, heap, heap_size);
if (include_address) {
used = print_address(s, size, label, pgm, heap, heap_size);
if (used >= size - 1)
return used;
s[used++] = ' ';
......
......@@ -102,7 +102,9 @@ void sort_host_symbols_by_location(struct program *pgm);
struct host_symbol *add_extra_host_symbol(struct program *pgm);
# endif
int print_label(char *s, size_t size, int include_plain_address, BC_WORD *label,
int print_address(char *s, size_t size, BC_WORD *addr,
struct program *pgm, BC_WORD *heap, size_t heap_size);
int print_label(char *s, size_t size, int include_address, BC_WORD *label,
struct program *pgm, BC_WORD *heap, size_t heap_size);
# ifdef DEBUG_CURSES
# include <curses.h>
......
......@@ -304,7 +304,7 @@ void wprint_node(WINDOW *win, BC_WORD *node, int with_arguments) {
b_arity = ((int16_t*)(node[0]))[-1] - 256 - a_arity;
}
} else {
int16_t arity = ((int16_t*)(node[0]))[-1];
int16_t arity = ((int32_t*)(node[0]))[-1];
if (arity < 0) {
a_arity = 1;
b_arity = 0;
......@@ -341,7 +341,7 @@ void wprint_node(WINDOW *win, BC_WORD *node, int with_arguments) {
/* TODO: unboxed values */
print_label(_tmp, 256, 0, (BC_WORD*) node[1], program, hp, heap_size);
print_address(_tmp, 256, (BC_WORD*) node[1], program, hp, heap_size);
wprintw(win, " %s", _tmp);
if (a_arity <= 1)
return;
......@@ -522,7 +522,7 @@ void debugger_show_node_as_tree_(WINDOW *win, BC_WORD *node, int indent, uint64_
b_arity = ((int16_t*)(node[0]))[-1] - 256 - a_arity;
}
} else {
int16_t arity = ((int16_t*)(node[0]))[-1];
int16_t arity = ((int32_t*)(node[0]))[-1];
if (arity < 0) {
a_arity = 1;
b_arity = 0;
......
......@@ -68,9 +68,9 @@ extern void* BOOL[];
extern void* CHAR[];
extern void* REAL[];
extern BC_WORD small_integers[];
extern BC_WORD static_characters[];
extern BC_WORD static_booleans[];
extern BC_WORD small_integers[66];
extern BC_WORD static_characters[512];
extern BC_WORD static_booleans[4];
#ifdef LINK_CLEAN_RUNTIME
#include "copy_interpreter_to_host.h"
......
......@@ -168,13 +168,23 @@ size_t string_to_size(char *size) {
}
}
static char hex_digits[]="0123456789abcdef";
char *escape(char c) {
static char s[2];
static char s[4];
if (c<' ') {
s[0]='\\';
s[1]='x';
s[2]=hex_digits[c>>4];
s[3]=hex_digits[c&0xf];
}
switch (c) {
case '\n': return "\\n";
case '\r': return "\\r";
case '\t': return "\\t";
case '\\': return "\\\\";
case '\'': return "'";
case '"': return "\\\"";
default:
s[0] = c;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment