[270] | 1 | /*
|
---|
| 2 | ** apibreak.c
|
---|
| 3 | **
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | #include <string.h>
|
---|
[331] | 7 | #include <mruby.h>
|
---|
| 8 | #include <mruby/irep.h>
|
---|
[270] | 9 | #include "mrdb.h"
|
---|
[331] | 10 | #include <mruby/debug.h>
|
---|
| 11 | #include <mruby/opcode.h>
|
---|
| 12 | #include <mruby/class.h>
|
---|
| 13 | #include <mruby/proc.h>
|
---|
| 14 | #include <mruby/variable.h>
|
---|
[270] | 15 | #include "mrdberror.h"
|
---|
| 16 | #include "apibreak.h"
|
---|
| 17 |
|
---|
| 18 | #define MAX_BREAKPOINTNO (MAX_BREAKPOINT * 1024)
|
---|
| 19 | #define MRB_DEBUG_BP_FILE_OK (0x0001)
|
---|
| 20 | #define MRB_DEBUG_BP_LINENO_OK (0x0002)
|
---|
| 21 |
|
---|
| 22 | static uint16_t
|
---|
[331] | 23 | check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno)
|
---|
[270] | 24 | {
|
---|
| 25 | uint32_t count = info_file->line_entry_count;
|
---|
| 26 | uint16_t l_idx;
|
---|
| 27 |
|
---|
[331] | 28 | if (info_file->line_type == mrb_debug_line_ary) {
|
---|
[270] | 29 | for (l_idx = 0; l_idx < count; ++l_idx) {
|
---|
[331] | 30 | if (lineno == info_file->lines.ary[l_idx]) {
|
---|
[270] | 31 | return lineno;
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
[331] | 34 | }
|
---|
| 35 | else {
|
---|
[270] | 36 | for (l_idx = 0; l_idx < count; ++l_idx) {
|
---|
[331] | 37 | if (lineno == info_file->lines.flat_map[l_idx].line) {
|
---|
[270] | 38 | return lineno;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | return 0;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | static int32_t
|
---|
[331] | 47 | get_break_index(mrb_debug_context *dbg, uint32_t bpno)
|
---|
[270] | 48 | {
|
---|
| 49 | uint32_t i;
|
---|
| 50 | int32_t index;
|
---|
| 51 | char hit = FALSE;
|
---|
| 52 |
|
---|
| 53 | for(i = 0 ; i < dbg->bpnum; i++) {
|
---|
[331] | 54 | if (dbg->bp[i].bpno == bpno) {
|
---|
[270] | 55 | hit = TRUE;
|
---|
| 56 | index = i;
|
---|
| 57 | break;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[331] | 61 | if (hit == FALSE) {
|
---|
[270] | 62 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | return index;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | static void
|
---|
[331] | 69 | free_breakpoint(mrb_state *mrb, mrb_debug_breakpoint *bp)
|
---|
[270] | 70 | {
|
---|
| 71 | switch(bp->type) {
|
---|
| 72 | case MRB_DEBUG_BPTYPE_LINE:
|
---|
| 73 | mrb_free(mrb, (void*)bp->point.linepoint.file);
|
---|
| 74 | break;
|
---|
| 75 | case MRB_DEBUG_BPTYPE_METHOD:
|
---|
| 76 | mrb_free(mrb, (void*)bp->point.methodpoint.method_name);
|
---|
[331] | 77 | if (bp->point.methodpoint.class_name != NULL) {
|
---|
[270] | 78 | mrb_free(mrb, (void*)bp->point.methodpoint.class_name);
|
---|
| 79 | }
|
---|
| 80 | break;
|
---|
| 81 | default:
|
---|
| 82 | break;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | static uint16_t
|
---|
[331] | 87 | check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
|
---|
[270] | 88 | {
|
---|
| 89 | mrb_irep_debug_info_file *info_file;
|
---|
| 90 | uint16_t result = 0;
|
---|
| 91 | uint16_t f_idx;
|
---|
| 92 | uint16_t fix_lineno;
|
---|
| 93 | uint16_t i;
|
---|
| 94 |
|
---|
| 95 | for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
|
---|
| 96 | info_file = irep->debug_info->files[f_idx];
|
---|
[331] | 97 | if (!strcmp(info_file->filename, file)) {
|
---|
[270] | 98 | result = MRB_DEBUG_BP_FILE_OK;
|
---|
| 99 |
|
---|
[331] | 100 | fix_lineno = check_lineno(info_file, lineno);
|
---|
| 101 | if (fix_lineno != 0) {
|
---|
[270] | 102 | return result | MRB_DEBUG_BP_LINENO_OK;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
[331] | 105 | for (i=0; i < irep->rlen; ++i) {
|
---|
[270] | 106 | result |= check_file_lineno(irep->reps[i], file, lineno);
|
---|
[331] | 107 | if (result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {
|
---|
[270] | 108 | return result;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | return result;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | static const char*
|
---|
[331] | 116 | get_class_name(mrb_state *mrb, struct RClass *class_obj)
|
---|
[270] | 117 | {
|
---|
| 118 | struct RClass *outer;
|
---|
| 119 | mrb_sym class_sym;
|
---|
| 120 |
|
---|
| 121 | outer = mrb_class_outer_module(mrb, class_obj);
|
---|
| 122 | class_sym = mrb_class_sym(mrb, class_obj, outer);
|
---|
| 123 | return mrb_sym2name(mrb, class_sym);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | static int32_t
|
---|
[331] | 127 | compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
|
---|
[270] | 128 | {
|
---|
| 129 | const char* class_name;
|
---|
| 130 | const char* method_name;
|
---|
| 131 | struct RProc* m;
|
---|
| 132 | struct RClass* sc;
|
---|
| 133 | const char* sn;
|
---|
| 134 | mrb_sym ssym;
|
---|
| 135 | mrb_debug_methodpoint *method_p;
|
---|
| 136 | mrb_bool is_defined;
|
---|
| 137 |
|
---|
| 138 | method_name = mrb_sym2name(mrb, method_sym);
|
---|
| 139 |
|
---|
| 140 | method_p = &bp->point.methodpoint;
|
---|
[331] | 141 | if (strcmp(method_p->method_name, method_name) == 0) {
|
---|
[270] | 142 | class_name = get_class_name(mrb, class_obj);
|
---|
[331] | 143 | if (class_name == NULL) {
|
---|
| 144 | if (method_p->class_name == NULL) {
|
---|
[270] | 145 | return bp->bpno;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
[331] | 148 | else if (method_p->class_name != NULL) {
|
---|
[270] | 149 | m = mrb_method_search_vm(mrb, &class_obj, method_sym);
|
---|
[331] | 150 | if (m == NULL) {
|
---|
[270] | 151 | return MRB_DEBUG_OK;
|
---|
| 152 | }
|
---|
[331] | 153 | if (MRB_PROC_CFUNC_P(m)) {
|
---|
[270] | 154 | *isCfunc = TRUE;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | is_defined = mrb_class_defined(mrb, method_p->class_name);
|
---|
[331] | 158 | if (is_defined == FALSE) {
|
---|
[270] | 159 | return MRB_DEBUG_OK;
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | sc = mrb_class_get(mrb, method_p->class_name);
|
---|
| 163 | ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name));
|
---|
| 164 | m = mrb_method_search_vm(mrb, &sc, ssym);
|
---|
[331] | 165 | if (m == NULL) {
|
---|
[270] | 166 | return MRB_DEBUG_OK;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | class_name = get_class_name(mrb, class_obj);
|
---|
| 170 | sn = get_class_name(mrb, sc);
|
---|
[331] | 171 | if (strcmp(sn, class_name) == 0) {
|
---|
[270] | 172 | return bp->bpno;
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 | return MRB_DEBUG_OK;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | int32_t
|
---|
[331] | 180 | mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t lineno)
|
---|
[270] | 181 | {
|
---|
| 182 | int32_t index;
|
---|
| 183 | char* set_file;
|
---|
| 184 | uint16_t result;
|
---|
| 185 |
|
---|
[331] | 186 | if ((mrb == NULL)||(dbg == NULL)||(file == NULL)) {
|
---|
[270] | 187 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
[331] | 190 | if (dbg->bpnum >= MAX_BREAKPOINT) {
|
---|
[270] | 191 | return MRB_DEBUG_BREAK_NUM_OVER;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[331] | 194 | if (dbg->next_bpno > MAX_BREAKPOINTNO) {
|
---|
[270] | 195 | return MRB_DEBUG_BREAK_NO_OVER;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | /* file and lineno check (line type mrb_debug_line_ary only.) */
|
---|
[331] | 199 | result = check_file_lineno(dbg->root_irep, file, lineno);
|
---|
| 200 | if (result == 0) {
|
---|
[270] | 201 | return MRB_DEBUG_BREAK_INVALID_FILE;
|
---|
[331] | 202 | }
|
---|
| 203 | else if (result == MRB_DEBUG_BP_FILE_OK) {
|
---|
[270] | 204 | return MRB_DEBUG_BREAK_INVALID_LINENO;
|
---|
[331] | 205 | }
|
---|
[270] | 206 |
|
---|
| 207 | set_file = mrb_malloc(mrb, strlen(file) + 1);
|
---|
| 208 |
|
---|
| 209 | index = dbg->bpnum;
|
---|
| 210 | dbg->bp[index].bpno = dbg->next_bpno;
|
---|
| 211 | dbg->next_bpno++;
|
---|
| 212 | dbg->bp[index].enable = TRUE;
|
---|
| 213 | dbg->bp[index].type = MRB_DEBUG_BPTYPE_LINE;
|
---|
| 214 | dbg->bp[index].point.linepoint.lineno = lineno;
|
---|
| 215 | dbg->bpnum++;
|
---|
| 216 |
|
---|
| 217 | strncpy(set_file, file, strlen(file) + 1);
|
---|
| 218 |
|
---|
| 219 | dbg->bp[index].point.linepoint.file = set_file;
|
---|
| 220 |
|
---|
| 221 | return dbg->bp[index].bpno;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | int32_t
|
---|
[331] | 225 | mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *class_name, const char *method_name)
|
---|
[270] | 226 | {
|
---|
| 227 | int32_t index;
|
---|
| 228 | char* set_class;
|
---|
| 229 | char* set_method;
|
---|
| 230 |
|
---|
[331] | 231 | if ((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
|
---|
[270] | 232 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[331] | 235 | if (dbg->bpnum >= MAX_BREAKPOINT) {
|
---|
[270] | 236 | return MRB_DEBUG_BREAK_NUM_OVER;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
[331] | 239 | if (dbg->next_bpno > MAX_BREAKPOINTNO) {
|
---|
[270] | 240 | return MRB_DEBUG_BREAK_NO_OVER;
|
---|
| 241 | }
|
---|
| 242 |
|
---|
[331] | 243 | if (class_name != NULL) {
|
---|
[270] | 244 | set_class = mrb_malloc(mrb, strlen(class_name) + 1);
|
---|
| 245 | strncpy(set_class, class_name, strlen(class_name) + 1);
|
---|
| 246 | }
|
---|
| 247 | else {
|
---|
| 248 | set_class = NULL;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | set_method = mrb_malloc(mrb, strlen(method_name) + 1);
|
---|
| 252 |
|
---|
| 253 | strncpy(set_method, method_name, strlen(method_name) + 1);
|
---|
| 254 |
|
---|
| 255 | index = dbg->bpnum;
|
---|
| 256 | dbg->bp[index].bpno = dbg->next_bpno;
|
---|
| 257 | dbg->next_bpno++;
|
---|
| 258 | dbg->bp[index].enable = TRUE;
|
---|
| 259 | dbg->bp[index].type = MRB_DEBUG_BPTYPE_METHOD;
|
---|
| 260 | dbg->bp[index].point.methodpoint.method_name = set_method;
|
---|
| 261 | dbg->bp[index].point.methodpoint.class_name = set_class;
|
---|
| 262 | dbg->bpnum++;
|
---|
| 263 |
|
---|
| 264 | return dbg->bp[index].bpno;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | int32_t
|
---|
[331] | 268 | mrb_debug_get_breaknum(mrb_state *mrb, mrb_debug_context *dbg)
|
---|
[270] | 269 | {
|
---|
[331] | 270 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 271 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | return dbg->bpnum;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[331] | 277 | int32_t
|
---|
| 278 | mrb_debug_get_break_all(mrb_state *mrb, mrb_debug_context *dbg, uint32_t size, mrb_debug_breakpoint *bp)
|
---|
[270] | 279 | {
|
---|
| 280 | uint32_t get_size = 0;
|
---|
| 281 |
|
---|
[331] | 282 | if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
|
---|
[270] | 283 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
[331] | 286 | if (dbg->bpnum >= size) {
|
---|
[270] | 287 | get_size = size;
|
---|
| 288 | }
|
---|
| 289 | else {
|
---|
| 290 | get_size = dbg->bpnum;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | memcpy(bp, dbg->bp, sizeof(mrb_debug_breakpoint) * get_size);
|
---|
| 294 |
|
---|
| 295 | return get_size;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | int32_t
|
---|
[331] | 299 | mrb_debug_get_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_debug_breakpoint *bp)
|
---|
[270] | 300 | {
|
---|
[331] | 301 | int32_t index;
|
---|
[270] | 302 |
|
---|
[331] | 303 | if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
|
---|
[270] | 304 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | index = get_break_index(dbg, bpno);
|
---|
[331] | 308 | if (index == MRB_DEBUG_BREAK_INVALID_NO) {
|
---|
[270] | 309 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | bp->bpno = dbg->bp[index].bpno;
|
---|
| 313 | bp->enable = dbg->bp[index].enable;
|
---|
| 314 | bp->point = dbg->bp[index].point;
|
---|
| 315 | bp->type = dbg->bp[index].type;
|
---|
| 316 |
|
---|
| 317 | return 0;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
[331] | 320 | int32_t
|
---|
| 321 | mrb_debug_delete_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
|
---|
[270] | 322 | {
|
---|
| 323 | uint32_t i;
|
---|
| 324 | int32_t index;
|
---|
| 325 |
|
---|
[331] | 326 | if ((mrb == NULL) ||(dbg == NULL)) {
|
---|
[270] | 327 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | index = get_break_index(dbg, bpno);
|
---|
[331] | 331 | if (index == MRB_DEBUG_BREAK_INVALID_NO) {
|
---|
[270] | 332 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | free_breakpoint(mrb, &dbg->bp[index]);
|
---|
| 336 |
|
---|
| 337 | for(i = index ; i < dbg->bpnum; i++) {
|
---|
[331] | 338 | if ((i + 1) == dbg->bpnum) {
|
---|
[270] | 339 | memset(&dbg->bp[i], 0, sizeof(mrb_debug_breakpoint));
|
---|
| 340 | }
|
---|
| 341 | else {
|
---|
| 342 | memcpy(&dbg->bp[i], &dbg->bp[i + 1], sizeof(mrb_debug_breakpoint));
|
---|
| 343 | }
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | dbg->bpnum--;
|
---|
| 347 |
|
---|
| 348 | return MRB_DEBUG_OK;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
[331] | 351 | int32_t
|
---|
| 352 | mrb_debug_delete_break_all(mrb_state *mrb, mrb_debug_context *dbg)
|
---|
[270] | 353 | {
|
---|
| 354 | uint32_t i;
|
---|
| 355 |
|
---|
[331] | 356 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 357 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | for(i = 0 ; i < dbg->bpnum ; i++) {
|
---|
| 361 | free_breakpoint(mrb, &dbg->bp[i]);
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | dbg->bpnum = 0;
|
---|
| 365 |
|
---|
| 366 | return MRB_DEBUG_OK;
|
---|
| 367 | }
|
---|
| 368 |
|
---|
[331] | 369 | int32_t
|
---|
| 370 | mrb_debug_enable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
|
---|
[270] | 371 | {
|
---|
| 372 | int32_t index = 0;
|
---|
| 373 |
|
---|
[331] | 374 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 375 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | index = get_break_index(dbg, bpno);
|
---|
[331] | 379 | if (index == MRB_DEBUG_BREAK_INVALID_NO) {
|
---|
[270] | 380 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | dbg->bp[index].enable = TRUE;
|
---|
| 384 |
|
---|
| 385 | return MRB_DEBUG_OK;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | int32_t
|
---|
[331] | 389 | mrb_debug_enable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
|
---|
[270] | 390 | {
|
---|
| 391 | uint32_t i;
|
---|
| 392 |
|
---|
[331] | 393 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 394 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | for(i = 0 ; i < dbg->bpnum; i++) {
|
---|
| 398 | dbg->bp[i].enable = TRUE;
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | return MRB_DEBUG_OK;
|
---|
| 402 | }
|
---|
| 403 |
|
---|
[331] | 404 | int32_t
|
---|
| 405 | mrb_debug_disable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
|
---|
[270] | 406 | {
|
---|
| 407 | int32_t index = 0;
|
---|
| 408 |
|
---|
[331] | 409 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 410 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | index = get_break_index(dbg, bpno);
|
---|
[331] | 414 | if (index == MRB_DEBUG_BREAK_INVALID_NO) {
|
---|
[270] | 415 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | dbg->bp[index].enable = FALSE;
|
---|
| 419 |
|
---|
| 420 | return MRB_DEBUG_OK;
|
---|
| 421 | }
|
---|
| 422 |
|
---|
[331] | 423 | int32_t
|
---|
| 424 | mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
|
---|
[270] | 425 | {
|
---|
| 426 | uint32_t i;
|
---|
| 427 |
|
---|
[331] | 428 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 429 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | for(i = 0 ; i < dbg->bpnum; i++) {
|
---|
| 433 | dbg->bp[i].enable = FALSE;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | return MRB_DEBUG_OK;
|
---|
| 437 | }
|
---|
| 438 |
|
---|
| 439 | static mrb_bool
|
---|
[331] | 440 | check_start_pc_for_line(mrb_irep *irep, mrb_code *pc, uint16_t line)
|
---|
[270] | 441 | {
|
---|
[331] | 442 | if (pc > irep->iseq) {
|
---|
| 443 | if (line == mrb_debug_get_line(irep, (uint32_t)(pc - irep->iseq - 1))) {
|
---|
[270] | 444 | return FALSE;
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
| 447 | return TRUE;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | int32_t
|
---|
[331] | 451 | mrb_debug_check_breakpoint_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t line)
|
---|
[270] | 452 | {
|
---|
| 453 | mrb_debug_breakpoint *bp;
|
---|
| 454 | mrb_debug_linepoint *line_p;
|
---|
[331] | 455 | uint32_t i;
|
---|
[270] | 456 |
|
---|
[331] | 457 | if ((mrb == NULL) || (dbg == NULL) || (file == NULL) || (line <= 0)) {
|
---|
[270] | 458 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 459 | }
|
---|
| 460 |
|
---|
[331] | 461 | if (!check_start_pc_for_line(dbg->irep, dbg->pc, line)) {
|
---|
[270] | 462 | return MRB_DEBUG_OK;
|
---|
| 463 | }
|
---|
| 464 |
|
---|
| 465 | bp = dbg->bp;
|
---|
| 466 | for(i=0; i<dbg->bpnum; i++) {
|
---|
| 467 | switch (bp->type) {
|
---|
| 468 | case MRB_DEBUG_BPTYPE_LINE:
|
---|
[331] | 469 | if (bp->enable == TRUE) {
|
---|
[270] | 470 | line_p = &bp->point.linepoint;
|
---|
[331] | 471 | if ((strcmp(line_p->file, file) == 0) && (line_p->lineno == line)) {
|
---|
[270] | 472 | return bp->bpno;
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 | break;
|
---|
| 476 | case MRB_DEBUG_BPTYPE_METHOD:
|
---|
| 477 | break;
|
---|
| 478 | case MRB_DEBUG_BPTYPE_NONE:
|
---|
| 479 | default:
|
---|
| 480 | return MRB_DEBUG_OK;
|
---|
| 481 | }
|
---|
| 482 | bp++;
|
---|
| 483 | }
|
---|
| 484 | return MRB_DEBUG_OK;
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 |
|
---|
[331] | 488 | int32_t
|
---|
| 489 | mrb_debug_check_breakpoint_method(mrb_state *mrb, mrb_debug_context *dbg, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
|
---|
[270] | 490 | {
|
---|
| 491 | mrb_debug_breakpoint *bp;
|
---|
| 492 | int32_t bpno;
|
---|
[331] | 493 | uint32_t i;
|
---|
[270] | 494 |
|
---|
[331] | 495 | if ((mrb == NULL) || (dbg == NULL) || (class_obj == NULL)) {
|
---|
[270] | 496 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | bp = dbg->bp;
|
---|
| 500 | for(i=0; i<dbg->bpnum; i++) {
|
---|
[331] | 501 | if (bp->type == MRB_DEBUG_BPTYPE_METHOD) {
|
---|
| 502 | if (bp->enable == TRUE) {
|
---|
[270] | 503 | bpno = compare_break_method(mrb, bp, class_obj, method_sym, isCfunc);
|
---|
[331] | 504 | if (bpno > 0) {
|
---|
[270] | 505 | return bpno;
|
---|
| 506 | }
|
---|
| 507 | }
|
---|
| 508 | }
|
---|
[331] | 509 | else if (bp->type == MRB_DEBUG_BPTYPE_NONE) {
|
---|
[270] | 510 | break;
|
---|
| 511 | }
|
---|
| 512 | bp++;
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 | return 0;
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 |
|
---|