summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c')
-rw-r--r--mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c74
1 files changed, 53 insertions, 21 deletions
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
index d3ccf08ae..a26630599 100644
--- a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
+++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
@@ -14,30 +14,62 @@
#include <mruby/variable.h>
#include "mrdberror.h"
#include "apibreak.h"
+#include "apistring.h"
#define MAX_BREAKPOINTNO (MAX_BREAKPOINT * 1024)
#define MRB_DEBUG_BP_FILE_OK (0x0001)
#define MRB_DEBUG_BP_LINENO_OK (0x0002)
+static uint32_t
+packed_int_decode(uint8_t *p, uint8_t **newpos)
+{
+ size_t i = 0, shift = 0;
+ uint32_t n = 0;
+
+ do {
+ n |= ((uint32_t)(p[i] & 0x7f)) << shift;
+ i++;
+ shift += 7;
+ } while (shift < sizeof(uint32_t) * 8 && (p[i - 1] & 0x80));
+ if (newpos) *newpos = p + i;
+ return n;
+}
+
static uint16_t
check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno)
{
uint32_t count = info_file->line_entry_count;
uint16_t l_idx;
- if (info_file->line_type == mrb_debug_line_ary) {
+ switch (info_file->line_type) {
+ case mrb_debug_line_ary:
for (l_idx = 0; l_idx < count; ++l_idx) {
if (lineno == info_file->lines.ary[l_idx]) {
return lineno;
}
}
- }
- else {
+ break;
+
+ case mrb_debug_line_flat_map:
for (l_idx = 0; l_idx < count; ++l_idx) {
if (lineno == info_file->lines.flat_map[l_idx].line) {
return lineno;
}
}
+ break;
+
+ case mrb_debug_line_packed_map:
+ {
+ uint8_t *p = info_file->lines.packed_map;
+ uint8_t *pend = p + count;
+ uint32_t line = 0;
+ while (p < pend) {
+ packed_int_decode(p, &p);
+ line += packed_int_decode(p, &p);
+ if (line == lineno) return lineno;
+ }
+ }
+ break;
}
return 0;
@@ -84,7 +116,7 @@ free_breakpoint(mrb_state *mrb, mrb_debug_breakpoint *bp)
}
static uint16_t
-check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
+check_file_lineno(mrb_state *mrb, const struct mrb_irep *irep, const char *file, uint16_t lineno)
{
mrb_irep_debug_info_file *info_file;
uint16_t result = 0;
@@ -93,8 +125,10 @@ check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
uint16_t i;
for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
+ const char *filename;
info_file = irep->debug_info->files[f_idx];
- if (!strcmp(info_file->filename, file)) {
+ filename = mrb_sym_name_len(mrb, info_file->filename_sym, NULL);
+ if (!strcmp(filename, file)) {
result = MRB_DEBUG_BP_FILE_OK;
fix_lineno = check_lineno(info_file, lineno);
@@ -103,7 +137,7 @@ check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
}
}
for (i=0; i < irep->rlen; ++i) {
- result |= check_file_lineno(irep->reps[i], file, lineno);
+ result |= check_file_lineno(mrb, irep->reps[i], file, lineno);
if (result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {
return result;
}
@@ -124,7 +158,7 @@ compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *cl
mrb_debug_methodpoint *method_p;
mrb_bool is_defined;
- method_name = mrb_sym2name(mrb, method_sym);
+ method_name = mrb_sym_name(mrb, method_sym);
method_p = &bp->point.methodpoint;
if (strcmp(method_p->method_name, method_name) == 0) {
@@ -149,7 +183,7 @@ compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *cl
}
sc = mrb_class_get(mrb, method_p->class_name);
- ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name));
+ ssym = mrb_intern_check_cstr(mrb, method_p->method_name);
m = mrb_method_search_vm(mrb, &sc, ssym);
if (MRB_METHOD_UNDEF_P(m)) {
return MRB_DEBUG_OK;
@@ -184,8 +218,8 @@ mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *fil
return MRB_DEBUG_BREAK_NO_OVER;
}
- /* file and lineno check (line type mrb_debug_line_ary only.) */
- result = check_file_lineno(dbg->root_irep, file, lineno);
+ /* file and lineno check. */
+ result = check_file_lineno(mrb, dbg->root_irep, file, lineno);
if (result == 0) {
return MRB_DEBUG_BREAK_INVALID_FILE;
}
@@ -193,7 +227,7 @@ mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *fil
return MRB_DEBUG_BREAK_INVALID_LINENO;
}
- set_file = (char*)mrb_malloc(mrb, strlen(file) + 1);
+ set_file = mrdb_strdup(mrb, file);
index = dbg->bpnum;
dbg->bp[index].bpno = dbg->next_bpno;
@@ -203,8 +237,6 @@ mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *fil
dbg->bp[index].point.linepoint.lineno = lineno;
dbg->bpnum++;
- strncpy(set_file, file, strlen(file) + 1);
-
dbg->bp[index].point.linepoint.file = set_file;
return dbg->bp[index].bpno;
@@ -230,16 +262,16 @@ mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *c
}
if (class_name != NULL) {
- set_class = (char*)mrb_malloc(mrb, strlen(class_name) + 1);
- strncpy(set_class, class_name, strlen(class_name) + 1);
+ set_class = mrdb_strdup(mrb, class_name);
}
else {
set_class = NULL;
}
- set_method = (char*)mrb_malloc(mrb, strlen(method_name) + 1);
-
- strncpy(set_method, method_name, strlen(method_name) + 1);
+ set_method = mrdb_strdup(mrb, method_name);
+ if (set_method == NULL) {
+ mrb_free(mrb, set_class);
+ }
index = dbg->bpnum;
dbg->bp[index].bpno = dbg->next_bpno;
@@ -426,10 +458,10 @@ mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
}
static mrb_bool
-check_start_pc_for_line(mrb_irep *irep, mrb_code *pc, uint16_t line)
+check_start_pc_for_line(mrb_state *mrb, const mrb_irep *irep, const mrb_code *pc, uint16_t line)
{
if (pc > irep->iseq) {
- if (line == mrb_debug_get_line(irep, pc - irep->iseq - 1)) {
+ if (line == mrb_debug_get_line(mrb, irep, pc - irep->iseq - 1)) {
return FALSE;
}
}
@@ -447,7 +479,7 @@ mrb_debug_check_breakpoint_line(mrb_state *mrb, mrb_debug_context *dbg, const ch
return MRB_DEBUG_INVALID_ARGUMENT;
}
- if (!check_start_pc_for_line(dbg->irep, dbg->pc, line)) {
+ if (!check_start_pc_for_line(mrb, dbg->irep, dbg->pc, line)) {
return MRB_DEBUG_OK;
}