Mercurial > repos > blastem
comparison debug.h @ 2178:f6d5bde4d07f
Finish debugger refactor started with expression parser changes
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 13 Aug 2022 19:16:30 -0700 |
parents | 8c28c5466d70 |
children | 2d7f8195be3b |
comparison
equal
deleted
inserted
replaced
2177:44596610b2a0 | 2178:f6d5bde4d07f |
---|---|
1 #ifndef DEBUG_H_ | 1 #ifndef DEBUG_H_ |
2 #define DEBUG_H_ | 2 #define DEBUG_H_ |
3 | 3 |
4 #include <stdint.h> | 4 #include <stdint.h> |
5 #include "tern.h" | |
5 #include "m68k_core.h" | 6 #include "m68k_core.h" |
6 #ifdef NEW_CORE | 7 #ifdef NEW_CORE |
7 #include "z80.h" | 8 #include "z80.h" |
8 #else | 9 #else |
9 #include "z80_to_x86.h" | 10 #include "z80_to_x86.h" |
10 #endif | 11 #endif |
11 | 12 |
13 typedef enum { | |
14 TOKEN_NONE, | |
15 TOKEN_NUM, | |
16 TOKEN_NAME, | |
17 TOKEN_OPER, | |
18 TOKEN_SIZE, | |
19 TOKEN_LBRACKET, | |
20 TOKEN_RBRACKET, | |
21 TOKEN_LPAREN, | |
22 TOKEN_RPAREN | |
23 } token_type; | |
24 | |
25 typedef struct { | |
26 token_type type; | |
27 union { | |
28 char *str; | |
29 char op[3]; | |
30 uint32_t num; | |
31 } v; | |
32 } token; | |
33 | |
34 typedef enum { | |
35 EXPR_NONE, | |
36 EXPR_SCALAR, | |
37 EXPR_UNARY, | |
38 EXPR_BINARY, | |
39 EXPR_SIZE, | |
40 EXPR_MEM | |
41 } expr_type; | |
42 | |
43 typedef struct expr expr; | |
44 | |
45 struct expr { | |
46 expr_type type; | |
47 expr *left; | |
48 expr *right; | |
49 token op; | |
50 }; | |
51 | |
52 typedef struct { | |
53 char *raw; | |
54 expr *parsed; | |
55 uint32_t value; | |
56 } command_arg; | |
57 | |
58 typedef struct debug_root debug_root; | |
59 typedef uint8_t (*raw_cmd)(debug_root *root, char *format, char *param); | |
60 typedef uint8_t (*cmd)(debug_root *root, char *format, int num_args, command_arg *args); | |
61 | |
62 typedef struct { | |
63 const char **names; | |
64 const char *usage; | |
65 const char *desc; | |
66 raw_cmd raw_impl; | |
67 cmd impl; | |
68 int min_args; | |
69 int max_args; | |
70 uint8_t skip_eval; | |
71 uint8_t visited; | |
72 } command_def; | |
73 | |
12 typedef struct disp_def { | 74 typedef struct disp_def { |
13 struct disp_def * next; | 75 struct disp_def *next; |
14 char * param; | 76 char *format; |
77 int num_args; | |
78 command_arg *args; | |
15 uint32_t index; | 79 uint32_t index; |
16 char format_char; | |
17 } disp_def; | 80 } disp_def; |
18 | 81 |
82 typedef struct { | |
83 command_def *def; | |
84 char *format; | |
85 char *raw; | |
86 command_arg *args; | |
87 int num_args; | |
88 } parsed_command; | |
89 | |
19 typedef struct bp_def { | 90 typedef struct bp_def { |
20 struct bp_def *next; | 91 struct bp_def *next; |
21 char *commands; | 92 parsed_command *commands; |
22 uint32_t address; | 93 uint32_t num_commands; |
23 uint32_t index; | 94 uint32_t address; |
95 uint32_t index; | |
24 } bp_def; | 96 } bp_def; |
25 | 97 |
26 typedef struct debug_root debug_root; | |
27 typedef uint8_t (*resolver)(debug_root *root, const char *name, uint32_t *out); | 98 typedef uint8_t (*resolver)(debug_root *root, const char *name, uint32_t *out); |
99 typedef uint8_t (*setter)(debug_root *root, const char *name, uint32_t value); | |
28 typedef uint8_t (*reader)(debug_root *root, uint32_t *out, char size); | 100 typedef uint8_t (*reader)(debug_root *root, uint32_t *out, char size); |
101 typedef uint8_t (*writer)(debug_root *root, uint32_t address, uint32_t value, char size); | |
29 | 102 |
30 struct debug_root { | 103 struct debug_root { |
31 void *cpu_context; | 104 void *cpu_context; |
32 bp_def *breakpoints; | 105 bp_def *breakpoints; |
33 disp_def *displays; | 106 disp_def *displays; |
34 resolver resolve; | 107 tern_node *commands; |
35 reader read_mem; | 108 resolver resolve; |
36 uint32_t bp_index; | 109 reader read_mem; |
37 uint32_t disp_index; | 110 setter set; |
38 uint32_t branch_t; | 111 writer write_mem; |
39 uint32_t branch_f; | 112 uint32_t bp_index; |
40 uint32_t address; | 113 uint32_t disp_index; |
114 uint32_t branch_t; | |
115 uint32_t branch_f; | |
116 void *inst; | |
117 uint32_t address; | |
118 uint32_t after; | |
41 }; | 119 }; |
42 | 120 |
43 debug_root *find_root(void *cpu); | 121 debug_root *find_root(void *cpu); |
122 debug_root *find_m68k_root(m68k_context *context); | |
123 debug_root *find_z80_root(z80_context *context); | |
44 bp_def ** find_breakpoint(bp_def ** cur, uint32_t address); | 124 bp_def ** find_breakpoint(bp_def ** cur, uint32_t address); |
45 bp_def ** find_breakpoint_idx(bp_def ** cur, uint32_t index); | 125 bp_def ** find_breakpoint_idx(bp_def ** cur, uint32_t index); |
46 void add_display(disp_def ** head, uint32_t *index, char format_char, char * param); | 126 void add_display(disp_def ** head, uint32_t *index, char format_char, char * param); |
47 void remove_display(disp_def ** head, uint32_t index); | 127 void remove_display(disp_def ** head, uint32_t index); |
48 void debugger(m68k_context * context, uint32_t address); | 128 void debugger(m68k_context * context, uint32_t address); |