Mercurial > repos > blastem
comparison debug.c @ 2190:59e0dcc01b2c
Add 'if' and 'while' debugger commands
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 20 Aug 2022 12:08:01 -0700 |
parents | 6b33ce6bc740 |
children | d87a76afbd8a |
comparison
equal
deleted
inserted
replaced
2189:6b33ce6bc740 | 2190:59e0dcc01b2c |
---|---|
1473 cmd->block.commands = NULL; | 1473 cmd->block.commands = NULL; |
1474 cmd->block.num_commands = 0; | 1474 cmd->block.num_commands = 0; |
1475 return 1; | 1475 return 1; |
1476 } | 1476 } |
1477 | 1477 |
1478 static uint8_t execute_block(debug_root *root, command_block * block) | |
1479 { | |
1480 uint8_t debugging = 1; | |
1481 for (int i = 0; i < block->num_commands; i++) | |
1482 { | |
1483 debugging = run_command(root, block->commands + i) && debugging; | |
1484 } | |
1485 return debugging; | |
1486 } | |
1487 | |
1488 static uint8_t cmd_if(debug_root *root, parsed_command *cmd) | |
1489 { | |
1490 return execute_block(root, cmd->args[0].value ? &cmd->block : &cmd->else_block); | |
1491 } | |
1492 | |
1493 static uint8_t cmd_while(debug_root *root, parsed_command *cmd) | |
1494 { | |
1495 if (!cmd->args[0].value) { | |
1496 return execute_block(root, &cmd->else_block); | |
1497 } | |
1498 int debugging = 1; | |
1499 do { | |
1500 debugging = execute_block(root, &cmd->block) && debugging; | |
1501 if (!eval_expr(root, cmd->args[0].parsed, &cmd->args[0].value)) { | |
1502 fprintf(stderr, "Failed to eval %s\n", cmd->args[0].raw); | |
1503 return 1; | |
1504 } | |
1505 } while (cmd->args[0].value); | |
1506 return debugging; | |
1507 } | |
1508 | |
1478 const char *expr_type_names[] = { | 1509 const char *expr_type_names[] = { |
1479 "EXPR_NONE", | 1510 "EXPR_NONE", |
1480 "EXPR_SCALAR", | 1511 "EXPR_SCALAR", |
1481 "EXPR_UNARY", | 1512 "EXPR_UNARY", |
1482 "EXPR_BINARY", | 1513 "EXPR_BINARY", |
2029 .desc = "Makes breakpoint BREAKPOINT conditional on the value of EXPRESSION or removes a condition if EXPRESSION is omitted", | 2060 .desc = "Makes breakpoint BREAKPOINT conditional on the value of EXPRESSION or removes a condition if EXPRESSION is omitted", |
2030 .impl = cmd_condition, | 2061 .impl = cmd_condition, |
2031 .min_args = 1, | 2062 .min_args = 1, |
2032 .max_args = 2, | 2063 .max_args = 2, |
2033 .skip_eval = 1 | 2064 .skip_eval = 1 |
2065 }, | |
2066 { | |
2067 .names = (const char *[]){ | |
2068 "if", NULL | |
2069 }, | |
2070 .usage = "if CONDITION", | |
2071 .desc = "If the condition is true, the following block is executed. Otherwise the else block is executed if present", | |
2072 .impl = cmd_if, | |
2073 .min_args = 1, | |
2074 .max_args = 1, | |
2075 .has_block = 1, | |
2076 .accepts_else = 1 | |
2077 }, | |
2078 { | |
2079 .names = (const char *[]){ | |
2080 "while", NULL | |
2081 }, | |
2082 .usage = "while CONDITION", | |
2083 .desc = "The following block is executed repeatedly until the condition is false. If the condition is false at the start, the else block is executed if present", | |
2084 .impl = cmd_while, | |
2085 .min_args = 1, | |
2086 .max_args = 1, | |
2087 .has_block = 1, | |
2088 .accepts_else = 1 | |
2034 } | 2089 } |
2035 }; | 2090 }; |
2036 #define NUM_COMMON (sizeof(common_commands)/sizeof(*common_commands)) | 2091 #define NUM_COMMON (sizeof(common_commands)/sizeof(*common_commands)) |
2037 | 2092 |
2038 command_def m68k_commands[] = { | 2093 command_def m68k_commands[] = { |