-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdb.h
More file actions
228 lines (190 loc) · 8.34 KB
/
sdb.h
File metadata and controls
228 lines (190 loc) · 8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* sdb.h - SDB (SPARC Debugger) for UT699/LEON3 Simulator
*
* Enhanced debugger for SPARC V8 simulation with features:
* - Code and data breakpoints
* - Watchpoints on memory and registers
* - Call stack display
* - Pipeline state inspection
* - Performance counters
* - Profiling integration
*
* Based on DLite from SimpleScalar, extensively modified for SPARC V8.
*/
#ifndef SDB_H
#define SDB_H
#include <stdio.h>
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "regs.h"
#include "memory.h"
#include "eval.h"
/*
* Supported SDB Commands:
*
* help - print command reference
* version - print SDB version information
* terminate - terminate the simulation with statistics
* quit - exit the simulator
* cont {<addr>} - continue program execution (optionally at <addr>)
* step - step program one instruction
* next - step program one instruction in current procedure
* stepi <n> - step <n> instructions
* print <expr> - print the value of <expr>
* regs - print register contents
* fregs - print floating-point register contents
* sregs - print special/control registers (PSR, WIM, TBR, Y)
* windows - print all register windows
* mstate - print machine specific state
* display/<mods> <addr> - display the value at <addr> using format <modifiers>
* dump {<addr>} {<cnt>} - dump memory at <addr> (optionally for <cnt> words)
* dis <addr> {<cnt>} - disassemble instructions at <addr>
* break <addr> - set breakpoint at <addr>
* dbreak <addr> {r|w|x} - set data breakpoint at <addr>
* watch <reg> - set watchpoint on register <reg>
* breaks - list active breakpoints and watchpoints
* delete <id> - delete breakpoint/watchpoint <id>
* clear - clear all breakpoints and watchpoints
* bt - print backtrace (call stack)
* info - print pipeline and simulation info
* profile - show profiling summary
* reset - reset CPU to initial state
* symbols - list loaded symbols
* where - show current location with source context
*
* Command modifiers <mods>:
* b - print a byte
* h - print a half (short)
* w - print a word
* q - print a qword
* d - print in decimal format
* u - print in unsigned decimal format
* o - print in octal format
* x - print in hex format
* 1 - print in binary format
* f - print a float
* F - print a double
* c - print a character
* s - print a string
*/
/* Maximum call stack depth for backtrace */
#define SDB_MAX_CALL_DEPTH 256
/* Maximum number of breakpoints */
#define SDB_MAX_BREAKPOINTS 64
/* Maximum number of watchpoints */
#define SDB_MAX_WATCHPOINTS 32
/* Breakpoint types */
#define SDB_BP_CODE 0x01 /* Code breakpoint */
#define SDB_BP_DATA_R 0x02 /* Data read breakpoint */
#define SDB_BP_DATA_W 0x04 /* Data write breakpoint */
#define SDB_BP_DATA_X 0x08 /* Data execute breakpoint */
/* Watchpoint types */
#define SDB_WP_REG 0x10 /* Register watchpoint */
#define SDB_WP_MEM 0x20 /* Memory watchpoint */
/* Call stack entry */
typedef struct {
md_addr_t call_pc; /* PC of CALL instruction */
md_addr_t func_addr; /* Address of called function */
md_addr_t return_addr; /* Expected return address */
counter_t entry_cycle; /* Cycle when function was entered */
counter_t entry_insn; /* Instruction count at entry */
char func_name[64]; /* Function name (if known) */
} sdb_call_entry_t;
/* Call stack structure */
typedef struct {
sdb_call_entry_t entries[SDB_MAX_CALL_DEPTH];
int depth;
} sdb_call_stack_t;
/* SDB register access function type */
typedef char * /* error str, NULL if none */
(*sdb_reg_obj_t)(struct regs_t *regs, /* registers to access */
int is_write, /* access type */
enum md_reg_type rt, /* reg bank to access */
int reg, /* register number */
struct eval_value_t *val); /* input, output */
/* SDB memory access function type */
typedef char * /* error str, NULL if none */
(*sdb_mem_obj_t)(struct mem_t *mem, /* memory space to access */
int is_write, /* access type */
md_addr_t addr, /* address to access */
char *p, /* input/output buffer */
int nbytes); /* size of access */
/* SDB machine state display function type */
typedef char * /* error str, NULL if none */
(*sdb_mstate_obj_t)(FILE *stream, /* output stream */
char *cmd, /* optional command string */
struct regs_t *regs,/* registers to access */
struct mem_t *mem); /* memory space to access */
/* Initialize the SDB debugger */
void sdb_init(sdb_reg_obj_t reg_obj, /* register state object */
sdb_mem_obj_t mem_obj, /* memory state object */
sdb_mstate_obj_t mstate_obj); /* machine state object */
/* Default memory state accessor */
char *sdb_mem_obj(struct mem_t *mem, /* memory space to access */
int is_write, /* access type */
md_addr_t addr, /* address to access */
char *p, /* input, output */
int nbytes); /* size of access */
/* Default machine-specific state accessor */
char *sdb_mstate_obj(FILE *stream, /* output stream */
char *cmd, /* optional command string */
struct regs_t *regs, /* registers to access */
struct mem_t *mem); /* memory space to access */
/* State access masks */
#define ACCESS_READ 0x01 /* read access allowed */
#define ACCESS_WRITE 0x02 /* write access allowed */
#define ACCESS_EXEC 0x04 /* execute access allowed */
/* Non-zero iff one breakpoint is set, for fast break check */
extern md_addr_t sdb_fastbreak;
/* Set non-zero to enter SDB after next instruction */
extern int sdb_active;
/* Non-zero to force a check for a break */
extern int sdb_check;
/* Internal break check interface */
int __sdb_check_break(md_addr_t next_PC, /* address of next inst */
int access, /* mem access of last inst */
md_addr_t addr, /* mem addr of last inst */
counter_t icount, /* instruction count */
counter_t cycle); /* cycle count */
/* Check for a break condition (macro for speed) */
#define sdb_check_break(NPC, ACCESS, ADDR, ICNT, CYCLE) \
((sdb_check || sdb_active) \
? __sdb_check_break((NPC), (ACCESS), (ADDR), (ICNT), (CYCLE))\
: FALSE)
/* SDB debugger main loop */
void sdb_main(md_addr_t regs_PC, /* addr of last inst to exec */
md_addr_t next_PC, /* addr of next inst to exec */
counter_t cycle, /* current processor cycle */
struct regs_t *regs, /* registers to access */
struct mem_t *mem); /* memory to access */
/*
* Call Stack Tracking API
*/
/* Initialize call stack tracking */
void sdb_call_stack_init(void);
/* Push a function call onto the call stack */
void sdb_call_push(md_addr_t call_pc, md_addr_t func_addr,
counter_t cycle, counter_t insn);
/* Pop a function return from the call stack */
void sdb_call_pop(md_addr_t return_pc, counter_t cycle, counter_t insn);
/* Get current call stack depth */
int sdb_call_depth(void);
/* Print backtrace */
void sdb_print_backtrace(FILE *stream);
/*
* Enhanced Features
*/
/* Print all register windows */
void sdb_print_windows(FILE *stream, struct regs_t *regs);
/* Print control registers (PSR, WIM, TBR, Y) */
void sdb_print_control_regs(FILE *stream, struct regs_t *regs);
/* Print floating-point registers */
void sdb_print_fp_regs(FILE *stream, struct regs_t *regs);
/* Print pipeline state (for sim-inorder) */
void sdb_print_pipeline(FILE *stream);
/* Print simulation info and statistics */
void sdb_print_info(FILE *stream);
/* Reset CPU state (for reset command) */
void sdb_reset_cpu(struct regs_t *regs, struct mem_t *mem);
#endif /* SDB_H */