- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
r321 r331 5 5 6 6 #include <string.h> 7 #include "mruby.h"8 #include "mruby/irep.h"7 #include <mruby.h> 8 #include <mruby/irep.h> 9 9 #include "mrdb.h" 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"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> 15 15 #include "mrdberror.h" 16 16 #include "apibreak.h" … … 21 21 22 22 static uint16_t 23 check_lineno( mrb_irep_debug_info_file *info_file, uint16_t lineno)23 check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno) 24 24 { 25 25 uint32_t count = info_file->line_entry_count; 26 26 uint16_t l_idx; 27 27 28 if ( info_file->line_type == mrb_debug_line_ary) {28 if (info_file->line_type == mrb_debug_line_ary) { 29 29 for (l_idx = 0; l_idx < count; ++l_idx) { 30 if (lineno == info_file->lines.ary[l_idx]) {30 if (lineno == info_file->lines.ary[l_idx]) { 31 31 return lineno; 32 32 } 33 33 } 34 } else { 34 } 35 else { 35 36 for (l_idx = 0; l_idx < count; ++l_idx) { 36 if (lineno == info_file->lines.flat_map[l_idx].line) {37 if (lineno == info_file->lines.flat_map[l_idx].line) { 37 38 return lineno; 38 39 } … … 44 45 45 46 static int32_t 46 get_break_index( mrb_debug_context *dbg, int32_t bpno)47 get_break_index(mrb_debug_context *dbg, uint32_t bpno) 47 48 { 48 49 uint32_t i; … … 51 52 52 53 for(i = 0 ; i < dbg->bpnum; i++) { 53 if (dbg->bp[i].bpno == bpno) {54 if (dbg->bp[i].bpno == bpno) { 54 55 hit = TRUE; 55 56 index = i; … … 58 59 } 59 60 60 if (hit == FALSE) {61 if (hit == FALSE) { 61 62 return MRB_DEBUG_BREAK_INVALID_NO; 62 63 } … … 66 67 67 68 static void 68 free_breakpoint( mrb_state *mrb, mrb_debug_breakpoint *bp)69 free_breakpoint(mrb_state *mrb, mrb_debug_breakpoint *bp) 69 70 { 70 71 switch(bp->type) { … … 74 75 case MRB_DEBUG_BPTYPE_METHOD: 75 76 mrb_free(mrb, (void*)bp->point.methodpoint.method_name); 76 if (bp->point.methodpoint.class_name != NULL) {77 if (bp->point.methodpoint.class_name != NULL) { 77 78 mrb_free(mrb, (void*)bp->point.methodpoint.class_name); 78 79 } … … 84 85 85 86 static uint16_t 86 check_file_lineno( struct mrb_irep *irep, const char *file, uint16_t lineno)87 check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno) 87 88 { 88 89 mrb_irep_debug_info_file *info_file; … … 94 95 for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) { 95 96 info_file = irep->debug_info->files[f_idx]; 96 if (!strcmp(info_file->filename, file)) {97 if (!strcmp(info_file->filename, file)) { 97 98 result = MRB_DEBUG_BP_FILE_OK; 98 99 99 fix_lineno = check_lineno( info_file, lineno);100 if (fix_lineno != 0) {100 fix_lineno = check_lineno(info_file, lineno); 101 if (fix_lineno != 0) { 101 102 return result | MRB_DEBUG_BP_LINENO_OK; 102 103 } 103 104 } 104 for ( i=0; i < irep->rlen; ++i) {105 for (i=0; i < irep->rlen; ++i) { 105 106 result |= check_file_lineno(irep->reps[i], file, lineno); 106 if (result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {107 if (result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) { 107 108 return result; 108 109 } … … 113 114 114 115 static const char* 115 get_class_name( mrb_state *mrb, struct RClass *class_obj)116 get_class_name(mrb_state *mrb, struct RClass *class_obj) 116 117 { 117 118 struct RClass *outer; … … 124 125 125 126 static int32_t 126 compare_break_method( mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)127 compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc) 127 128 { 128 129 const char* class_name; … … 138 139 139 140 method_p = &bp->point.methodpoint; 140 if (strcmp(method_p->method_name, method_name) == 0) {141 if (strcmp(method_p->method_name, method_name) == 0) { 141 142 class_name = get_class_name(mrb, class_obj); 142 if (class_name == NULL) {143 if (method_p->class_name == NULL) {143 if (class_name == NULL) { 144 if (method_p->class_name == NULL) { 144 145 return bp->bpno; 145 146 } 146 147 } 147 else if (method_p->class_name != NULL) {148 else if (method_p->class_name != NULL) { 148 149 m = mrb_method_search_vm(mrb, &class_obj, method_sym); 149 if (m == NULL) {150 if (m == NULL) { 150 151 return MRB_DEBUG_OK; 151 152 } 152 if (MRB_PROC_CFUNC_P(m)) {153 if (MRB_PROC_CFUNC_P(m)) { 153 154 *isCfunc = TRUE; 154 155 } 155 156 156 157 is_defined = mrb_class_defined(mrb, method_p->class_name); 157 if (is_defined == FALSE) {158 if (is_defined == FALSE) { 158 159 return MRB_DEBUG_OK; 159 160 } … … 162 163 ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name)); 163 164 m = mrb_method_search_vm(mrb, &sc, ssym); 164 if (m == NULL) {165 if (m == NULL) { 165 166 return MRB_DEBUG_OK; 166 167 } … … 168 169 class_name = get_class_name(mrb, class_obj); 169 170 sn = get_class_name(mrb, sc); 170 if (strcmp(sn, class_name) == 0) {171 if (strcmp(sn, class_name) == 0) { 171 172 return bp->bpno; 172 173 } … … 177 178 178 179 int32_t 179 mrb_debug_set_break_line( 180 mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t lineno) 180 181 { 181 182 int32_t index; … … 183 184 uint16_t result; 184 185 185 if ((mrb == NULL)||(dbg == NULL)||(file == NULL)) {186 return MRB_DEBUG_INVALID_ARGUMENT; 187 } 188 189 if (dbg->bpnum >= MAX_BREAKPOINT) {186 if ((mrb == NULL)||(dbg == NULL)||(file == NULL)) { 187 return MRB_DEBUG_INVALID_ARGUMENT; 188 } 189 190 if (dbg->bpnum >= MAX_BREAKPOINT) { 190 191 return MRB_DEBUG_BREAK_NUM_OVER; 191 192 } 192 193 193 if (dbg->next_bpno > MAX_BREAKPOINTNO) {194 if (dbg->next_bpno > MAX_BREAKPOINTNO) { 194 195 return MRB_DEBUG_BREAK_NO_OVER; 195 196 } 196 197 197 198 /* file and lineno check (line type mrb_debug_line_ary only.) */ 198 result = check_file_lineno( dbg->root_irep, file, lineno);199 if (result == 0) {199 result = check_file_lineno(dbg->root_irep, file, lineno); 200 if (result == 0) { 200 201 return MRB_DEBUG_BREAK_INVALID_FILE; 201 }else if(result == MRB_DEBUG_BP_FILE_OK) { 202 } 203 else if (result == MRB_DEBUG_BP_FILE_OK) { 202 204 return MRB_DEBUG_BREAK_INVALID_LINENO; 203 } 205 } 204 206 205 207 set_file = mrb_malloc(mrb, strlen(file) + 1); … … 221 223 222 224 int32_t 223 mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char *class_name, const char *method_name)225 mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *class_name, const char *method_name) 224 226 { 225 227 int32_t index; … … 227 229 char* set_method; 228 230 229 if ((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {230 return MRB_DEBUG_INVALID_ARGUMENT; 231 } 232 233 if (dbg->bpnum >= MAX_BREAKPOINT) {231 if ((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) { 232 return MRB_DEBUG_INVALID_ARGUMENT; 233 } 234 235 if (dbg->bpnum >= MAX_BREAKPOINT) { 234 236 return MRB_DEBUG_BREAK_NUM_OVER; 235 237 } 236 238 237 if (dbg->next_bpno > MAX_BREAKPOINTNO) {239 if (dbg->next_bpno > MAX_BREAKPOINTNO) { 238 240 return MRB_DEBUG_BREAK_NO_OVER; 239 241 } 240 242 241 if (class_name != NULL) {243 if (class_name != NULL) { 242 244 set_class = mrb_malloc(mrb, strlen(class_name) + 1); 243 245 strncpy(set_class, class_name, strlen(class_name) + 1); … … 264 266 265 267 int32_t 266 mrb_debug_get_breaknum( mrb_state *mrb, mrb_debug_context *dbg)267 { 268 if ((mrb == NULL) || (dbg == NULL)) {268 mrb_debug_get_breaknum(mrb_state *mrb, mrb_debug_context *dbg) 269 { 270 if ((mrb == NULL) || (dbg == NULL)) { 269 271 return MRB_DEBUG_INVALID_ARGUMENT; 270 272 } … … 273 275 } 274 276 275 int32_t 276 mrb_debug_get_break_all( mrb_state *mrb, mrb_debug_context *dbg, uint32_t size, mrb_debug_breakpoint *bp)277 int32_t 278 mrb_debug_get_break_all(mrb_state *mrb, mrb_debug_context *dbg, uint32_t size, mrb_debug_breakpoint *bp) 277 279 { 278 280 uint32_t get_size = 0; 279 281 280 if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {281 return MRB_DEBUG_INVALID_ARGUMENT; 282 } 283 284 if (dbg->bpnum >= size) {282 if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) { 283 return MRB_DEBUG_INVALID_ARGUMENT; 284 } 285 286 if (dbg->bpnum >= size) { 285 287 get_size = size; 286 288 } … … 295 297 296 298 int32_t 297 mrb_debug_get_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_debug_breakpoint *bp)298 { 299 uint32_t index;300 301 if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) {299 mrb_debug_get_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno, mrb_debug_breakpoint *bp) 300 { 301 int32_t index; 302 303 if ((mrb == NULL) || (dbg == NULL) || (bp == NULL)) { 302 304 return MRB_DEBUG_INVALID_ARGUMENT; 303 305 } 304 306 305 307 index = get_break_index(dbg, bpno); 306 if (index == MRB_DEBUG_BREAK_INVALID_NO) {308 if (index == MRB_DEBUG_BREAK_INVALID_NO) { 307 309 return MRB_DEBUG_BREAK_INVALID_NO; 308 310 } … … 316 318 } 317 319 318 int32_t 319 mrb_debug_delete_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)320 int32_t 321 mrb_debug_delete_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno) 320 322 { 321 323 uint32_t i; 322 324 int32_t index; 323 325 324 if ((mrb == NULL) ||(dbg == NULL)) {326 if ((mrb == NULL) ||(dbg == NULL)) { 325 327 return MRB_DEBUG_INVALID_ARGUMENT; 326 328 } 327 329 328 330 index = get_break_index(dbg, bpno); 329 if (index == MRB_DEBUG_BREAK_INVALID_NO) {331 if (index == MRB_DEBUG_BREAK_INVALID_NO) { 330 332 return MRB_DEBUG_BREAK_INVALID_NO; 331 333 } … … 334 336 335 337 for(i = index ; i < dbg->bpnum; i++) { 336 if ((i + 1) == dbg->bpnum) {338 if ((i + 1) == dbg->bpnum) { 337 339 memset(&dbg->bp[i], 0, sizeof(mrb_debug_breakpoint)); 338 340 } … … 347 349 } 348 350 349 int32_t 350 mrb_debug_delete_break_all( mrb_state *mrb, mrb_debug_context *dbg)351 { 352 uint32_t i; 353 354 if ((mrb == NULL) || (dbg == NULL)) {351 int32_t 352 mrb_debug_delete_break_all(mrb_state *mrb, mrb_debug_context *dbg) 353 { 354 uint32_t i; 355 356 if ((mrb == NULL) || (dbg == NULL)) { 355 357 return MRB_DEBUG_INVALID_ARGUMENT; 356 358 } … … 365 367 } 366 368 367 int32_t 368 mrb_debug_enable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)369 int32_t 370 mrb_debug_enable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno) 369 371 { 370 372 int32_t index = 0; 371 373 372 if ((mrb == NULL) || (dbg == NULL)) {374 if ((mrb == NULL) || (dbg == NULL)) { 373 375 return MRB_DEBUG_INVALID_ARGUMENT; 374 376 } 375 377 376 378 index = get_break_index(dbg, bpno); 377 if (index == MRB_DEBUG_BREAK_INVALID_NO) {379 if (index == MRB_DEBUG_BREAK_INVALID_NO) { 378 380 return MRB_DEBUG_BREAK_INVALID_NO; 379 381 } … … 385 387 386 388 int32_t 387 mrb_debug_enable_break_all( mrb_state *mrb, mrb_debug_context *dbg)388 { 389 uint32_t i; 390 391 if ((mrb == NULL) || (dbg == NULL)) {389 mrb_debug_enable_break_all(mrb_state *mrb, mrb_debug_context *dbg) 390 { 391 uint32_t i; 392 393 if ((mrb == NULL) || (dbg == NULL)) { 392 394 return MRB_DEBUG_INVALID_ARGUMENT; 393 395 } … … 400 402 } 401 403 402 int32_t 403 mrb_debug_disable_break( mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)404 int32_t 405 mrb_debug_disable_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno) 404 406 { 405 407 int32_t index = 0; 406 408 407 if ((mrb == NULL) || (dbg == NULL)) {409 if ((mrb == NULL) || (dbg == NULL)) { 408 410 return MRB_DEBUG_INVALID_ARGUMENT; 409 411 } 410 412 411 413 index = get_break_index(dbg, bpno); 412 if (index == MRB_DEBUG_BREAK_INVALID_NO) {414 if (index == MRB_DEBUG_BREAK_INVALID_NO) { 413 415 return MRB_DEBUG_BREAK_INVALID_NO; 414 416 } … … 419 421 } 420 422 421 int32_t 422 mrb_debug_disable_break_all( mrb_state *mrb, mrb_debug_context *dbg)423 { 424 uint32_t i; 425 426 if ((mrb == NULL) || (dbg == NULL)) {423 int32_t 424 mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg) 425 { 426 uint32_t i; 427 428 if ((mrb == NULL) || (dbg == NULL)) { 427 429 return MRB_DEBUG_INVALID_ARGUMENT; 428 430 } … … 436 438 437 439 static mrb_bool 438 check_start_pc_for_line( mrb_irep *irep, mrb_code *pc, uint16_t line)439 { 440 if ( pc > irep->iseq) {441 if (line == mrb_debug_get_line(irep, (uint32_t)(pc - irep->iseq - 1))) {440 check_start_pc_for_line(mrb_irep *irep, mrb_code *pc, uint16_t line) 441 { 442 if (pc > irep->iseq) { 443 if (line == mrb_debug_get_line(irep, (uint32_t)(pc - irep->iseq - 1))) { 442 444 return FALSE; 443 445 } … … 447 449 448 450 int32_t 449 mrb_debug_check_breakpoint_line( mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t line)451 mrb_debug_check_breakpoint_line(mrb_state *mrb, mrb_debug_context *dbg, const char *file, uint16_t line) 450 452 { 451 453 mrb_debug_breakpoint *bp; 452 454 mrb_debug_linepoint *line_p; 453 int i;454 455 if ((mrb == NULL) || (dbg == NULL) || (file == NULL) || (line <= 0)) {456 return MRB_DEBUG_INVALID_ARGUMENT; 457 } 458 459 if (!check_start_pc_for_line(dbg->irep, dbg->pc, line)) {455 uint32_t i; 456 457 if ((mrb == NULL) || (dbg == NULL) || (file == NULL) || (line <= 0)) { 458 return MRB_DEBUG_INVALID_ARGUMENT; 459 } 460 461 if (!check_start_pc_for_line(dbg->irep, dbg->pc, line)) { 460 462 return MRB_DEBUG_OK; 461 463 } … … 465 467 switch (bp->type) { 466 468 case MRB_DEBUG_BPTYPE_LINE: 467 if (bp->enable == TRUE) {469 if (bp->enable == TRUE) { 468 470 line_p = &bp->point.linepoint; 469 if ((strcmp(line_p->file, file) == 0) && (line_p->lineno == line)) {471 if ((strcmp(line_p->file, file) == 0) && (line_p->lineno == line)) { 470 472 return bp->bpno; 471 473 } … … 484 486 485 487 486 int32_t 487 mrb_debug_check_breakpoint_method( mrb_state *mrb, mrb_debug_context *dbg, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)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) 488 490 { 489 491 mrb_debug_breakpoint *bp; 490 492 int32_t bpno; 491 int i;492 493 if ((mrb == NULL) || (dbg == NULL) || (class_obj == NULL)) {493 uint32_t i; 494 495 if ((mrb == NULL) || (dbg == NULL) || (class_obj == NULL)) { 494 496 return MRB_DEBUG_INVALID_ARGUMENT; 495 497 } … … 497 499 bp = dbg->bp; 498 500 for(i=0; i<dbg->bpnum; i++) { 499 if (bp->type == MRB_DEBUG_BPTYPE_METHOD) {500 if (bp->enable == TRUE) {501 if (bp->type == MRB_DEBUG_BPTYPE_METHOD) { 502 if (bp->enable == TRUE) { 501 503 bpno = compare_break_method(mrb, bp, class_obj, method_sym, isCfunc); 502 if (bpno > 0) {504 if (bpno > 0) { 503 505 return bpno; 504 506 } 505 507 } 506 508 } 507 else if (bp->type == MRB_DEBUG_BPTYPE_NONE) {509 else if (bp->type == MRB_DEBUG_BPTYPE_NONE) { 508 510 break; 509 511 }
Note:
See TracChangeset
for help on using the changeset viewer.