mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-09-22 23:18:01 +03:00
Merge pull request #284 from kichikuou/debugger
debugger: Display values of reference variables
This commit is contained in:
@@ -94,6 +94,7 @@ void dbg_print_vm_state(void);
|
|||||||
void dbg_print_current_line(void);
|
void dbg_print_current_line(void);
|
||||||
union vm_value dbg_eval_string(const char *str, struct ain_type *type_out);
|
union vm_value dbg_eval_string(const char *str, struct ain_type *type_out);
|
||||||
struct string *dbg_value_to_string(struct ain_type *type, union vm_value value, int recursive);
|
struct string *dbg_value_to_string(struct ain_type *type, union vm_value value, int recursive);
|
||||||
|
struct string *dbg_variable_to_string(struct ain_type *type, struct page *page, int slot, int recursive);
|
||||||
|
|
||||||
void dbg_dap_init(void);
|
void dbg_dap_init(void);
|
||||||
void dbg_dap_quit(void);
|
void dbg_dap_quit(void);
|
||||||
|
|||||||
+33
-1
@@ -764,6 +764,8 @@ static void dbg_indent(struct string **s, int indent_level)
|
|||||||
}
|
}
|
||||||
static struct string *_dbg_value_to_string(struct ain_type *type, union vm_value value,
|
static struct string *_dbg_value_to_string(struct ain_type *type, union vm_value value,
|
||||||
int recursive, int indent);
|
int recursive, int indent);
|
||||||
|
static struct string *_dbg_variable_to_string(
|
||||||
|
struct ain_type *type, struct page *page, int slot, int recursive, int indent);
|
||||||
|
|
||||||
static struct string *dbg_string_to_string(struct string *str)
|
static struct string *dbg_string_to_string(struct string *str)
|
||||||
{
|
{
|
||||||
@@ -788,10 +790,12 @@ static struct string *dbg_struct_to_string(struct ain_type *type, union vm_value
|
|||||||
struct string *out = cstr_to_string("{\n");
|
struct string *out = cstr_to_string("{\n");
|
||||||
for (int i = 0; i < page->nr_vars; i++) {
|
for (int i = 0; i < page->nr_vars; i++) {
|
||||||
struct ain_variable *m = &ain->structures[type->struc].members[i];
|
struct ain_variable *m = &ain->structures[type->struc].members[i];
|
||||||
|
if (m->type.data == AIN_VOID)
|
||||||
|
continue;
|
||||||
dbg_indent(&out, indent + 1);
|
dbg_indent(&out, indent + 1);
|
||||||
string_append_cstr(&out, m->name, strlen(m->name));
|
string_append_cstr(&out, m->name, strlen(m->name));
|
||||||
string_append_cstr(&out, " = ", 3);
|
string_append_cstr(&out, " = ", 3);
|
||||||
struct string *tmp = _dbg_value_to_string(&m->type, page->values[i],
|
struct string *tmp = _dbg_variable_to_string(&m->type, page, i,
|
||||||
recursive - 1, indent + 1);
|
recursive - 1, indent + 1);
|
||||||
string_append(&out, tmp);
|
string_append(&out, tmp);
|
||||||
free_string(tmp);
|
free_string(tmp);
|
||||||
@@ -871,6 +875,34 @@ struct string *dbg_value_to_string(struct ain_type *type, union vm_value value,
|
|||||||
return _dbg_value_to_string(type, value, recursive, 0);
|
return _dbg_value_to_string(type, value, recursive, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct string *_dbg_variable_to_string(
|
||||||
|
struct ain_type *type, struct page *page, int slot, int recursive, int indent)
|
||||||
|
{
|
||||||
|
enum ain_data_type value_type;
|
||||||
|
switch (type->data) {
|
||||||
|
case AIN_REF_INT: value_type = AIN_INT; break;
|
||||||
|
case AIN_REF_LONG_INT: value_type = AIN_LONG_INT; break;
|
||||||
|
case AIN_REF_BOOL: value_type = AIN_BOOL; break;
|
||||||
|
case AIN_REF_FLOAT: value_type = AIN_FLOAT; break;
|
||||||
|
default:
|
||||||
|
return _dbg_value_to_string(type, page->values[slot], recursive, indent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get referenced value
|
||||||
|
int pageno = page->values[slot].i;
|
||||||
|
int varno = page->values[slot + 1].i;
|
||||||
|
if (pageno < 0) {
|
||||||
|
return cstr_to_string("NULL");
|
||||||
|
}
|
||||||
|
struct ain_type t = {.data = value_type};
|
||||||
|
return _dbg_value_to_string(&t, heap[pageno].page->values[varno], recursive, indent);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct string *dbg_variable_to_string(struct ain_type *type, struct page *page, int slot, int recursive)
|
||||||
|
{
|
||||||
|
return _dbg_variable_to_string(type, page, slot, recursive, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// the maximum number of instructions preceeding the instruction pointer to be displayed
|
// the maximum number of instructions preceeding the instruction pointer to be displayed
|
||||||
#define DASM_REWIND 16
|
#define DASM_REWIND 16
|
||||||
// the number of instructions following the instruction pointer to be displayed
|
// the number of instructions following the instruction pointer to be displayed
|
||||||
|
|||||||
+9
-3
@@ -126,7 +126,9 @@ static void dbg_cmd_locals(unsigned nr_args, char **args)
|
|||||||
struct page *page = heap_get_page(call_stack[call_stack_ptr - (frame_no+1)].page_slot);
|
struct page *page = heap_get_page(call_stack[call_stack_ptr - (frame_no+1)].page_slot);
|
||||||
struct ain_function *f = &ain->functions[page->index];
|
struct ain_function *f = &ain->functions[page->index];
|
||||||
for (int i = 0; i < f->nr_vars; i++) {
|
for (int i = 0; i < f->nr_vars; i++) {
|
||||||
struct string *value = dbg_value_to_string(&f->vars[i].type, page->values[i], 1);
|
if (f->vars[i].type.data == AIN_VOID)
|
||||||
|
continue;
|
||||||
|
struct string *value = dbg_variable_to_string(&f->vars[i].type, page, i, 1);
|
||||||
printf("[%d] %s: %s\n", i, display_sjis0(f->vars[i].name), display_sjis1(value->text));
|
printf("[%d] %s: %s\n", i, display_sjis0(f->vars[i].name), display_sjis1(value->text));
|
||||||
free_string(value);
|
free_string(value);
|
||||||
}
|
}
|
||||||
@@ -138,7 +140,9 @@ static void log_handler(struct breakpoint *bp)
|
|||||||
struct page *locals = local_page();
|
struct page *locals = local_page();
|
||||||
printf("%s(", display_sjis0(f->name));
|
printf("%s(", display_sjis0(f->name));
|
||||||
for (int i = 0; i < f->nr_args; i++) {
|
for (int i = 0; i < f->nr_args; i++) {
|
||||||
struct string *value = dbg_value_to_string(&f->vars[i].type, locals->values[i], 1);
|
if (f->vars[i].type.data == AIN_VOID)
|
||||||
|
continue;
|
||||||
|
struct string *value = dbg_variable_to_string(&f->vars[i].type, locals, i, 1);
|
||||||
printf(i > 0 ? ", %s" : "%s", display_sjis0(value->text));
|
printf(i > 0 ? ", %s" : "%s", display_sjis0(value->text));
|
||||||
free_string(value);
|
free_string(value);
|
||||||
}
|
}
|
||||||
@@ -175,7 +179,9 @@ static void dbg_cmd_members(unsigned nr_args, char **args)
|
|||||||
assert(page->nr_vars == s->nr_members);
|
assert(page->nr_vars == s->nr_members);
|
||||||
|
|
||||||
for (int i = 0; i < s->nr_members; i++) {
|
for (int i = 0; i < s->nr_members; i++) {
|
||||||
struct string *value = dbg_value_to_string(&s->members[i].type, page->values[i], 1);
|
if (s->members[i].type.data == AIN_VOID)
|
||||||
|
continue;
|
||||||
|
struct string *value = dbg_variable_to_string(&s->members[i].type, page, i, 1);
|
||||||
printf("[%d] %s: %s\n", i, display_sjis0(s->members[i].name), display_sjis1(value->text));
|
printf("[%d] %s: %s\n", i, display_sjis0(s->members[i].name), display_sjis1(value->text));
|
||||||
free_string(value);
|
free_string(value);
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-11
@@ -325,32 +325,34 @@ static int make_var_ref(struct ain_type *type, union vm_value value)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cJSON *value_to_json(const char *name, struct ain_type *type, union vm_value value)
|
static cJSON *value_to_json(const char *name, struct ain_type *type, struct page *page, int slot)
|
||||||
{
|
{
|
||||||
char *s_type = ain_strtype_d(ain, type);
|
char *s_type = ain_strtype_d(ain, type);
|
||||||
struct string *s_val = dbg_value_to_string(type, value, 0);
|
struct string *s_val = dbg_variable_to_string(type, page, slot, 0);
|
||||||
|
|
||||||
cJSON *json = cJSON_CreateObject();
|
cJSON *json = cJSON_CreateObject();
|
||||||
json_add_sjis_to_object(json, "name", name);
|
json_add_sjis_to_object(json, "name", name);
|
||||||
json_add_sjis_to_object(json, "value", s_val->text);
|
json_add_sjis_to_object(json, "value", s_val->text);
|
||||||
json_add_sjis_to_object(json, "type", s_type);
|
json_add_sjis_to_object(json, "type", s_type);
|
||||||
cJSON_AddNumberToObject(json, "variablesReference", make_var_ref(type, value));
|
cJSON_AddNumberToObject(json, "variablesReference", make_var_ref(type, page->values[slot]));
|
||||||
|
|
||||||
free_string(s_val);
|
free_string(s_val);
|
||||||
free(s_type);
|
free(s_type);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cJSON *var_to_json(struct ain_variable *var, union vm_value value)
|
static void add_var_to_json_array(cJSON *array, struct ain_variable *var, struct page *page, int slot)
|
||||||
{
|
{
|
||||||
return value_to_json(var->name, &var->type, value);
|
if (var->type.data == AIN_VOID)
|
||||||
|
return;
|
||||||
|
cJSON_AddItemToArray(array, value_to_json(var->name, &var->type, page, slot));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_arguments_to_array(cJSON *array, struct page *page)
|
static void add_arguments_to_array(cJSON *array, struct page *page)
|
||||||
{
|
{
|
||||||
struct ain_function *f = &ain->functions[page->index];
|
struct ain_function *f = &ain->functions[page->index];
|
||||||
for (int i = 0; i < f->nr_args; i++) {
|
for (int i = 0; i < f->nr_args; i++) {
|
||||||
cJSON_AddItemToArray(array, var_to_json(&f->vars[i], page->values[i]));
|
add_var_to_json_array(array, &f->vars[i], page, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,7 +360,7 @@ static void add_locals_to_array(cJSON *array, struct page *page)
|
|||||||
{
|
{
|
||||||
struct ain_function *f = &ain->functions[page->index];
|
struct ain_function *f = &ain->functions[page->index];
|
||||||
for (int i = f->nr_args; i < f->nr_vars; i++) {
|
for (int i = f->nr_args; i < f->nr_vars; i++) {
|
||||||
cJSON_AddItemToArray(array, var_to_json(&f->vars[i], page->values[i]));
|
add_var_to_json_array(array, &f->vars[i], page, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +368,7 @@ static void add_variables_to_array(cJSON *array, struct page *page)
|
|||||||
{
|
{
|
||||||
struct ain_function *f = &ain->functions[page->index];
|
struct ain_function *f = &ain->functions[page->index];
|
||||||
for (int i = 0; i < f->nr_vars; i++) {
|
for (int i = 0; i < f->nr_vars; i++) {
|
||||||
cJSON_AddItemToArray(array, var_to_json(&f->vars[i], page->values[i]));
|
add_var_to_json_array(array, &f->vars[i], page, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,14 +376,14 @@ static void add_members_to_array(cJSON *array, struct page *page)
|
|||||||
{
|
{
|
||||||
struct ain_struct *s = &ain->structures[page->index];
|
struct ain_struct *s = &ain->structures[page->index];
|
||||||
for (int i = 0; i < s->nr_members; i++) {
|
for (int i = 0; i < s->nr_members; i++) {
|
||||||
cJSON_AddItemToArray(array, var_to_json(&s->members[i], page->values[i]));
|
add_var_to_json_array(array, &s->members[i], page, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_globals_to_array(cJSON *array, struct page *page)
|
static void add_globals_to_array(cJSON *array, struct page *page)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ain->nr_globals; i++) {
|
for (int i = 0; i < ain->nr_globals; i++) {
|
||||||
cJSON_AddItemToArray(array, var_to_json(&ain->globals[i], page->values[i]));
|
add_var_to_json_array(array, &ain->globals[i], page, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,7 +397,7 @@ static void add_array_elements_to_array(cJSON *array, struct page *page)
|
|||||||
snprintf(name, 512, "[%d]", i);
|
snprintf(name, 512, "[%d]", i);
|
||||||
struct ain_type type;
|
struct ain_type type;
|
||||||
type.data = variable_type(page, i, &type.struc, &type.rank);
|
type.data = variable_type(page, i, &type.struc, &type.rank);
|
||||||
cJSON_AddItemToArray(array, value_to_json(name, &type, page->values[i]));
|
cJSON_AddItemToArray(array, value_to_json(name, &type, page, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user