From f16ea05a178a0ffd38a054d28a01c1780d63d03a Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 8 Jul 2021 07:10:11 +0900 Subject: debug.c: new debug line information format `mrb_debug_line_packed_map`. It uses BER number compression of delta of instruction positions and line numbers. BER compression is a variable length number representation. * `mrb_debug_line_ary`: array of line numbers represented in `uint16_t`. `[lineno, lineno, ...]` * `mrb_debug_line_flat_map`: array of `mrb_irep_debug_info_line`, which is `struct {uint32_t pos; uint16_t lineno}`, for each line. * `mrb_debug_line_packed_map` [new]: sequence of BER compressed 2 numbers, `pos_delta, lineno_delta`. Deltas are differences from previous values (starting `0`). `line_entry_counts` represents total length of a packed map string for this type. --- src/cdump.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'src/cdump.c') diff --git a/src/cdump.c b/src/cdump.c index 9b7040e58..72b4ad0b3 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -258,9 +258,7 @@ cdump_syms(mrb_state *mrb, const char *name, const char *key, int n, int syms_le static int simple_debug_info(mrb_irep_debug_info *info) { - if (!info || - info->flen != 1 || - info->files[0]->line_type != mrb_debug_line_ary) { + if (!info || info->flen != 1) { return 0; } return 1; @@ -276,6 +274,7 @@ cdump_debug(mrb_state *mrb, const char *name, int n, mrb_irep_debug_info *info, const char *filename; mrb_int file_len; int len, i; + const char *line_type; if (!simple_debug_info(info)) return MRB_DUMP_INVALID_IREP; @@ -289,19 +288,44 @@ cdump_debug(mrb_state *mrb, const char *name, int n, mrb_irep_debug_info *info, mrb_str_cat_cstr(mrb, init_syms_code, filename); mrb_str_cat_cstr(mrb, init_syms_code, "\");\n"); - fprintf(fp, "static uint16_t %s_debug_lines_%d[%d] = {", name, n, len); - for (i=0; ifiles[0]->lines.ary[i]); - } - fputs("};\n", fp); + switch (info->files[0]->line_type) { + case mrb_debug_line_ary: + line_type = "mrb_debug_line_ary"; + fprintf(fp, "static uint16_t %s_debug_lines_%d[%d] = {", name, n, len); + for (i=0; ifiles[0]->lines.ary[i]); + } + fputs("};\n", fp); + break; + case mrb_debug_line_flat_map: + line_type = "mrb_debug_line_flat_map"; + fprintf(fp, "static struct mrb_irep_debug_info_line %s_debug_lines_%d[%d] = {", name, n, len); + for (i=0; ifiles[0]->lines.flat_map[i]; + fprintf(fp, "\t{.start_pos=0x%04x,.line=%d},\n", fmap->start_pos, fmap->line); + } + fputs("};\n", fp); + break; + + case mrb_debug_line_packed_map: + line_type = "mrb_debug_line_packed_map"; + fprintf(fp, "static char %s_debug_lines_%d[] = \"", name, n); + char *pmap = info->files[0]->lines.packed_map; + for (i=0; ifiles[0]->start_pos, - info->files[0]->filename_sym, - info->files[0]->line_entry_count, - name,n); + fprintf(fp, "%d, %d, %d, %s, {%s_debug_lines_%d}};\n", + info->files[0]->start_pos, + info->files[0]->filename_sym, + info->files[0]->line_entry_count, + line_type, + name,n); fprintf(fp, "static mrb_irep_debug_info_file *%s_debug_file_%d_ = &%s_debug_file_%d;\n", name, n, name, n); fprintf(fp, "static mrb_irep_debug_info %s_debug_%d = {\n", name, n); -- cgit v1.2.3