From 1b42bcf12cea10d7d9b9b9c20c267e1053d96dd3 Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 20 Jun 2021 14:00:25 +0200 Subject: [PATCH 1/3] bdb : partially unbreak Todo's have been left off in the code. What doesn't work: - Loading external natives - Reading symbols (blocked by #99) --- bdb/src/bdb.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bdb/src/bdb.c b/bdb/src/bdb.c index ab0fece..bee4812 100644 --- a/bdb/src/bdb.c +++ b/bdb/src/bdb.c @@ -298,7 +298,6 @@ void bdb_print_location(Bdb_State *state) Bdb_Err bdb_reset(Bdb_State *state) { - // TODO(#276): bdb does not support native function loading bm_load_program_from_file(&state->bm, state->program_file_path); state->bm.halt = 1; @@ -307,10 +306,7 @@ Bdb_Err bdb_reset(Bdb_State *state) state->is_in_step_over_mode = 0; state->step_over_mode_call_depth = 0; - fprintf(stdout, "INFO : Loading debug symbols...\n"); - if (bdb_load_symtab(state, state->program_file_path) == BDB_FAIL) { - return BDB_FAIL; - } + fprintf(stdout, "TODO: BDB does not load symbols from a symbol table\n"); // Update addresses of breakpoints on labels for (size_t i = 0; i < state->breakpoints_size; ++i) { @@ -328,6 +324,16 @@ Bdb_Err bdb_reset(Bdb_State *state) } } + for (size_t i = 0; i < state->bm.externals_size; ++i) { + if (strcmp(state->bm.externals[i].name, "write") == 0) { + bm_push_native(&state->bm, native_write); + } else if (strcmp(state->bm.externals[i].name, "external") == 0) { + bm_push_native(&state->bm, native_external); + } else { + fprintf(stderr, "TODO(#276): bdb does not support native function loading\n"); + } + } + return BDB_OK; } @@ -432,6 +438,7 @@ Bdb_Err bdb_run_command(Bdb_State *state, String_View command_word, String_View if (bdb_parse_word(state, addr, &value) == BDB_FAIL) { fprintf(stderr, "ERR : `"SV_Fmt"` is not a number\n", SV_Arg(addr)); + break; } bdb_add_breakpoint(state, value.as_u64, SV_NULL); From d42db3205c2c00c6adb1abf3f2c38be5b74ae23e Mon Sep 17 00:00:00 2001 From: Nico Sonack Date: Sun, 20 Jun 2021 14:15:49 +0200 Subject: [PATCH 2/3] bdb : remove symtab code --- bdb/src/bdb.c | 33 --------------------------------- bdb/src/bdb.h | 1 - 2 files changed, 34 deletions(-) diff --git a/bdb/src/bdb.c b/bdb/src/bdb.c index bee4812..789775b 100644 --- a/bdb/src/bdb.c +++ b/bdb/src/bdb.c @@ -38,39 +38,6 @@ Bdb_Binding *bdb_resolve_binding(Bdb_State *bdb, String_View name) return NULL; } -Bdb_Err bdb_load_symtab(Bdb_State *state, const char *program_file_path) -{ - assert(state); - - String_View symtab_file = - sv_from_cstr(CSTR_CONCAT(&state->sym_arena, program_file_path, ".sym")); - - String_View symtab = {0}; - if (arena_slurp_file(&state->sym_arena, symtab_file, &symtab) < 0) { - fprintf(stderr, "ERROR: could not read file "SV_Fmt": %s\n", - SV_Arg(symtab_file), strerror(errno)); - exit(1); - } - - while (symtab.count > 0) { - symtab = sv_trim_left(symtab); - String_View raw_addr = sv_chop_by_delim(&symtab, '\t'); - symtab = sv_trim_left(symtab); - String_View raw_sym_type = sv_chop_by_delim(&symtab, '\t'); - symtab = sv_trim_left(symtab); - String_View name = sv_chop_by_delim(&symtab, '\n'); - Word value = word_u64(sv_to_u64(raw_addr)); - Type type = (Type)sv_to_u64(raw_sym_type); - - state->bindings[state->bindings_size].name = name; - state->bindings[state->bindings_size].value = value; - state->bindings[state->bindings_size].type = type; - state->bindings_size += 1; - } - - return BDB_OK; -} - // TODO(#187): bdb_print_instr should take information from the actual source code void bdb_print_instr(Bdb_State *state, FILE *f, Inst *i) { diff --git a/bdb/src/bdb.h b/bdb/src/bdb.h index 1fdbe7b..9897a76 100644 --- a/bdb/src/bdb.h +++ b/bdb/src/bdb.h @@ -63,7 +63,6 @@ typedef struct Bdb_State { } Bdb_State; Bdb_Err bdb_state_init(Bdb_State *, const char *program_file_path); -Bdb_Err bdb_load_symtab(Bdb_State *state, const char *program_file_path); Bdb_Err bdb_step_instr(Bdb_State *); Bdb_Err bdb_step_over_instr(Bdb_State *state); Bdb_Err bdb_continue(Bdb_State *); From 39bbf0ff336264089268e00f40cb8c40cd92f669 Mon Sep 17 00:00:00 2001 From: rexim Date: Mon, 21 Jun 2021 13:44:37 +0700 Subject: [PATCH 3/3] Add TODO(#467) --- bdb/src/bdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bdb/src/bdb.c b/bdb/src/bdb.c index 789775b..9fcd4f3 100644 --- a/bdb/src/bdb.c +++ b/bdb/src/bdb.c @@ -273,7 +273,7 @@ Bdb_Err bdb_reset(Bdb_State *state) state->is_in_step_over_mode = 0; state->step_over_mode_call_depth = 0; - fprintf(stdout, "TODO: BDB does not load symbols from a symbol table\n"); + fprintf(stdout, "TODO(#467): BDB does not load symbols from a symbol table\n"); // Update addresses of breakpoints on labels for (size_t i = 0; i < state->breakpoints_size; ++i) {