Rev 2927 | Rev 3153 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2927 | Rev 3149 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
2 | * Copyright (c) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup amd64debug |
29 | /** @addtogroup amd64debug |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <arch/debugger.h> |
35 | #include <arch/debugger.h> |
36 | #include <console/kconsole.h> |
36 | #include <console/kconsole.h> |
37 | #include <console/cmd.h> |
37 | #include <console/cmd.h> |
38 | #include <symtab.h> |
38 | #include <symtab.h> |
39 | #include <print.h> |
39 | #include <print.h> |
40 | #include <panic.h> |
40 | #include <panic.h> |
41 | #include <interrupt.h> |
41 | #include <interrupt.h> |
42 | #include <arch/asm.h> |
42 | #include <arch/asm.h> |
43 | #include <arch/cpu.h> |
43 | #include <arch/cpu.h> |
44 | #include <debug.h> |
44 | #include <debug.h> |
45 | #include <func.h> |
45 | #include <func.h> |
46 | #include <smp/ipi.h> |
46 | #include <smp/ipi.h> |
47 | 47 | ||
48 | typedef struct { |
48 | typedef struct { |
49 | uintptr_t address; /**< Breakpoint address */ |
49 | uintptr_t address; /**< Breakpoint address */ |
50 | int flags; /**< Flags regarding breakpoint */ |
50 | int flags; /**< Flags regarding breakpoint */ |
51 | int counter; /**< How many times the exception occured */ |
51 | int counter; /**< How many times the exception occured */ |
52 | } bpinfo_t; |
52 | } bpinfo_t; |
53 | 53 | ||
54 | static bpinfo_t breakpoints[BKPOINTS_MAX]; |
54 | static bpinfo_t breakpoints[BKPOINTS_MAX]; |
55 | SPINLOCK_INITIALIZE(bkpoint_lock); |
55 | SPINLOCK_INITIALIZE(bkpoint_lock); |
56 | 56 | ||
57 | static int cmd_print_breakpoints(cmd_arg_t *argv); |
57 | static int cmd_print_breakpoints(cmd_arg_t *argv); |
58 | static cmd_info_t bkpts_info = { |
58 | static cmd_info_t bkpts_info = { |
59 | .name = "bkpts", |
59 | .name = "bkpts", |
60 | .description = "Print breakpoint table.", |
60 | .description = "Print breakpoint table.", |
61 | .func = cmd_print_breakpoints, |
61 | .func = cmd_print_breakpoints, |
62 | .argc = 0, |
62 | .argc = 0, |
63 | }; |
63 | }; |
64 | 64 | ||
65 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
65 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
66 | 66 | ||
67 | static int cmd_del_breakpoint(cmd_arg_t *argv); |
67 | static int cmd_del_breakpoint(cmd_arg_t *argv); |
68 | static cmd_arg_t del_argv = { |
68 | static cmd_arg_t del_argv = { |
69 | .type = ARG_TYPE_INT |
69 | .type = ARG_TYPE_INT |
70 | }; |
70 | }; |
71 | static cmd_info_t delbkpt_info = { |
71 | static cmd_info_t delbkpt_info = { |
72 | .name = "delbkpt", |
72 | .name = "delbkpt", |
73 | .description = "delbkpt <number> - Delete breakpoint.", |
73 | .description = "delbkpt <number> - Delete breakpoint.", |
74 | .func = cmd_del_breakpoint, |
74 | .func = cmd_del_breakpoint, |
75 | .argc = 1, |
75 | .argc = 1, |
76 | .argv = &del_argv |
76 | .argv = &del_argv |
77 | }; |
77 | }; |
78 | 78 | ||
79 | static int cmd_add_breakpoint(cmd_arg_t *argv); |
79 | static int cmd_add_breakpoint(cmd_arg_t *argv); |
80 | static cmd_arg_t add_argv = { |
80 | static cmd_arg_t add_argv = { |
81 | .type = ARG_TYPE_INT |
81 | .type = ARG_TYPE_INT |
82 | }; |
82 | }; |
83 | static cmd_info_t addbkpt_info = { |
83 | static cmd_info_t addbkpt_info = { |
84 | .name = "addbkpt", |
84 | .name = "addbkpt", |
85 | .description = "addbkpt <&symbol> - new breakpoint.", |
85 | .description = "addbkpt <&symbol> - new breakpoint.", |
86 | .func = cmd_add_breakpoint, |
86 | .func = cmd_add_breakpoint, |
87 | .argc = 1, |
87 | .argc = 1, |
88 | .argv = &add_argv |
88 | .argv = &add_argv |
89 | }; |
89 | }; |
90 | 90 | ||
91 | static cmd_arg_t addw_argv = { |
91 | static cmd_arg_t addw_argv = { |
92 | .type = ARG_TYPE_INT |
92 | .type = ARG_TYPE_INT |
93 | }; |
93 | }; |
94 | static cmd_info_t addwatchp_info = { |
94 | static cmd_info_t addwatchp_info = { |
95 | .name = "addwatchp", |
95 | .name = "addwatchp", |
96 | .description = "addbwatchp <&symbol> - new write watchpoint.", |
96 | .description = "addbwatchp <&symbol> - new write watchpoint.", |
97 | .func = cmd_add_breakpoint, |
97 | .func = cmd_add_breakpoint, |
98 | .argc = 1, |
98 | .argc = 1, |
99 | .argv = &addw_argv |
99 | .argv = &addw_argv |
100 | }; |
100 | }; |
101 | 101 | ||
102 | #endif |
102 | #endif |
103 | 103 | ||
104 | /** Print table of active breakpoints */ |
104 | /** Print table of active breakpoints */ |
105 | int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused))) |
105 | int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused))) |
106 | { |
106 | { |
107 | unsigned int i; |
107 | unsigned int i; |
108 | char *symbol; |
108 | char *symbol; |
109 | 109 | ||
110 | if (sizeof(void *) == 4) { |
110 | #ifdef __32_BITS__ |
111 | printf("# Count Address In symbol\n"); |
111 | printf("# Count Address In symbol\n"); |
112 | printf("-- ----- ---------- ---------\n"); |
112 | printf("-- ----- ---------- ---------\n"); |
113 | } else { |
113 | #endif |
- | 114 | ||
- | 115 | #ifdef __64_BITS__ |
|
114 | printf("# Count Address In symbol\n"); |
116 | printf("# Count Address In symbol\n"); |
115 | printf("-- ----- ------------------ ---------\n"); |
117 | printf("-- ----- ------------------ ---------\n"); |
116 | } |
118 | #endif |
117 | 119 | ||
118 | for (i = 0; i < BKPOINTS_MAX; i++) |
120 | for (i = 0; i < BKPOINTS_MAX; i++) |
119 | if (breakpoints[i].address) { |
121 | if (breakpoints[i].address) { |
120 | symbol = get_symtab_entry(breakpoints[i].address); |
122 | symbol = get_symtab_entry(breakpoints[i].address); |
121 | 123 | ||
122 | if (sizeof(void *) == 4) |
124 | #ifdef __32_BITS__ |
123 | printf("%-2u %-5d %#10zx %s\n", i, breakpoints[i].counter, |
125 | printf("%-2u %-5d %#10zx %s\n", i, breakpoints[i].counter, |
124 | breakpoints[i].address, symbol); |
126 | breakpoints[i].address, symbol); |
125 | else |
127 | #endif |
- | 128 | ||
- | 129 | #ifdef __64_BITS__ |
|
126 | printf("%-2u %-5d %#18zx %s\n", i, breakpoints[i].counter, |
130 | printf("%-2u %-5d %#18zx %s\n", i, breakpoints[i].counter, |
127 | breakpoints[i].address, symbol); |
131 | breakpoints[i].address, symbol); |
- | 132 | #endif |
|
- | 133 | ||
128 | } |
134 | } |
129 | return 1; |
135 | return 1; |
130 | } |
136 | } |
131 | 137 | ||
132 | /* Setup DR register according to table */ |
138 | /* Setup DR register according to table */ |
133 | static void setup_dr(int curidx) |
139 | static void setup_dr(int curidx) |
134 | { |
140 | { |
135 | unative_t dr7; |
141 | unative_t dr7; |
136 | bpinfo_t *cur = &breakpoints[curidx]; |
142 | bpinfo_t *cur = &breakpoints[curidx]; |
137 | int flags = breakpoints[curidx].flags; |
143 | int flags = breakpoints[curidx].flags; |
138 | 144 | ||
139 | /* Disable breakpoint in DR7 */ |
145 | /* Disable breakpoint in DR7 */ |
140 | dr7 = read_dr7(); |
146 | dr7 = read_dr7(); |
141 | dr7 &= ~(0x2 << (curidx*2)); |
147 | dr7 &= ~(0x2 << (curidx*2)); |
142 | 148 | ||
143 | if (cur->address) { /* Setup DR register */ |
149 | if (cur->address) { /* Setup DR register */ |
144 | /* Set breakpoint to debug registers */ |
150 | /* Set breakpoint to debug registers */ |
145 | switch (curidx) { |
151 | switch (curidx) { |
146 | case 0: |
152 | case 0: |
147 | write_dr0(cur->address); |
153 | write_dr0(cur->address); |
148 | break; |
154 | break; |
149 | case 1: |
155 | case 1: |
150 | write_dr1(cur->address); |
156 | write_dr1(cur->address); |
151 | break; |
157 | break; |
152 | case 2: |
158 | case 2: |
153 | write_dr2(cur->address); |
159 | write_dr2(cur->address); |
154 | break; |
160 | break; |
155 | case 3: |
161 | case 3: |
156 | write_dr3(cur->address); |
162 | write_dr3(cur->address); |
157 | break; |
163 | break; |
158 | } |
164 | } |
159 | /* Set type to requested breakpoint & length*/ |
165 | /* Set type to requested breakpoint & length*/ |
160 | dr7 &= ~ (0x3 << (16 + 4*curidx)); |
166 | dr7 &= ~ (0x3 << (16 + 4*curidx)); |
161 | dr7 &= ~ (0x3 << (18 + 4*curidx)); |
167 | dr7 &= ~ (0x3 << (18 + 4*curidx)); |
162 | if ((flags & BKPOINT_INSTR)) { |
168 | if ((flags & BKPOINT_INSTR)) { |
163 | ; |
169 | ; |
164 | } else { |
170 | } else { |
- | 171 | ||
165 | if (sizeof(int) == 4) |
172 | #ifdef __32_BITS__ |
166 | dr7 |= ((unative_t) 0x3) << (18 + 4*curidx); |
173 | dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx); |
- | 174 | #endif |
|
- | 175 | ||
167 | else /* 8 */ |
176 | #ifdef __64_BITS__ |
168 | dr7 |= ((unative_t) 0x2) << (18 + 4*curidx); |
177 | dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx); |
- | 178 | #endif |
|
169 | 179 | ||
170 | if ((flags & BKPOINT_WRITE)) |
180 | if ((flags & BKPOINT_WRITE)) |
171 | dr7 |= ((unative_t) 0x1) << (16 + 4*curidx); |
181 | dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx); |
172 | else if ((flags & BKPOINT_READ_WRITE)) |
182 | else if ((flags & BKPOINT_READ_WRITE)) |
173 | dr7 |= ((unative_t) 0x3) << (16 + 4*curidx); |
183 | dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx); |
174 | } |
184 | } |
175 | 185 | ||
176 | /* Enable global breakpoint */ |
186 | /* Enable global breakpoint */ |
177 | dr7 |= 0x2 << (curidx*2); |
187 | dr7 |= 0x2 << (curidx*2); |
178 | 188 | ||
179 | write_dr7(dr7); |
189 | write_dr7(dr7); |
180 | 190 | ||
181 | } |
191 | } |
182 | } |
192 | } |
183 | 193 | ||
184 | /** Enable hardware breakpoint |
194 | /** Enable hardware breakpoint |
185 | * |
195 | * |
186 | * @param where Address of HW breakpoint |
196 | * @param where Address of HW breakpoint |
187 | * @param flags Type of breakpoint (EXECUTE, WRITE) |
197 | * @param flags Type of breakpoint (EXECUTE, WRITE) |
188 | * @return Debug slot on success, -1 - no available HW breakpoint |
198 | * @return Debug slot on success, -1 - no available HW breakpoint |
189 | */ |
199 | */ |
190 | int breakpoint_add(const void *where, const int flags, int curidx) |
200 | int breakpoint_add(const void *where, const int flags, int curidx) |
191 | { |
201 | { |
192 | ipl_t ipl; |
202 | ipl_t ipl; |
193 | int i; |
203 | int i; |
194 | bpinfo_t *cur; |
204 | bpinfo_t *cur; |
195 | 205 | ||
196 | ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE)); |
206 | ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE)); |
197 | 207 | ||
198 | ipl = interrupts_disable(); |
208 | ipl = interrupts_disable(); |
199 | spinlock_lock(&bkpoint_lock); |
209 | spinlock_lock(&bkpoint_lock); |
200 | 210 | ||
201 | if (curidx == -1) { |
211 | if (curidx == -1) { |
202 | /* Find free space in slots */ |
212 | /* Find free space in slots */ |
203 | for (i = 0; i < BKPOINTS_MAX; i++) |
213 | for (i = 0; i < BKPOINTS_MAX; i++) |
204 | if (!breakpoints[i].address) { |
214 | if (!breakpoints[i].address) { |
205 | curidx = i; |
215 | curidx = i; |
206 | break; |
216 | break; |
207 | } |
217 | } |
208 | if (curidx == -1) { |
218 | if (curidx == -1) { |
209 | /* Too many breakpoints */ |
219 | /* Too many breakpoints */ |
210 | spinlock_unlock(&bkpoint_lock); |
220 | spinlock_unlock(&bkpoint_lock); |
211 | interrupts_restore(ipl); |
221 | interrupts_restore(ipl); |
212 | return -1; |
222 | return -1; |
213 | } |
223 | } |
214 | } |
224 | } |
215 | cur = &breakpoints[curidx]; |
225 | cur = &breakpoints[curidx]; |
216 | 226 | ||
217 | cur->address = (uintptr_t) where; |
227 | cur->address = (uintptr_t) where; |
218 | cur->flags = flags; |
228 | cur->flags = flags; |
219 | cur->counter = 0; |
229 | cur->counter = 0; |
220 | 230 | ||
221 | setup_dr(curidx); |
231 | setup_dr(curidx); |
222 | 232 | ||
223 | spinlock_unlock(&bkpoint_lock); |
233 | spinlock_unlock(&bkpoint_lock); |
224 | interrupts_restore(ipl); |
234 | interrupts_restore(ipl); |
225 | 235 | ||
226 | /* Send IPI */ |
236 | /* Send IPI */ |
227 | #ifdef CONFIG_SMP |
237 | #ifdef CONFIG_SMP |
228 | // ipi_broadcast(VECTOR_DEBUG_IPI); |
238 | // ipi_broadcast(VECTOR_DEBUG_IPI); |
229 | #endif |
239 | #endif |
230 | 240 | ||
231 | return curidx; |
241 | return curidx; |
232 | } |
242 | } |
233 | 243 | ||
234 | #ifdef amd64 |
244 | #ifdef amd64 |
235 | # define getip(x) ((x)->rip) |
245 | # define getip(x) ((x)->rip) |
236 | #else |
246 | #else |
237 | # define getip(x) ((x)->eip) |
247 | # define getip(x) ((x)->eip) |
238 | #endif |
248 | #endif |
239 | 249 | ||
240 | static void handle_exception(int slot, istate_t *istate) |
250 | static void handle_exception(int slot, istate_t *istate) |
241 | { |
251 | { |
242 | ASSERT(breakpoints[slot].address); |
252 | ASSERT(breakpoints[slot].address); |
243 | 253 | ||
244 | /* Handle zero checker */ |
254 | /* Handle zero checker */ |
245 | if (! (breakpoints[slot].flags & BKPOINT_INSTR)) { |
255 | if (! (breakpoints[slot].flags & BKPOINT_INSTR)) { |
246 | if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) { |
256 | if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) { |
247 | if (*((unative_t *) breakpoints[slot].address) != 0) |
257 | if (*((unative_t *) breakpoints[slot].address) != 0) |
248 | return; |
258 | return; |
249 | printf("**** Found ZERO on address %lx (slot %d) ****\n", |
259 | printf("**** Found ZERO on address %lx (slot %d) ****\n", |
250 | breakpoints[slot].address, slot); |
260 | breakpoints[slot].address, slot); |
251 | } else { |
261 | } else { |
252 | printf("Data watchpoint - new data: %lx\n", |
262 | printf("Data watchpoint - new data: %lx\n", |
253 | *((unative_t *) breakpoints[slot].address)); |
263 | *((unative_t *) breakpoints[slot].address)); |
254 | } |
264 | } |
255 | } |
265 | } |
256 | printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate), |
266 | printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate), |
257 | get_symtab_entry(getip(istate))); |
267 | get_symtab_entry(getip(istate))); |
258 | printf("***Type 'exit' to exit kconsole.\n"); |
268 | printf("***Type 'exit' to exit kconsole.\n"); |
259 | atomic_set(&haltstate,1); |
269 | atomic_set(&haltstate,1); |
260 | kconsole((void *) "debug"); |
270 | kconsole((void *) "debug"); |
261 | atomic_set(&haltstate,0); |
271 | atomic_set(&haltstate,0); |
262 | } |
272 | } |
263 | 273 | ||
264 | void breakpoint_del(int slot) |
274 | void breakpoint_del(int slot) |
265 | { |
275 | { |
266 | bpinfo_t *cur; |
276 | bpinfo_t *cur; |
267 | ipl_t ipl; |
277 | ipl_t ipl; |
268 | 278 | ||
269 | ipl = interrupts_disable(); |
279 | ipl = interrupts_disable(); |
270 | spinlock_lock(&bkpoint_lock); |
280 | spinlock_lock(&bkpoint_lock); |
271 | 281 | ||
272 | cur = &breakpoints[slot]; |
282 | cur = &breakpoints[slot]; |
273 | if (!cur->address) { |
283 | if (!cur->address) { |
274 | spinlock_unlock(&bkpoint_lock); |
284 | spinlock_unlock(&bkpoint_lock); |
275 | interrupts_restore(ipl); |
285 | interrupts_restore(ipl); |
276 | return; |
286 | return; |
277 | } |
287 | } |
278 | 288 | ||
279 | cur->address = NULL; |
289 | cur->address = NULL; |
280 | 290 | ||
281 | setup_dr(slot); |
291 | setup_dr(slot); |
282 | 292 | ||
283 | spinlock_unlock(&bkpoint_lock); |
293 | spinlock_unlock(&bkpoint_lock); |
284 | interrupts_restore(ipl); |
294 | interrupts_restore(ipl); |
285 | #ifdef CONFIG_SMP |
295 | #ifdef CONFIG_SMP |
286 | // ipi_broadcast(VECTOR_DEBUG_IPI); |
296 | // ipi_broadcast(VECTOR_DEBUG_IPI); |
287 | #endif |
297 | #endif |
288 | } |
298 | } |
289 | 299 | ||
290 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
300 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
291 | 301 | ||
292 | /** Remove breakpoint from table */ |
302 | /** Remove breakpoint from table */ |
293 | int cmd_del_breakpoint(cmd_arg_t *argv) |
303 | int cmd_del_breakpoint(cmd_arg_t *argv) |
294 | { |
304 | { |
295 | unative_t bpno = argv->intval; |
305 | unative_t bpno = argv->intval; |
296 | if (bpno > BKPOINTS_MAX) { |
306 | if (bpno > BKPOINTS_MAX) { |
297 | printf("Invalid breakpoint number.\n"); |
307 | printf("Invalid breakpoint number.\n"); |
298 | return 0; |
308 | return 0; |
299 | } |
309 | } |
300 | breakpoint_del(argv->intval); |
310 | breakpoint_del(argv->intval); |
301 | return 1; |
311 | return 1; |
302 | } |
312 | } |
303 | 313 | ||
304 | /** Add new breakpoint to table */ |
314 | /** Add new breakpoint to table */ |
305 | static int cmd_add_breakpoint(cmd_arg_t *argv) |
315 | static int cmd_add_breakpoint(cmd_arg_t *argv) |
306 | { |
316 | { |
307 | int flags; |
317 | int flags; |
308 | int id; |
318 | int id; |
309 | 319 | ||
310 | if (argv == &add_argv) { |
320 | if (argv == &add_argv) { |
311 | flags = BKPOINT_INSTR; |
321 | flags = BKPOINT_INSTR; |
312 | } else { /* addwatchp */ |
322 | } else { /* addwatchp */ |
313 | flags = BKPOINT_WRITE; |
323 | flags = BKPOINT_WRITE; |
314 | } |
324 | } |
315 | printf("Adding breakpoint on address: %p\n", argv->intval); |
325 | printf("Adding breakpoint on address: %p\n", argv->intval); |
316 | id = breakpoint_add((void *)argv->intval, flags, -1); |
326 | id = breakpoint_add((void *)argv->intval, flags, -1); |
317 | if (id < 0) |
327 | if (id < 0) |
318 | printf("Add breakpoint failed.\n"); |
328 | printf("Add breakpoint failed.\n"); |
319 | else |
329 | else |
320 | printf("Added breakpoint %d.\n", id); |
330 | printf("Added breakpoint %d.\n", id); |
321 | 331 | ||
322 | return 1; |
332 | return 1; |
323 | } |
333 | } |
324 | #endif |
334 | #endif |
325 | 335 | ||
326 | static void debug_exception(int n __attribute__((unused)), istate_t *istate) |
336 | static void debug_exception(int n __attribute__((unused)), istate_t *istate) |
327 | { |
337 | { |
328 | unative_t dr6; |
338 | unative_t dr6; |
329 | int i; |
339 | int i; |
330 | 340 | ||
331 | /* Set RF to restart the instruction */ |
341 | /* Set RF to restart the instruction */ |
332 | #ifdef amd64 |
342 | #ifdef amd64 |
333 | istate->rflags |= RFLAGS_RF; |
343 | istate->rflags |= RFLAGS_RF; |
334 | #else |
344 | #else |
335 | istate->eflags |= EFLAGS_RF; |
345 | istate->eflags |= EFLAGS_RF; |
336 | #endif |
346 | #endif |
337 | 347 | ||
338 | dr6 = read_dr6(); |
348 | dr6 = read_dr6(); |
339 | for (i=0; i < BKPOINTS_MAX; i++) { |
349 | for (i=0; i < BKPOINTS_MAX; i++) { |
340 | if (dr6 & (1 << i)) { |
350 | if (dr6 & (1 << i)) { |
341 | dr6 &= ~ (1 << i); |
351 | dr6 &= ~ (1 << i); |
342 | write_dr6(dr6); |
352 | write_dr6(dr6); |
343 | 353 | ||
344 | handle_exception(i, istate); |
354 | handle_exception(i, istate); |
345 | } |
355 | } |
346 | } |
356 | } |
347 | } |
357 | } |
348 | 358 | ||
349 | #ifdef CONFIG_SMP |
359 | #ifdef CONFIG_SMP |
350 | static void debug_ipi(int n __attribute__((unused)), istate_t *istate __attribute__((unused))) |
360 | static void debug_ipi(int n __attribute__((unused)), istate_t *istate __attribute__((unused))) |
351 | { |
361 | { |
352 | int i; |
362 | int i; |
353 | 363 | ||
354 | spinlock_lock(&bkpoint_lock); |
364 | spinlock_lock(&bkpoint_lock); |
355 | for (i = 0; i < BKPOINTS_MAX; i++) |
365 | for (i = 0; i < BKPOINTS_MAX; i++) |
356 | setup_dr(i); |
366 | setup_dr(i); |
357 | spinlock_unlock(&bkpoint_lock); |
367 | spinlock_unlock(&bkpoint_lock); |
358 | } |
368 | } |
359 | #endif |
369 | #endif |
360 | 370 | ||
361 | /** Initialize debugger */ |
371 | /** Initialize debugger */ |
362 | void debugger_init() |
372 | void debugger_init() |
363 | { |
373 | { |
364 | int i; |
374 | int i; |
365 | 375 | ||
366 | for (i=0; i<BKPOINTS_MAX; i++) |
376 | for (i=0; i<BKPOINTS_MAX; i++) |
367 | breakpoints[i].address = NULL; |
377 | breakpoints[i].address = NULL; |
368 | 378 | ||
369 | cmd_initialize(&bkpts_info); |
379 | cmd_initialize(&bkpts_info); |
370 | if (!cmd_register(&bkpts_info)) |
380 | if (!cmd_register(&bkpts_info)) |
371 | panic("could not register command %s\n", bkpts_info.name); |
381 | panic("could not register command %s\n", bkpts_info.name); |
372 | 382 | ||
373 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
383 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
374 | cmd_initialize(&delbkpt_info); |
384 | cmd_initialize(&delbkpt_info); |
375 | if (!cmd_register(&delbkpt_info)) |
385 | if (!cmd_register(&delbkpt_info)) |
376 | panic("could not register command %s\n", delbkpt_info.name); |
386 | panic("could not register command %s\n", delbkpt_info.name); |
377 | 387 | ||
378 | cmd_initialize(&addbkpt_info); |
388 | cmd_initialize(&addbkpt_info); |
379 | if (!cmd_register(&addbkpt_info)) |
389 | if (!cmd_register(&addbkpt_info)) |
380 | panic("could not register command %s\n", addbkpt_info.name); |
390 | panic("could not register command %s\n", addbkpt_info.name); |
381 | 391 | ||
382 | cmd_initialize(&addwatchp_info); |
392 | cmd_initialize(&addwatchp_info); |
383 | if (!cmd_register(&addwatchp_info)) |
393 | if (!cmd_register(&addwatchp_info)) |
384 | panic("could not register command %s\n", addwatchp_info.name); |
394 | panic("could not register command %s\n", addwatchp_info.name); |
385 | #endif |
395 | #endif |
386 | 396 | ||
387 | exc_register(VECTOR_DEBUG, "debugger", |
397 | exc_register(VECTOR_DEBUG, "debugger", |
388 | debug_exception); |
398 | debug_exception); |
389 | #ifdef CONFIG_SMP |
399 | #ifdef CONFIG_SMP |
390 | exc_register(VECTOR_DEBUG_IPI, "debugger_smp", |
400 | exc_register(VECTOR_DEBUG_IPI, "debugger_smp", |
391 | debug_ipi); |
401 | debug_ipi); |
392 | #endif |
402 | #endif |
393 | } |
403 | } |
394 | 404 | ||
395 | /** @} |
405 | /** @} |
396 | */ |
406 | */ |
397 | 407 |