[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
|
---|
[439] | 87 | check_file_lineno(mrb_state *mrb, 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) {
|
---|
[439] | 96 | const char *filename;
|
---|
[270] | 97 | info_file = irep->debug_info->files[f_idx];
|
---|
[439] | 98 | filename = mrb_sym_name_len(mrb, info_file->filename_sym, NULL);
|
---|
| 99 | if (!strcmp(filename, file)) {
|
---|
[270] | 100 | result = MRB_DEBUG_BP_FILE_OK;
|
---|
| 101 |
|
---|
[331] | 102 | fix_lineno = check_lineno(info_file, lineno);
|
---|
| 103 | if (fix_lineno != 0) {
|
---|
[270] | 104 | return result | MRB_DEBUG_BP_LINENO_OK;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
[331] | 107 | for (i=0; i < irep->rlen; ++i) {
|
---|
[439] | 108 | result |= check_file_lineno(mrb, irep->reps[i], file, lineno);
|
---|
[331] | 109 | if (result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {
|
---|
[270] | 110 | return result;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | return result;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | static int32_t
|
---|
[331] | 118 | compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
|
---|
[270] | 119 | {
|
---|
| 120 | const char* class_name;
|
---|
| 121 | const char* method_name;
|
---|
[439] | 122 | mrb_method_t m;
|
---|
[270] | 123 | struct RClass* sc;
|
---|
| 124 | const char* sn;
|
---|
| 125 | mrb_sym ssym;
|
---|
| 126 | mrb_debug_methodpoint *method_p;
|
---|
| 127 | mrb_bool is_defined;
|
---|
| 128 |
|
---|
[439] | 129 | method_name = mrb_sym_name(mrb, method_sym);
|
---|
[270] | 130 |
|
---|
| 131 | method_p = &bp->point.methodpoint;
|
---|
[331] | 132 | if (strcmp(method_p->method_name, method_name) == 0) {
|
---|
[439] | 133 | class_name = mrb_class_name(mrb, class_obj);
|
---|
[331] | 134 | if (class_name == NULL) {
|
---|
| 135 | if (method_p->class_name == NULL) {
|
---|
[270] | 136 | return bp->bpno;
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
[331] | 139 | else if (method_p->class_name != NULL) {
|
---|
[270] | 140 | m = mrb_method_search_vm(mrb, &class_obj, method_sym);
|
---|
[439] | 141 | if (MRB_METHOD_UNDEF_P(m)) {
|
---|
[270] | 142 | return MRB_DEBUG_OK;
|
---|
| 143 | }
|
---|
[439] | 144 | if (MRB_METHOD_CFUNC_P(m)) {
|
---|
[270] | 145 | *isCfunc = TRUE;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | is_defined = mrb_class_defined(mrb, method_p->class_name);
|
---|
[331] | 149 | if (is_defined == FALSE) {
|
---|
[270] | 150 | return MRB_DEBUG_OK;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | sc = mrb_class_get(mrb, method_p->class_name);
|
---|
| 154 | ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name));
|
---|
| 155 | m = mrb_method_search_vm(mrb, &sc, ssym);
|
---|
[439] | 156 | if (MRB_METHOD_UNDEF_P(m)) {
|
---|
[270] | 157 | return MRB_DEBUG_OK;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[439] | 160 | class_name = mrb_class_name(mrb, class_obj);
|
---|
| 161 | sn = mrb_class_name(mrb, sc);
|
---|
[331] | 162 | if (strcmp(sn, class_name) == 0) {
|
---|
[270] | 163 | return bp->bpno;
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 | return MRB_DEBUG_OK;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | int32_t
|
---|
[331] | 171 | mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t lineno)
|
---|
[270] | 172 | {
|
---|
| 173 | int32_t index;
|
---|
| 174 | char* set_file;
|
---|
| 175 | uint16_t result;
|
---|
| 176 |
|
---|
[331] | 177 | if ((mrb == NULL)||(dbg == NULL)||(file == NULL)) {
|
---|
[270] | 178 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[331] | 181 | if (dbg->bpnum >= MAX_BREAKPOINT) {
|
---|
[270] | 182 | return MRB_DEBUG_BREAK_NUM_OVER;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[331] | 185 | if (dbg->next_bpno > MAX_BREAKPOINTNO) {
|
---|
[270] | 186 | return MRB_DEBUG_BREAK_NO_OVER;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | /* file and lineno check (line type mrb_debug_line_ary only.) */
|
---|
[439] | 190 | result = check_file_lineno(mrb, dbg->root_irep, file, lineno);
|
---|
[331] | 191 | if (result == 0) {
|
---|
[270] | 192 | return MRB_DEBUG_BREAK_INVALID_FILE;
|
---|
[331] | 193 | }
|
---|
| 194 | else if (result == MRB_DEBUG_BP_FILE_OK) {
|
---|
[270] | 195 | return MRB_DEBUG_BREAK_INVALID_LINENO;
|
---|
[331] | 196 | }
|
---|
[270] | 197 |
|
---|
[439] | 198 | set_file = (char*)mrb_malloc(mrb, strlen(file) + 1);
|
---|
[270] | 199 |
|
---|
| 200 | index = dbg->bpnum;
|
---|
| 201 | dbg->bp[index].bpno = dbg->next_bpno;
|
---|
| 202 | dbg->next_bpno++;
|
---|
| 203 | dbg->bp[index].enable = TRUE;
|
---|
| 204 | dbg->bp[index].type = MRB_DEBUG_BPTYPE_LINE;
|
---|
| 205 | dbg->bp[index].point.linepoint.lineno = lineno;
|
---|
| 206 | dbg->bpnum++;
|
---|
| 207 |
|
---|
| 208 | strncpy(set_file, file, strlen(file) + 1);
|
---|
| 209 |
|
---|
| 210 | dbg->bp[index].point.linepoint.file = set_file;
|
---|
| 211 |
|
---|
| 212 | return dbg->bp[index].bpno;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | int32_t
|
---|
[331] | 216 | mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *class_name, const char *method_name)
|
---|
[270] | 217 | {
|
---|
| 218 | int32_t index;
|
---|
| 219 | char* set_class;
|
---|
| 220 | char* set_method;
|
---|
| 221 |
|
---|
[331] | 222 | if ((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
|
---|
[270] | 223 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[331] | 226 | if (dbg->bpnum >= MAX_BREAKPOINT) {
|
---|
[270] | 227 | return MRB_DEBUG_BREAK_NUM_OVER;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[331] | 230 | if (dbg->next_bpno > MAX_BREAKPOINTNO) {
|
---|
[270] | 231 | return MRB_DEBUG_BREAK_NO_OVER;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[331] | 234 | if (class_name != NULL) {
|
---|
[439] | 235 | set_class = (char*)mrb_malloc(mrb, strlen(class_name) + 1);
|
---|
[270] | 236 | strncpy(set_class, class_name, strlen(class_name) + 1);
|
---|
| 237 | }
|
---|
| 238 | else {
|
---|
| 239 | set_class = NULL;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[439] | 242 | set_method = (char*)mrb_malloc(mrb, strlen(method_name) + 1);
|
---|
[270] | 243 |
|
---|
| 244 | strncpy(set_method, method_name, strlen(method_name) + 1);
|
---|
| 245 |
|
---|
| 246 | index = dbg->bpnum;
|
---|
| 247 | dbg->bp[index].bpno = dbg->next_bpno;
|
---|
| 248 | dbg->next_bpno++;
|
---|
| 249 | dbg->bp[index].enable = TRUE;
|
---|
| 250 | dbg->bp[index].type = MRB_DEBUG_BPTYPE_METHOD;
|
---|
| 251 | dbg->bp[index].point.methodpoint.method_name = set_method;
|
---|
| 252 | dbg->bp[index].point.methodpoint.class_name = set_class;
|
---|
| 253 | dbg->bpnum++;
|
---|
| 254 |
|
---|
| 255 | return dbg->bp[index].bpno;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | int32_t
|
---|
[331] | 259 | mrb_debug_get_breaknum(mrb_state *mrb, mrb_debug_context *dbg)
|
---|
[270] | 260 | {
|
---|
[331] | 261 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 262 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | return dbg->bpnum;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[331] | 268 | int32_t
|
---|
| 269 | mrb_debug_get_break_all(mrb_state *mrb, mrb_debug_context *dbg, uint32_t size, mrb_debug_breakpoint *bp)
|
---|
[270] | 270 | {
|
---|
| 271 | uint32_t get_size = 0;
|
---|
| 272 |
|
---|
[331] | 273 | if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
|
---|
[270] | 274 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[331] | 277 | if (dbg->bpnum >= size) {
|
---|
[270] | 278 | get_size = size;
|
---|
| 279 | }
|
---|
| 280 | else {
|
---|
| 281 | get_size = dbg->bpnum;
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | memcpy(bp, dbg->bp, sizeof(mrb_debug_breakpoint) * get_size);
|
---|
| 285 |
|
---|
| 286 | return get_size;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | int32_t
|
---|
[331] | 290 | mrb_debug_get_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_debug_breakpoint *bp)
|
---|
[270] | 291 | {
|
---|
[331] | 292 | int32_t index;
|
---|
[270] | 293 |
|
---|
[331] | 294 | if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {
|
---|
[270] | 295 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | index = get_break_index(dbg, bpno);
|
---|
[331] | 299 | if (index == MRB_DEBUG_BREAK_INVALID_NO) {
|
---|
[270] | 300 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | bp->bpno = dbg->bp[index].bpno;
|
---|
| 304 | bp->enable = dbg->bp[index].enable;
|
---|
| 305 | bp->point = dbg->bp[index].point;
|
---|
| 306 | bp->type = dbg->bp[index].type;
|
---|
| 307 |
|
---|
| 308 | return 0;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
[331] | 311 | int32_t
|
---|
| 312 | mrb_debug_delete_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
|
---|
[270] | 313 | {
|
---|
| 314 | uint32_t i;
|
---|
| 315 | int32_t index;
|
---|
| 316 |
|
---|
[331] | 317 | if ((mrb == NULL) ||(dbg == NULL)) {
|
---|
[270] | 318 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | index = get_break_index(dbg, bpno);
|
---|
[331] | 322 | if (index == MRB_DEBUG_BREAK_INVALID_NO) {
|
---|
[270] | 323 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | free_breakpoint(mrb, &dbg->bp[index]);
|
---|
| 327 |
|
---|
| 328 | for(i = index ; i < dbg->bpnum; i++) {
|
---|
[331] | 329 | if ((i + 1) == dbg->bpnum) {
|
---|
[270] | 330 | memset(&dbg->bp[i], 0, sizeof(mrb_debug_breakpoint));
|
---|
| 331 | }
|
---|
| 332 | else {
|
---|
| 333 | memcpy(&dbg->bp[i], &dbg->bp[i + 1], sizeof(mrb_debug_breakpoint));
|
---|
| 334 | }
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | dbg->bpnum--;
|
---|
| 338 |
|
---|
| 339 | return MRB_DEBUG_OK;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
[331] | 342 | int32_t
|
---|
| 343 | mrb_debug_delete_break_all(mrb_state *mrb, mrb_debug_context *dbg)
|
---|
[270] | 344 | {
|
---|
| 345 | uint32_t i;
|
---|
| 346 |
|
---|
[331] | 347 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 348 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | for(i = 0 ; i < dbg->bpnum ; i++) {
|
---|
| 352 | free_breakpoint(mrb, &dbg->bp[i]);
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | dbg->bpnum = 0;
|
---|
| 356 |
|
---|
| 357 | return MRB_DEBUG_OK;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
[331] | 360 | int32_t
|
---|
| 361 | mrb_debug_enable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
|
---|
[270] | 362 | {
|
---|
| 363 | int32_t index = 0;
|
---|
| 364 |
|
---|
[331] | 365 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 366 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 367 | }
|
---|
| 368 |
|
---|
| 369 | index = get_break_index(dbg, bpno);
|
---|
[331] | 370 | if (index == MRB_DEBUG_BREAK_INVALID_NO) {
|
---|
[270] | 371 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | dbg->bp[index].enable = TRUE;
|
---|
| 375 |
|
---|
| 376 | return MRB_DEBUG_OK;
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | int32_t
|
---|
[331] | 380 | mrb_debug_enable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
|
---|
[270] | 381 | {
|
---|
| 382 | uint32_t i;
|
---|
| 383 |
|
---|
[331] | 384 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 385 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | for(i = 0 ; i < dbg->bpnum; i++) {
|
---|
| 389 | dbg->bp[i].enable = TRUE;
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | return MRB_DEBUG_OK;
|
---|
| 393 | }
|
---|
| 394 |
|
---|
[331] | 395 | int32_t
|
---|
| 396 | mrb_debug_disable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
|
---|
[270] | 397 | {
|
---|
| 398 | int32_t index = 0;
|
---|
| 399 |
|
---|
[331] | 400 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 401 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | index = get_break_index(dbg, bpno);
|
---|
[331] | 405 | if (index == MRB_DEBUG_BREAK_INVALID_NO) {
|
---|
[270] | 406 | return MRB_DEBUG_BREAK_INVALID_NO;
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | dbg->bp[index].enable = FALSE;
|
---|
| 410 |
|
---|
| 411 | return MRB_DEBUG_OK;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
[331] | 414 | int32_t
|
---|
| 415 | mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
|
---|
[270] | 416 | {
|
---|
| 417 | uint32_t i;
|
---|
| 418 |
|
---|
[331] | 419 | if ((mrb == NULL) || (dbg == NULL)) {
|
---|
[270] | 420 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | for(i = 0 ; i < dbg->bpnum; i++) {
|
---|
| 424 | dbg->bp[i].enable = FALSE;
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | return MRB_DEBUG_OK;
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 | static mrb_bool
|
---|
[439] | 431 | check_start_pc_for_line(mrb_state *mrb, mrb_irep *irep, const mrb_code *pc, uint16_t line)
|
---|
[270] | 432 | {
|
---|
[331] | 433 | if (pc > irep->iseq) {
|
---|
[439] | 434 | if (line == mrb_debug_get_line(mrb, irep, pc - irep->iseq - 1)) {
|
---|
[270] | 435 | return FALSE;
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
| 438 | return TRUE;
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | int32_t
|
---|
[331] | 442 | mrb_debug_check_breakpoint_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t line)
|
---|
[270] | 443 | {
|
---|
| 444 | mrb_debug_breakpoint *bp;
|
---|
| 445 | mrb_debug_linepoint *line_p;
|
---|
[331] | 446 | uint32_t i;
|
---|
[270] | 447 |
|
---|
[331] | 448 | if ((mrb == NULL) || (dbg == NULL) || (file == NULL) || (line <= 0)) {
|
---|
[270] | 449 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 450 | }
|
---|
| 451 |
|
---|
[439] | 452 | if (!check_start_pc_for_line(mrb, dbg->irep, dbg->pc, line)) {
|
---|
[270] | 453 | return MRB_DEBUG_OK;
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | bp = dbg->bp;
|
---|
| 457 | for(i=0; i<dbg->bpnum; i++) {
|
---|
| 458 | switch (bp->type) {
|
---|
| 459 | case MRB_DEBUG_BPTYPE_LINE:
|
---|
[331] | 460 | if (bp->enable == TRUE) {
|
---|
[270] | 461 | line_p = &bp->point.linepoint;
|
---|
[331] | 462 | if ((strcmp(line_p->file, file) == 0) && (line_p->lineno == line)) {
|
---|
[270] | 463 | return bp->bpno;
|
---|
| 464 | }
|
---|
| 465 | }
|
---|
| 466 | break;
|
---|
| 467 | case MRB_DEBUG_BPTYPE_METHOD:
|
---|
| 468 | break;
|
---|
| 469 | case MRB_DEBUG_BPTYPE_NONE:
|
---|
| 470 | default:
|
---|
| 471 | return MRB_DEBUG_OK;
|
---|
| 472 | }
|
---|
| 473 | bp++;
|
---|
| 474 | }
|
---|
| 475 | return MRB_DEBUG_OK;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 |
|
---|
[331] | 479 | int32_t
|
---|
| 480 | mrb_debug_check_breakpoint_method(mrb_state *mrb, mrb_debug_context *dbg, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
|
---|
[270] | 481 | {
|
---|
| 482 | mrb_debug_breakpoint *bp;
|
---|
| 483 | int32_t bpno;
|
---|
[331] | 484 | uint32_t i;
|
---|
[270] | 485 |
|
---|
[331] | 486 | if ((mrb == NULL) || (dbg == NULL) || (class_obj == NULL)) {
|
---|
[270] | 487 | return MRB_DEBUG_INVALID_ARGUMENT;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
| 490 | bp = dbg->bp;
|
---|
| 491 | for(i=0; i<dbg->bpnum; i++) {
|
---|
[331] | 492 | if (bp->type == MRB_DEBUG_BPTYPE_METHOD) {
|
---|
| 493 | if (bp->enable == TRUE) {
|
---|
[270] | 494 | bpno = compare_break_method(mrb, bp, class_obj, method_sym, isCfunc);
|
---|
[331] | 495 | if (bpno > 0) {
|
---|
[270] | 496 | return bpno;
|
---|
| 497 | }
|
---|
| 498 | }
|
---|
| 499 | }
|
---|
[331] | 500 | else if (bp->type == MRB_DEBUG_BPTYPE_NONE) {
|
---|
[270] | 501 | break;
|
---|
| 502 | }
|
---|
| 503 | bp++;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | return 0;
|
---|
| 507 | }
|
---|