From: Brendan Hansen Date: Thu, 15 Dec 2022 03:21:37 +0000 (-0600) Subject: bugfix in debug info when passing structure by implicit pointer X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=bf58a904a9e439da36c04758c8d9daea57f4cc65;p=onyx.git bugfix in debug info when passing structure by implicit pointer --- diff --git a/compiler/src/wasm_output.h b/compiler/src/wasm_output.h index 4d1e4b20..c2557827 100644 --- a/compiler/src/wasm_output.h +++ b/compiler/src/wasm_output.h @@ -970,15 +970,19 @@ static i32 output_ovm_debug_sections(OnyxWasmModule* module, bh_buffer* buff) { continue; } - if (type->kind == Type_Kind_DynArray) { - output_unsigned_integer(7, §ion_buff); - output_unsigned_integer(type->DynArray.elem->id, §ion_buff); - continue; - } + // This would be nice if this would work... + // But it breaks when passing dynamic arrays as parameters. + // if (type->kind == Type_Kind_DynArray) { + // output_unsigned_integer(7, §ion_buff); + // output_unsigned_integer(type->DynArray.elem->id, §ion_buff); + // continue; + // } if (type_is_structlike_strict(type)) { output_unsigned_integer(3, §ion_buff); + output_unsigned_integer(type_structlike_is_simple(type), §ion_buff); + i32 mem_count = type_structlike_mem_count(type); output_unsigned_integer(mem_count, §ion_buff); diff --git a/interpreter/include/ovm_debug.h b/interpreter/include/ovm_debug.h index c09f0b4c..a6b53e9f 100644 --- a/interpreter/include/ovm_debug.h +++ b/interpreter/include/ovm_debug.h @@ -92,6 +92,7 @@ typedef struct debug_type_structure_member_t { } debug_type_structure_member_t; typedef struct debug_type_structure_t { + b32 simple; u32 member_count; debug_type_structure_member_t *members; } debug_type_structure_t; diff --git a/interpreter/src/debug/debug_info.c b/interpreter/src/debug/debug_info.c index 0be08ce4..99bc1f65 100644 --- a/interpreter/src/debug/debug_info.c +++ b/interpreter/src/debug/debug_info.c @@ -146,6 +146,8 @@ void debug_info_import_type_info(debug_info_t *info, u8 *data, u32 len) { break; case debug_type_kind_structure: + type.structure.simple = uleb128_to_uint(data, &offset); + type.structure.member_count = uleb128_to_uint(data, &offset); type.structure.members = bh_alloc_array(info->alloc, debug_type_structure_member_t, type.structure.member_count); diff --git a/interpreter/src/debug/debug_runtime_values.c b/interpreter/src/debug/debug_runtime_values.c index bc75fbd3..2e27764d 100644 --- a/interpreter/src/debug/debug_runtime_values.c +++ b/interpreter/src/debug/debug_runtime_values.c @@ -23,7 +23,7 @@ static bool lookup_register_in_frame(ovm_state_t *state, ovm_stack_frame_t *fram if (frame == &bh_arr_last(state->stack_frames)) { val_num_base = state->value_number_offset; } else { - val_num_base = (frame + 1)->value_number_base; + val_num_base = frame->value_number_base; } *out = state->numbered_values[val_num_base + reg]; @@ -295,6 +295,8 @@ static void append_ovm_value_with_type(debug_runtime_value_builder_t *builder, o break; } + // TODO: Should this output all of the members? + // Is this guaranteed to only have 1 member? case debug_type_kind_structure: { append_ovm_value_with_type(builder, value, type->structure.members[0].type); break; @@ -497,7 +499,18 @@ void debug_runtime_value_build_descend(debug_runtime_value_builder_t *builder, u builder->it_name = mem->name; if (builder->base_loc_kind == debug_sym_loc_register) { - builder->base_loc += index; + if (type->structure.simple) { + builder->base_loc += index; + + } else { + ovm_value_t value; + if (!lookup_register_in_frame(builder->ovm_state, builder->ovm_frame, builder->base_loc, &value)) { + goto bad_case; + } + + builder->base_loc_kind = debug_sym_loc_global; + builder->base_loc = value.u32 + mem->offset; + } } else if (builder->base_loc_kind == debug_sym_loc_stack || builder->base_loc_kind == debug_sym_loc_global) { diff --git a/shared/lib/linux_x86_64/lib/libovmwasm.so b/shared/lib/linux_x86_64/lib/libovmwasm.so index f9bd9f97..cc82da38 100755 Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ