Rev 3431 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3431 | Rev 4377 | ||
---|---|---|---|
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> |
- | |
39 | #include <print.h> |
38 | #include <print.h> |
40 | #include <panic.h> |
39 | #include <panic.h> |
41 | #include <interrupt.h> |
40 | #include <interrupt.h> |
42 | #include <arch/asm.h> |
41 | #include <arch/asm.h> |
43 | #include <arch/cpu.h> |
42 | #include <arch/cpu.h> |
44 | #include <debug.h> |
43 | #include <debug.h> |
45 | #include <func.h> |
44 | #include <func.h> |
46 | #include <smp/ipi.h> |
45 | #include <smp/ipi.h> |
- | 46 | #include <symtab.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 | #ifdef CONFIG_KCONSOLE |
|
- | 58 | ||
57 | static int cmd_print_breakpoints(cmd_arg_t *argv); |
59 | static int cmd_print_breakpoints(cmd_arg_t *argv); |
58 | static cmd_info_t bkpts_info = { |
60 | static cmd_info_t bkpts_info = { |
59 | .name = "bkpts", |
61 | .name = "bkpts", |
60 | .description = "Print breakpoint table.", |
62 | .description = "Print breakpoint table.", |
61 | .func = cmd_print_breakpoints, |
63 | .func = cmd_print_breakpoints, |
62 | .argc = 0, |
64 | .argc = 0, |
63 | }; |
65 | }; |
64 | 66 | ||
65 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
- | |
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 |
- | |
103 | - | ||
104 | /** Print table of active breakpoints */ |
- | |
105 | int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused))) |
- | |
106 | { |
- | |
107 | unsigned int i; |
- | |
108 | char *symbol; |
- | |
109 | - | ||
110 | #ifdef __32_BITS__ |
102 | #endif /* CONFIG_KCONSOLE */ |
111 | printf("# Count Address In symbol\n"); |
- | |
112 | printf("-- ----- ---------- ---------\n"); |
- | |
113 | #endif |
- | |
114 | - | ||
115 | #ifdef __64_BITS__ |
- | |
116 | printf("# Count Address In symbol\n"); |
- | |
117 | printf("-- ----- ------------------ ---------\n"); |
- | |
118 | #endif |
- | |
119 | - | ||
120 | for (i = 0; i < BKPOINTS_MAX; i++) |
- | |
121 | if (breakpoints[i].address) { |
- | |
122 | symbol = get_symtab_entry(breakpoints[i].address); |
- | |
123 | - | ||
124 | #ifdef __32_BITS__ |
- | |
125 | printf("%-2u %-5d %#10zx %s\n", i, |
- | |
126 | breakpoints[i].counter, breakpoints[i].address, |
- | |
127 | symbol); |
- | |
128 | #endif |
- | |
129 | - | ||
130 | #ifdef __64_BITS__ |
- | |
131 | printf("%-2u %-5d %#18zx %s\n", i, |
- | |
132 | breakpoints[i].counter, breakpoints[i].address, |
- | |
133 | symbol); |
- | |
134 | #endif |
- | |
135 | - | ||
136 | } |
- | |
137 | return 1; |
- | |
138 | } |
- | |
139 | 103 | ||
140 | /* Setup DR register according to table */ |
104 | /* Setup DR register according to table */ |
141 | static void setup_dr(int curidx) |
105 | static void setup_dr(int curidx) |
142 | { |
106 | { |
143 | unative_t dr7; |
107 | unative_t dr7; |
144 | bpinfo_t *cur = &breakpoints[curidx]; |
108 | bpinfo_t *cur = &breakpoints[curidx]; |
145 | int flags = breakpoints[curidx].flags; |
109 | int flags = breakpoints[curidx].flags; |
146 | 110 | ||
147 | /* Disable breakpoint in DR7 */ |
111 | /* Disable breakpoint in DR7 */ |
148 | dr7 = read_dr7(); |
112 | dr7 = read_dr7(); |
149 | dr7 &= ~(0x2 << (curidx*2)); |
113 | dr7 &= ~(0x2 << (curidx*2)); |
150 | 114 | ||
151 | if (cur->address) { /* Setup DR register */ |
115 | if (cur->address) { /* Setup DR register */ |
152 | /* Set breakpoint to debug registers */ |
116 | /* Set breakpoint to debug registers */ |
153 | switch (curidx) { |
117 | switch (curidx) { |
154 | case 0: |
118 | case 0: |
155 | write_dr0(cur->address); |
119 | write_dr0(cur->address); |
156 | break; |
120 | break; |
157 | case 1: |
121 | case 1: |
158 | write_dr1(cur->address); |
122 | write_dr1(cur->address); |
159 | break; |
123 | break; |
160 | case 2: |
124 | case 2: |
161 | write_dr2(cur->address); |
125 | write_dr2(cur->address); |
162 | break; |
126 | break; |
163 | case 3: |
127 | case 3: |
164 | write_dr3(cur->address); |
128 | write_dr3(cur->address); |
165 | break; |
129 | break; |
166 | } |
130 | } |
167 | /* Set type to requested breakpoint & length*/ |
131 | /* Set type to requested breakpoint & length*/ |
168 | dr7 &= ~ (0x3 << (16 + 4*curidx)); |
132 | dr7 &= ~ (0x3 << (16 + 4*curidx)); |
169 | dr7 &= ~ (0x3 << (18 + 4*curidx)); |
133 | dr7 &= ~ (0x3 << (18 + 4*curidx)); |
170 | if ((flags & BKPOINT_INSTR)) { |
134 | if ((flags & BKPOINT_INSTR)) { |
171 | ; |
135 | ; |
172 | } else { |
136 | } else { |
173 | 137 | ||
174 | #ifdef __32_BITS__ |
138 | #ifdef __32_BITS__ |
175 | dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx); |
139 | dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx); |
176 | #endif |
140 | #endif |
177 | 141 | ||
178 | #ifdef __64_BITS__ |
142 | #ifdef __64_BITS__ |
179 | dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx); |
143 | dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx); |
180 | #endif |
144 | #endif |
181 | 145 | ||
182 | if ((flags & BKPOINT_WRITE)) |
146 | if ((flags & BKPOINT_WRITE)) |
183 | dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx); |
147 | dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx); |
184 | else if ((flags & BKPOINT_READ_WRITE)) |
148 | else if ((flags & BKPOINT_READ_WRITE)) |
185 | dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx); |
149 | dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx); |
186 | } |
150 | } |
187 | 151 | ||
188 | /* Enable global breakpoint */ |
152 | /* Enable global breakpoint */ |
189 | dr7 |= 0x2 << (curidx * 2); |
153 | dr7 |= 0x2 << (curidx * 2); |
190 | 154 | ||
191 | write_dr7(dr7); |
155 | write_dr7(dr7); |
192 | 156 | ||
193 | } |
157 | } |
194 | } |
158 | } |
195 | 159 | ||
196 | /** Enable hardware breakpoint |
160 | /** Enable hardware breakpoint |
197 | * |
161 | * |
198 | * @param where Address of HW breakpoint |
162 | * @param where Address of HW breakpoint |
199 | * @param flags Type of breakpoint (EXECUTE, WRITE) |
163 | * @param flags Type of breakpoint (EXECUTE, WRITE) |
200 | * @return Debug slot on success, -1 - no available HW breakpoint |
164 | * @return Debug slot on success, -1 - no available HW breakpoint |
201 | */ |
165 | */ |
202 | int breakpoint_add(const void *where, const int flags, int curidx) |
166 | int breakpoint_add(const void *where, const int flags, int curidx) |
203 | { |
167 | { |
204 | ipl_t ipl; |
168 | ipl_t ipl; |
205 | int i; |
169 | int i; |
206 | bpinfo_t *cur; |
170 | bpinfo_t *cur; |
207 | 171 | ||
208 | ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE)); |
172 | ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE)); |
209 | 173 | ||
210 | ipl = interrupts_disable(); |
174 | ipl = interrupts_disable(); |
211 | spinlock_lock(&bkpoint_lock); |
175 | spinlock_lock(&bkpoint_lock); |
212 | 176 | ||
213 | if (curidx == -1) { |
177 | if (curidx == -1) { |
214 | /* Find free space in slots */ |
178 | /* Find free space in slots */ |
215 | for (i = 0; i < BKPOINTS_MAX; i++) |
179 | for (i = 0; i < BKPOINTS_MAX; i++) |
216 | if (!breakpoints[i].address) { |
180 | if (!breakpoints[i].address) { |
217 | curidx = i; |
181 | curidx = i; |
218 | break; |
182 | break; |
219 | } |
183 | } |
220 | if (curidx == -1) { |
184 | if (curidx == -1) { |
221 | /* Too many breakpoints */ |
185 | /* Too many breakpoints */ |
222 | spinlock_unlock(&bkpoint_lock); |
186 | spinlock_unlock(&bkpoint_lock); |
223 | interrupts_restore(ipl); |
187 | interrupts_restore(ipl); |
224 | return -1; |
188 | return -1; |
225 | } |
189 | } |
226 | } |
190 | } |
227 | cur = &breakpoints[curidx]; |
191 | cur = &breakpoints[curidx]; |
228 | 192 | ||
229 | cur->address = (uintptr_t) where; |
193 | cur->address = (uintptr_t) where; |
230 | cur->flags = flags; |
194 | cur->flags = flags; |
231 | cur->counter = 0; |
195 | cur->counter = 0; |
232 | 196 | ||
233 | setup_dr(curidx); |
197 | setup_dr(curidx); |
234 | 198 | ||
235 | spinlock_unlock(&bkpoint_lock); |
199 | spinlock_unlock(&bkpoint_lock); |
236 | interrupts_restore(ipl); |
200 | interrupts_restore(ipl); |
237 | 201 | ||
238 | /* Send IPI */ |
202 | /* Send IPI */ |
239 | #ifdef CONFIG_SMP |
203 | #ifdef CONFIG_SMP |
240 | // ipi_broadcast(VECTOR_DEBUG_IPI); |
204 | // ipi_broadcast(VECTOR_DEBUG_IPI); |
241 | #endif |
205 | #endif |
242 | 206 | ||
243 | return curidx; |
207 | return curidx; |
244 | } |
208 | } |
245 | 209 | ||
246 | #ifdef amd64 |
210 | #ifdef __64_BITS__ |
247 | # define getip(x) ((x)->rip) |
211 | #define getip(x) ((x)->rip) |
248 | #else |
212 | #else |
249 | # define getip(x) ((x)->eip) |
213 | #define getip(x) ((x)->eip) |
250 | #endif |
214 | #endif |
251 | 215 | ||
252 | static void handle_exception(int slot, istate_t *istate) |
216 | static void handle_exception(int slot, istate_t *istate) |
253 | { |
217 | { |
254 | ASSERT(breakpoints[slot].address); |
218 | ASSERT(breakpoints[slot].address); |
255 | 219 | ||
256 | /* Handle zero checker */ |
220 | /* Handle zero checker */ |
257 | if (! (breakpoints[slot].flags & BKPOINT_INSTR)) { |
221 | if (! (breakpoints[slot].flags & BKPOINT_INSTR)) { |
258 | if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) { |
222 | if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) { |
259 | if (*((unative_t *) breakpoints[slot].address) != 0) |
223 | if (*((unative_t *) breakpoints[slot].address) != 0) |
260 | return; |
224 | return; |
261 | printf("*** Found ZERO on address %lx (slot %d) ***\n", |
225 | printf("*** Found ZERO on address %lx (slot %d) ***\n", |
262 | breakpoints[slot].address, slot); |
226 | breakpoints[slot].address, slot); |
263 | } else { |
227 | } else { |
264 | printf("Data watchpoint - new data: %lx\n", |
228 | printf("Data watchpoint - new data: %lx\n", |
265 | *((unative_t *) breakpoints[slot].address)); |
229 | *((unative_t *) breakpoints[slot].address)); |
266 | } |
230 | } |
267 | } |
231 | } |
- | 232 | ||
268 | printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate), |
233 | printf("Reached breakpoint %d:%lx (%s)\n", slot, getip(istate), |
269 | get_symtab_entry(getip(istate))); |
234 | symtab_fmt_name_lookup(getip(istate))); |
- | 235 | ||
270 | printf("***Type 'exit' to exit kconsole.\n"); |
236 | #ifdef CONFIG_KCONSOLE |
271 | atomic_set(&haltstate,1); |
237 | atomic_set(&haltstate, 1); |
272 | kconsole((void *) "debug"); |
238 | kconsole("debug", "Debug console ready.\n", false); |
273 | atomic_set(&haltstate,0); |
239 | atomic_set(&haltstate, 0); |
- | 240 | #endif |
|
274 | } |
241 | } |
275 | 242 | ||
276 | void breakpoint_del(int slot) |
243 | void breakpoint_del(int slot) |
277 | { |
244 | { |
278 | bpinfo_t *cur; |
245 | bpinfo_t *cur; |
279 | ipl_t ipl; |
246 | ipl_t ipl; |
280 | 247 | ||
281 | ipl = interrupts_disable(); |
248 | ipl = interrupts_disable(); |
282 | spinlock_lock(&bkpoint_lock); |
249 | spinlock_lock(&bkpoint_lock); |
283 | 250 | ||
284 | cur = &breakpoints[slot]; |
251 | cur = &breakpoints[slot]; |
285 | if (!cur->address) { |
252 | if (!cur->address) { |
286 | spinlock_unlock(&bkpoint_lock); |
253 | spinlock_unlock(&bkpoint_lock); |
287 | interrupts_restore(ipl); |
254 | interrupts_restore(ipl); |
288 | return; |
255 | return; |
289 | } |
256 | } |
290 | 257 | ||
291 | cur->address = NULL; |
258 | cur->address = NULL; |
292 | 259 | ||
293 | setup_dr(slot); |
260 | setup_dr(slot); |
294 | 261 | ||
295 | spinlock_unlock(&bkpoint_lock); |
262 | spinlock_unlock(&bkpoint_lock); |
296 | interrupts_restore(ipl); |
263 | interrupts_restore(ipl); |
297 | #ifdef CONFIG_SMP |
264 | #ifdef CONFIG_SMP |
298 | // ipi_broadcast(VECTOR_DEBUG_IPI); |
265 | // ipi_broadcast(VECTOR_DEBUG_IPI); |
299 | #endif |
266 | #endif |
300 | } |
267 | } |
301 | 268 | ||
302 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
- | |
303 | 269 | ||
304 | /** Remove breakpoint from table */ |
- | |
305 | int cmd_del_breakpoint(cmd_arg_t *argv) |
- | |
306 | { |
- | |
307 | unative_t bpno = argv->intval; |
- | |
308 | if (bpno > BKPOINTS_MAX) { |
- | |
309 | printf("Invalid breakpoint number.\n"); |
- | |
310 | return 0; |
- | |
311 | } |
- | |
312 | breakpoint_del(argv->intval); |
- | |
313 | return 1; |
- | |
314 | } |
- | |
315 | - | ||
316 | /** Add new breakpoint to table */ |
- | |
317 | static int cmd_add_breakpoint(cmd_arg_t *argv) |
- | |
318 | { |
- | |
319 | int flags; |
- | |
320 | int id; |
- | |
321 | - | ||
322 | if (argv == &add_argv) { |
- | |
323 | flags = BKPOINT_INSTR; |
- | |
324 | } else { /* addwatchp */ |
- | |
325 | flags = BKPOINT_WRITE; |
- | |
326 | } |
- | |
327 | printf("Adding breakpoint on address: %p\n", argv->intval); |
- | |
328 | id = breakpoint_add((void *)argv->intval, flags, -1); |
- | |
329 | if (id < 0) |
- | |
330 | printf("Add breakpoint failed.\n"); |
- | |
331 | else |
- | |
332 | printf("Added breakpoint %d.\n", id); |
- | |
333 | - | ||
334 | return 1; |
- | |
335 | } |
- | |
336 | #endif |
- | |
337 | 270 | ||
338 | static void debug_exception(int n __attribute__((unused)), istate_t *istate) |
271 | static void debug_exception(int n __attribute__((unused)), istate_t *istate) |
339 | { |
272 | { |
340 | unative_t dr6; |
273 | unative_t dr6; |
341 | int i; |
274 | int i; |
342 | 275 | ||
343 | dr6 = read_dr6(); |
276 | dr6 = read_dr6(); |
344 | 277 | ||
345 | #ifdef CONFIG_UDEBUG |
278 | #ifdef CONFIG_UDEBUG |
346 | if (dr6 & DR6_BS) { |
279 | if (dr6 & DR6_BS) { |
347 | if (THREAD && istate_from_uspace(istate)) { |
280 | if (THREAD && istate_from_uspace(istate)) { |
348 | /* |
281 | /* |
349 | * The userspace thread has TF set and executed |
282 | * The userspace thread has TF set and executed |
350 | * an instruction |
283 | * an instruction |
351 | */ |
284 | */ |
352 | udebug_trap_event(istate->eip); |
285 | udebug_trap_event(istate->eip); |
353 | return; |
286 | return; |
354 | } |
287 | } |
355 | } |
288 | } |
356 | #endif |
289 | #endif |
357 | 290 | ||
358 | /* Set RF to restart the instruction */ |
291 | /* Set RF to restart the instruction */ |
359 | #ifdef amd64 |
292 | #ifdef __64_BITS__ |
360 | istate->rflags |= RFLAGS_RF; |
293 | istate->rflags |= RFLAGS_RF; |
361 | #else |
294 | #else |
362 | istate->eflags |= EFLAGS_RF; |
295 | istate->eflags |= EFLAGS_RF; |
363 | #endif |
296 | #endif |
364 | 297 | ||
365 | for (i=0; i < BKPOINTS_MAX; i++) { |
298 | for (i=0; i < BKPOINTS_MAX; i++) { |
366 | if (dr6 & (1 << i)) { |
299 | if (dr6 & (1 << i)) { |
367 | dr6 &= ~ (1 << i); |
300 | dr6 &= ~ (1 << i); |
368 | write_dr6(dr6); |
301 | write_dr6(dr6); |
369 | 302 | ||
370 | handle_exception(i, istate); |
303 | handle_exception(i, istate); |
371 | } |
304 | } |
372 | } |
305 | } |
373 | } |
306 | } |
374 | 307 | ||
375 | #ifdef CONFIG_SMP |
308 | #ifdef CONFIG_SMP |
376 | static void |
309 | static void |
377 | debug_ipi(int n __attribute__((unused)), |
310 | debug_ipi(int n __attribute__((unused)), |
378 | istate_t *istate __attribute__((unused))) |
311 | istate_t *istate __attribute__((unused))) |
379 | { |
312 | { |
380 | int i; |
313 | int i; |
381 | 314 | ||
382 | spinlock_lock(&bkpoint_lock); |
315 | spinlock_lock(&bkpoint_lock); |
383 | for (i = 0; i < BKPOINTS_MAX; i++) |
316 | for (i = 0; i < BKPOINTS_MAX; i++) |
384 | setup_dr(i); |
317 | setup_dr(i); |
385 | spinlock_unlock(&bkpoint_lock); |
318 | spinlock_unlock(&bkpoint_lock); |
386 | } |
319 | } |
387 | #endif |
320 | #endif |
388 | 321 | ||
389 | /** Initialize debugger */ |
322 | /** Initialize debugger */ |
390 | void debugger_init() |
323 | void debugger_init() |
391 | { |
324 | { |
392 | int i; |
325 | int i; |
393 | 326 | ||
394 | for (i = 0; i < BKPOINTS_MAX; i++) |
327 | for (i = 0; i < BKPOINTS_MAX; i++) |
395 | breakpoints[i].address = NULL; |
328 | breakpoints[i].address = NULL; |
396 | 329 | ||
- | 330 | #ifdef CONFIG_KCONSOLE |
|
397 | cmd_initialize(&bkpts_info); |
331 | cmd_initialize(&bkpts_info); |
398 | if (!cmd_register(&bkpts_info)) |
332 | if (!cmd_register(&bkpts_info)) |
399 | panic("could not register command %s\n", bkpts_info.name); |
333 | printf("Cannot register command %s\n", bkpts_info.name); |
400 | 334 | ||
401 | #ifndef CONFIG_DEBUG_AS_WATCHPOINT |
- | |
402 | cmd_initialize(&delbkpt_info); |
335 | cmd_initialize(&delbkpt_info); |
403 | if (!cmd_register(&delbkpt_info)) |
336 | if (!cmd_register(&delbkpt_info)) |
404 | panic("could not register command %s\n", delbkpt_info.name); |
337 | printf("Cannot register command %s\n", delbkpt_info.name); |
405 | 338 | ||
406 | cmd_initialize(&addbkpt_info); |
339 | cmd_initialize(&addbkpt_info); |
407 | if (!cmd_register(&addbkpt_info)) |
340 | if (!cmd_register(&addbkpt_info)) |
408 | panic("could not register command %s\n", addbkpt_info.name); |
341 | printf("Cannot register command %s\n", addbkpt_info.name); |
409 | 342 | ||
410 | cmd_initialize(&addwatchp_info); |
343 | cmd_initialize(&addwatchp_info); |
411 | if (!cmd_register(&addwatchp_info)) |
344 | if (!cmd_register(&addwatchp_info)) |
412 | panic("could not register command %s\n", addwatchp_info.name); |
345 | printf("Cannot register command %s\n", addwatchp_info.name); |
413 | #endif |
346 | #endif /* CONFIG_KCONSOLE */ |
414 | 347 | ||
415 | exc_register(VECTOR_DEBUG, "debugger", debug_exception); |
348 | exc_register(VECTOR_DEBUG, "debugger", debug_exception); |
416 | #ifdef CONFIG_SMP |
349 | #ifdef CONFIG_SMP |
417 | exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi); |
350 | exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi); |
418 | #endif |
351 | #endif |
419 | } |
352 | } |
420 | 353 | ||
- | 354 | #ifdef CONFIG_KCONSOLE |
|
- | 355 | /** Print table of active breakpoints */ |
|
- | 356 | int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused))) |
|
- | 357 | { |
|
- | 358 | unsigned int i; |
|
- | 359 | char *symbol; |
|
- | 360 | ||
- | 361 | #ifdef __32_BITS__ |
|
- | 362 | printf("# Count Address In symbol\n"); |
|
- | 363 | printf("-- ----- ---------- ---------\n"); |
|
- | 364 | #endif |
|
- | 365 | ||
- | 366 | #ifdef __64_BITS__ |
|
- | 367 | printf("# Count Address In symbol\n"); |
|
- | 368 | printf("-- ----- ------------------ ---------\n"); |
|
- | 369 | #endif |
|
- | 370 | ||
- | 371 | for (i = 0; i < BKPOINTS_MAX; i++) |
|
- | 372 | if (breakpoints[i].address) { |
|
- | 373 | symbol = symtab_fmt_name_lookup( |
|
- | 374 | breakpoints[i].address); |
|
- | 375 | ||
- | 376 | #ifdef __32_BITS__ |
|
- | 377 | printf("%-2u %-5d %#10zx %s\n", i, |
|
- | 378 | breakpoints[i].counter, breakpoints[i].address, |
|
- | 379 | symbol); |
|
- | 380 | #endif |
|
- | 381 | ||
- | 382 | #ifdef __64_BITS__ |
|
- | 383 | printf("%-2u %-5d %#18zx %s\n", i, |
|
- | 384 | breakpoints[i].counter, breakpoints[i].address, |
|
- | 385 | symbol); |
|
- | 386 | #endif |
|
- | 387 | ||
- | 388 | } |
|
- | 389 | return 1; |
|
- | 390 | } |
|
- | 391 | ||
- | 392 | /** Remove breakpoint from table */ |
|
- | 393 | int cmd_del_breakpoint(cmd_arg_t *argv) |
|
- | 394 | { |
|
- | 395 | unative_t bpno = argv->intval; |
|
- | 396 | if (bpno > BKPOINTS_MAX) { |
|
- | 397 | printf("Invalid breakpoint number.\n"); |
|
- | 398 | return 0; |
|
- | 399 | } |
|
- | 400 | breakpoint_del(argv->intval); |
|
- | 401 | return 1; |
|
- | 402 | } |
|
- | 403 | ||
- | 404 | /** Add new breakpoint to table */ |
|
- | 405 | static int cmd_add_breakpoint(cmd_arg_t *argv) |
|
- | 406 | { |
|
- | 407 | int flags; |
|
- | 408 | int id; |
|
- | 409 | ||
- | 410 | if (argv == &add_argv) { |
|
- | 411 | flags = BKPOINT_INSTR; |
|
- | 412 | } else { /* addwatchp */ |
|
- | 413 | flags = BKPOINT_WRITE; |
|
- | 414 | } |
|
- | 415 | printf("Adding breakpoint on address: %p\n", argv->intval); |
|
- | 416 | id = breakpoint_add((void *)argv->intval, flags, -1); |
|
- | 417 | if (id < 0) |
|
- | 418 | printf("Add breakpoint failed.\n"); |
|
- | 419 | else |
|
- | 420 | printf("Added breakpoint %d.\n", id); |
|
- | 421 | ||
- | 422 | return 1; |
|
- | 423 | } |
|
- | 424 | #endif /* CONFIG_KCONSOLE */ |
|
- | 425 | ||
421 | /** @} |
426 | /** @} |
422 | */ |
427 | */ |
423 | 428 |