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--[-rwxr-xr-x]mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c238
1 files changed, 111 insertions, 127 deletions
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
index 9515e8be4..137f52431 100755..100644
--- a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
+++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
@@ -4,14 +4,14 @@
*/
#include <string.h>
-#include "mruby.h"
-#include "mruby/irep.h"
+#include <mruby.h>
+#include <mruby/irep.h>
#include "mrdb.h"
-#include "mruby/debug.h"
-#include "mruby/opcode.h"
-#include "mruby/class.h"
-#include "mruby/proc.h"
-#include "mruby/variable.h"
+#include <mruby/debug.h>
+#include <mruby/opcode.h>
+#include <mruby/class.h>
+#include <mruby/proc.h>
+#include <mruby/variable.h>
#include "mrdberror.h"
#include "apibreak.h"
#include "apistring.h"
@@ -21,20 +21,21 @@
#define MRB_DEBUG_BP_LINENO_OK (0x0002)
static uint16_t
-check_lineno( mrb_irep_debug_info_file *info_file, uint16_t lineno )
+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 ) {
+ if (info_file->line_type == mrb_debug_line_ary) {
for (l_idx = 0; l_idx < count; ++l_idx) {
- if(lineno == info_file->lines.ary[l_idx]) {
+ if (lineno == info_file->lines.ary[l_idx]) {
return lineno;
}
}
- } else {
+ }
+ else {
for (l_idx = 0; l_idx < count; ++l_idx) {
- if(lineno == info_file->lines.flat_map[l_idx].line) {
+ if (lineno == info_file->lines.flat_map[l_idx].line) {
return lineno;
}
}
@@ -44,21 +45,21 @@ check_lineno( mrb_irep_debug_info_file *info_file, uint16_t lineno )
}
static int32_t
-get_break_index( mrb_debug_context *dbg, int32_t bpno )
+get_break_index(mrb_debug_context *dbg, uint32_t bpno)
{
uint32_t i;
int32_t index;
char hit = FALSE;
for(i = 0 ; i < dbg->bpnum; i++) {
- if(dbg->bp[i].bpno == bpno) {
+ if (dbg->bp[i].bpno == bpno) {
hit = TRUE;
index = i;
break;
}
}
- if(hit == FALSE) {
+ if (hit == FALSE) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
@@ -66,7 +67,7 @@ get_break_index( mrb_debug_context *dbg, int32_t bpno )
}
static void
-free_breakpoint( mrb_state *mrb, mrb_debug_breakpoint *bp )
+free_breakpoint(mrb_state *mrb, mrb_debug_breakpoint *bp)
{
switch(bp->type) {
case MRB_DEBUG_BPTYPE_LINE:
@@ -74,7 +75,7 @@ free_breakpoint( mrb_state *mrb, mrb_debug_breakpoint *bp )
break;
case MRB_DEBUG_BPTYPE_METHOD:
mrb_free(mrb, (void*)bp->point.methodpoint.method_name);
- if(bp->point.methodpoint.class_name != NULL) {
+ if (bp->point.methodpoint.class_name != NULL) {
mrb_free(mrb, (void*)bp->point.methodpoint.class_name);
}
break;
@@ -84,7 +85,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,18 +94,20 @@ 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 );
- if(fix_lineno != 0) {
+ fix_lineno = check_lineno(info_file, lineno);
+ if (fix_lineno != 0) {
return result | MRB_DEBUG_BP_LINENO_OK;
}
}
- for ( i=0; i < irep->rlen; ++i ) {
- result |= check_file_lineno(irep->reps[i], file, lineno);
- if(result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {
+ for (i=0; i < irep->rlen; ++i) {
+ result |= check_file_lineno(mrb, irep->reps[i], file, lineno);
+ if (result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {
return result;
}
}
@@ -112,63 +115,52 @@ check_file_lineno( struct mrb_irep *irep, const char *file, uint16_t lineno )
return result;
}
-static const char*
-get_class_name( mrb_state *mrb, struct RClass *class_obj )
-{
- struct RClass *outer;
- mrb_sym class_sym;
-
- outer = mrb_class_outer_module(mrb, class_obj);
- class_sym = mrb_class_sym(mrb, class_obj, outer);
- return mrb_sym2name(mrb, class_sym);
-}
-
static int32_t
-compare_break_method( mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc )
+compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
{
const char* class_name;
const char* method_name;
- struct RProc* m;
+ mrb_method_t m;
struct RClass* sc;
const char* sn;
mrb_sym ssym;
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) {
- class_name = get_class_name(mrb, class_obj);
- if(class_name == NULL) {
- if(method_p->class_name == NULL) {
+ if (strcmp(method_p->method_name, method_name) == 0) {
+ class_name = mrb_class_name(mrb, class_obj);
+ if (class_name == NULL) {
+ if (method_p->class_name == NULL) {
return bp->bpno;
}
}
- else if(method_p->class_name != NULL) {
+ else if (method_p->class_name != NULL) {
m = mrb_method_search_vm(mrb, &class_obj, method_sym);
- if(m == NULL) {
+ if (MRB_METHOD_UNDEF_P(m)) {
return MRB_DEBUG_OK;
}
- if(MRB_PROC_CFUNC_P(m)) {
+ if (MRB_METHOD_CFUNC_P(m)) {
*isCfunc = TRUE;
}
is_defined = mrb_class_defined(mrb, method_p->class_name);
- if(is_defined == FALSE) {
+ if (is_defined == FALSE) {
return MRB_DEBUG_OK;
}
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(m == NULL) {
+ if (MRB_METHOD_UNDEF_P(m)) {
return MRB_DEBUG_OK;
}
- class_name = get_class_name(mrb, class_obj);
- sn = get_class_name(mrb, sc);
- if(strcmp(sn, class_name) == 0) {
+ class_name = mrb_class_name(mrb, class_obj);
+ sn = mrb_class_name(mrb, sc);
+ if (strcmp(sn, class_name) == 0) {
return bp->bpno;
}
}
@@ -177,36 +169,36 @@ compare_break_method( mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *c
}
int32_t
-mrb_debug_set_break_line( mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t lineno)
+mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t lineno)
{
int32_t index;
char* set_file;
uint16_t result;
+ size_t len;
- if((mrb == NULL)||(dbg == NULL)||(file == NULL)) {
+ if ((mrb == NULL)||(dbg == NULL)||(file == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
- if(dbg->bpnum >= MAX_BREAKPOINT) {
+ if (dbg->bpnum >= MAX_BREAKPOINT) {
return MRB_DEBUG_BREAK_NUM_OVER;
}
- if(dbg->next_bpno > MAX_BREAKPOINTNO) {
+ if (dbg->next_bpno > MAX_BREAKPOINTNO) {
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 );
- if(result == 0) {
+ result = check_file_lineno(mrb, dbg->root_irep, file, lineno);
+ if (result == 0) {
return MRB_DEBUG_BREAK_INVALID_FILE;
- }else if(result == MRB_DEBUG_BP_FILE_OK) {
+ }
+ else if (result == MRB_DEBUG_BP_FILE_OK) {
return MRB_DEBUG_BREAK_INVALID_LINENO;
- }
+ }
+ len = strlen(file) + 1;
set_file = mrb_debug_strdup(mrb, file);
- if(set_file == NULL) {
- return MRB_DEBUG_NOBUF;
- }
index = dbg->bpnum;
dbg->bp[index].bpno = dbg->next_bpno;
@@ -222,40 +214,34 @@ mrb_debug_set_break_line( mrb_state *mrb, mrb_debug_context *dbg, const char *fi
}
int32_t
-mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char *class_name, const char *method_name )
+mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *class_name, const char *method_name)
{
int32_t index;
char* set_class;
char* set_method;
- if((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
- if(dbg->bpnum >= MAX_BREAKPOINT) {
+ if (dbg->bpnum >= MAX_BREAKPOINT) {
return MRB_DEBUG_BREAK_NUM_OVER;
}
- if(dbg->next_bpno > MAX_BREAKPOINTNO) {
+ if (dbg->next_bpno > MAX_BREAKPOINTNO) {
return MRB_DEBUG_BREAK_NO_OVER;
}
- if(class_name != NULL) {
+ if (class_name != NULL) {
set_class = mrb_debug_strdup(mrb, class_name);
- if(set_class == NULL) {
- return MRB_DEBUG_NOBUF;
- }
}
else {
set_class = NULL;
}
set_method = mrb_debug_strdup(mrb, method_name);
- if(set_method == NULL) {
- if(set_class != NULL) {
- mrb_free(mrb, (void*)set_class);
- }
- return MRB_DEBUG_NOBUF;
+ if (set_method == NULL) {
+ mrb_free(mrb, set_class);
}
index = dbg->bpnum;
@@ -271,25 +257,25 @@ mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char *
}
int32_t
-mrb_debug_get_breaknum( mrb_state *mrb, mrb_debug_context *dbg )
+mrb_debug_get_breaknum(mrb_state *mrb, mrb_debug_context *dbg)
{
- if((mrb == NULL) || (dbg == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
return dbg->bpnum;
}
-int32_t
-mrb_debug_get_break_all( mrb_state *mrb, mrb_debug_context *dbg, uint32_t size, mrb_debug_breakpoint *bp )
+int32_t
+mrb_debug_get_break_all(mrb_state *mrb, mrb_debug_context *dbg, uint32_t size, mrb_debug_breakpoint *bp)
{
uint32_t get_size = 0;
- if((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
- if(dbg->bpnum >= size) {
+ if (dbg->bpnum >= size) {
get_size = size;
}
else {
@@ -302,16 +288,16 @@ mrb_debug_get_break_all( mrb_state *mrb, mrb_debug_context *dbg, uint32_t size,
}
int32_t
-mrb_debug_get_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_debug_breakpoint *bp )
+mrb_debug_get_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_debug_breakpoint *bp)
{
- uint32_t index;
+ int32_t index;
- if((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
index = get_break_index(dbg, bpno);
- if(index == MRB_DEBUG_BREAK_INVALID_NO) {
+ if (index == MRB_DEBUG_BREAK_INVALID_NO) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
@@ -323,25 +309,25 @@ mrb_debug_get_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_
return 0;
}
-int32_t
-mrb_debug_delete_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
+int32_t
+mrb_debug_delete_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
{
uint32_t i;
int32_t index;
- if((mrb == NULL) ||(dbg == NULL)) {
+ if ((mrb == NULL) ||(dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
index = get_break_index(dbg, bpno);
- if(index == MRB_DEBUG_BREAK_INVALID_NO) {
+ if (index == MRB_DEBUG_BREAK_INVALID_NO) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
free_breakpoint(mrb, &dbg->bp[index]);
for(i = index ; i < dbg->bpnum; i++) {
- if(dbg->bp[i + 1].type == MRB_DEBUG_BPTYPE_NONE) {
+ if ((i + 1) == dbg->bpnum) {
memset(&dbg->bp[i], 0, sizeof(mrb_debug_breakpoint));
}
else {
@@ -354,12 +340,12 @@ mrb_debug_delete_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
return MRB_DEBUG_OK;
}
-int32_t
-mrb_debug_delete_break_all( mrb_state *mrb, mrb_debug_context *dbg )
+int32_t
+mrb_debug_delete_break_all(mrb_state *mrb, mrb_debug_context *dbg)
{
uint32_t i;
- if((mrb == NULL) || (dbg == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
@@ -372,17 +358,17 @@ mrb_debug_delete_break_all( mrb_state *mrb, mrb_debug_context *dbg )
return MRB_DEBUG_OK;
}
-int32_t
-mrb_debug_enable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
+int32_t
+mrb_debug_enable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
{
int32_t index = 0;
- if((mrb == NULL) || (dbg == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
index = get_break_index(dbg, bpno);
- if(index == MRB_DEBUG_BREAK_INVALID_NO) {
+ if (index == MRB_DEBUG_BREAK_INVALID_NO) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
@@ -392,11 +378,11 @@ mrb_debug_enable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
}
int32_t
-mrb_debug_enable_break_all( mrb_state *mrb, mrb_debug_context *dbg )
+mrb_debug_enable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
{
uint32_t i;
- if((mrb == NULL) || (dbg == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
@@ -407,17 +393,17 @@ mrb_debug_enable_break_all( mrb_state *mrb, mrb_debug_context *dbg )
return MRB_DEBUG_OK;
}
-int32_t
-mrb_debug_disable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
+int32_t
+mrb_debug_disable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
{
int32_t index = 0;
- if((mrb == NULL) || (dbg == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
index = get_break_index(dbg, bpno);
- if(index == MRB_DEBUG_BREAK_INVALID_NO) {
+ if (index == MRB_DEBUG_BREAK_INVALID_NO) {
return MRB_DEBUG_BREAK_INVALID_NO;
}
@@ -426,12 +412,12 @@ mrb_debug_disable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno )
return MRB_DEBUG_OK;
}
-int32_t
-mrb_debug_disable_break_all( mrb_state *mrb, mrb_debug_context *dbg )
+int32_t
+mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
{
uint32_t i;
- if((mrb == NULL) || (dbg == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
@@ -443,10 +429,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, (uint32_t)(pc - irep->iseq - 1))) {
+ if (pc > irep->iseq) {
+ if (line == mrb_debug_get_line(mrb, irep, pc - irep->iseq - 1)) {
return FALSE;
}
}
@@ -454,27 +440,27 @@ check_start_pc_for_line( mrb_irep *irep, mrb_code *pc, uint16_t line )
}
int32_t
-mrb_debug_check_breakpoint_line( mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t line )
+mrb_debug_check_breakpoint_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t line)
{
mrb_debug_breakpoint *bp;
mrb_debug_linepoint *line_p;
- int i;
+ uint32_t i;
- if((mrb == NULL) || (dbg == NULL) || (file == NULL) || (line <= 0)) {
+ if ((mrb == NULL) || (dbg == NULL) || (file == NULL) || (line <= 0)) {
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;
}
bp = dbg->bp;
- for(i=0; i<MAX_BREAKPOINT; i++) {
+ for(i=0; i<dbg->bpnum; i++) {
switch (bp->type) {
case MRB_DEBUG_BPTYPE_LINE:
- if(bp->enable == TRUE) {
+ if (bp->enable == TRUE) {
line_p = &bp->point.linepoint;
- if((strcmp(line_p->file, file) == 0) && (line_p->lineno == line)) {
+ if ((strcmp(line_p->file, file) == 0) && (line_p->lineno == line)) {
return bp->bpno;
}
}
@@ -491,28 +477,28 @@ mrb_debug_check_breakpoint_line( mrb_state *mrb, mrb_debug_context *dbg, const c
}
-int32_t
-mrb_debug_check_breakpoint_method( mrb_state *mrb, mrb_debug_context *dbg, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc )
+int32_t
+mrb_debug_check_breakpoint_method(mrb_state *mrb, mrb_debug_context *dbg, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
{
mrb_debug_breakpoint *bp;
int32_t bpno;
- int i;
+ uint32_t i;
- if((mrb == NULL) || (dbg == NULL) || (class_obj == NULL)) {
+ if ((mrb == NULL) || (dbg == NULL) || (class_obj == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
}
bp = dbg->bp;
- for(i=0; i<MAX_BREAKPOINT; i++) {
- if(bp->type == MRB_DEBUG_BPTYPE_METHOD) {
- if(bp->enable == TRUE) {
+ for(i=0; i<dbg->bpnum; i++) {
+ if (bp->type == MRB_DEBUG_BPTYPE_METHOD) {
+ if (bp->enable == TRUE) {
bpno = compare_break_method(mrb, bp, class_obj, method_sym, isCfunc);
- if(bpno > 0) {
+ if (bpno > 0) {
return bpno;
}
}
}
- else if(bp->type == MRB_DEBUG_BPTYPE_NONE) {
+ else if (bp->type == MRB_DEBUG_BPTYPE_NONE) {
break;
}
bp++;
@@ -520,5 +506,3 @@ mrb_debug_check_breakpoint_method( mrb_state *mrb, mrb_debug_context *dbg, struc
return 0;
}
-
-