1 /*-
2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
25 */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kdb.h>
33 #include <sys/proc.h>
34 #include <sys/sysent.h>
35
36 #include <machine/cpu.h>
37 #include <machine/frame.h>
38 #include <machine/md_var.h>
39 #include <machine/pcb.h>
40 #include <machine/reg.h>
41 #include <machine/stack.h>
42
43 #include <vm/vm.h>
44 #include <vm/vm_param.h>
45 #include <vm/pmap.h>
46
47 #include <ddb/ddb.h>
48 #include <ddb/db_access.h>
49 #include <ddb/db_sym.h>
50 #include <ddb/db_variables.h>
51
52 static db_varfcn_t db_esp;
53 static db_varfcn_t db_frame;
54 static db_varfcn_t db_frame_seg;
55 static db_varfcn_t db_gs;
56 static db_varfcn_t db_ss;
57
58 /*
59 * Machine register set.
60 */
61 #define DB_OFFSET(x) (db_expr_t *)offsetof(struct trapframe, x)
62 struct db_variable db_regs[] = {
63 { "cs", DB_OFFSET(tf_cs), db_frame_seg },
64 { "ds", DB_OFFSET(tf_ds), db_frame_seg },
65 { "es", DB_OFFSET(tf_es), db_frame_seg },
66 { "fs", DB_OFFSET(tf_fs), db_frame_seg },
67 { "gs", NULL, db_gs },
68 { "ss", NULL, db_ss },
69 { "eax", DB_OFFSET(tf_eax), db_frame },
70 { "ecx", DB_OFFSET(tf_ecx), db_frame },
71 { "edx", DB_OFFSET(tf_edx), db_frame },
72 { "ebx", DB_OFFSET(tf_ebx), db_frame },
73 { "esp", NULL, db_esp },
74 { "ebp", DB_OFFSET(tf_ebp), db_frame },
75 { "esi", DB_OFFSET(tf_esi), db_frame },
76 { "edi", DB_OFFSET(tf_edi), db_frame },
77 { "eip", DB_OFFSET(tf_eip), db_frame },
78 { "efl", DB_OFFSET(tf_eflags), db_frame },
79 };
80 struct db_variable *db_eregs = db_regs + nitems(db_regs);
81
82 static __inline int
83 get_esp(struct trapframe *tf)
84 {
85 return (TF_HAS_STACKREGS(tf) ? tf->tf_esp : (intptr_t)&tf->tf_esp);
86 }
87
88 static int
89 db_frame(struct db_variable *vp, db_expr_t *valuep, int op)
90 {
91 int *reg;
92
93 if (kdb_frame == NULL)
94 return (0);
95
96 reg = (int *)((uintptr_t)kdb_frame + (db_expr_t)vp->valuep);
97 if (op == DB_VAR_GET)
98 *valuep = *reg;
99 else
100 *reg = *valuep;
101 return (1);
102 }
103
104 static int
105 db_frame_seg(struct db_variable *vp, db_expr_t *valuep, int op)
106 {
107 struct trapframe_vm86 *tfp;
108 int off;
109 uint16_t *reg;
110
111 if (kdb_frame == NULL)
112 return (0);
113
114 off = (intptr_t)vp->valuep;
115 if (kdb_frame->tf_eflags & PSL_VM) {
116 tfp = (void *)kdb_frame;
117 switch ((intptr_t)vp->valuep) {
118 case (intptr_t)DB_OFFSET(tf_cs):
119 reg = (uint16_t *)&tfp->tf_cs;
120 break;
121 case (intptr_t)DB_OFFSET(tf_ds):
122 reg = (uint16_t *)&tfp->tf_vm86_ds;
123 break;
124 case (intptr_t)DB_OFFSET(tf_es):
125 reg = (uint16_t *)&tfp->tf_vm86_es;
126 break;
127 case (intptr_t)DB_OFFSET(tf_fs):
128 reg = (uint16_t *)&tfp->tf_vm86_fs;
129 break;
130 }
131 } else
132 reg = (uint16_t *)((uintptr_t)kdb_frame + off);
133 if (op == DB_VAR_GET)
134 *valuep = *reg;
135 else
136 *reg = *valuep;
137 return (1);
138 }
139
140 static int
141 db_esp(struct db_variable *vp, db_expr_t *valuep, int op)
142 {
143
144 if (kdb_frame == NULL)
145 return (0);
146
147 if (op == DB_VAR_GET)
148 *valuep = get_esp(kdb_frame);
149 else if (TF_HAS_STACKREGS(kdb_frame))
150 kdb_frame->tf_esp = *valuep;
151 return (1);
152 }
153
154 static int
155 db_gs(struct db_variable *vp, db_expr_t *valuep, int op)
156 {
157 struct trapframe_vm86 *tfp;
158
159 if (kdb_frame != NULL && kdb_frame->tf_eflags & PSL_VM) {
160 tfp = (void *)kdb_frame;
161 if (op == DB_VAR_GET)
162 *valuep = tfp->tf_vm86_gs;
163 else
164 tfp->tf_vm86_gs = *valuep;
165 return (1);
166 }
167 if (op == DB_VAR_GET)
168 *valuep = rgs();
169 else
170 load_gs(*valuep);
171 return (1);
172 }
173
174 static int
175 db_ss(struct db_variable *vp, db_expr_t *valuep, int op)
176 {
177
178 if (kdb_frame == NULL)
179 return (0);
180
181 if (op == DB_VAR_GET)
182 *valuep = TF_HAS_STACKREGS(kdb_frame) ? kdb_frame->tf_ss :
183 rss();
184 else if (TF_HAS_STACKREGS(kdb_frame))
185 kdb_frame->tf_ss = *valuep;
186 return (1);
187 }
188
189 #define NORMAL 0
190 #define TRAP 1
191 #define INTERRUPT 2
192 #define SYSCALL 3
193 #define DOUBLE_FAULT 4
194
195 static void db_nextframe(struct i386_frame **, db_addr_t *, struct thread *);
196 static int db_numargs(struct i386_frame *);
197 static void db_print_stack_entry(const char *, int, char **, int *, db_addr_t,
198 void *);
199 static void decode_syscall(int, struct thread *);
200
201 static const char * watchtype_str(int type);
202 int i386_set_watch(int watchnum, unsigned int watchaddr, int size, int access,
203 struct dbreg *d);
204 int i386_clr_watch(int watchnum, struct dbreg *d);
205
206 /*
207 * Figure out how many arguments were passed into the frame at "fp".
208 */
209 static int
210 db_numargs(fp)
211 struct i386_frame *fp;
212 {
213 char *argp;
214 int inst;
215 int args;
216
217 argp = (char *)db_get_value((int)&fp->f_retaddr, 4, false);
218 /*
219 * XXX etext is wrong for LKMs. We should attempt to interpret
220 * the instruction at the return address in all cases. This
221 * may require better fault handling.
222 */
223 if (argp < btext || argp >= etext) {
224 args = -1;
225 } else {
226 retry:
227 inst = db_get_value((int)argp, 4, false);
228 if ((inst & 0xff) == 0x59) /* popl %ecx */
229 args = 1;
230 else if ((inst & 0xffff) == 0xc483) /* addl $Ibs, %esp */
231 args = ((inst >> 16) & 0xff) / 4;
232 else if ((inst & 0xf8ff) == 0xc089) { /* movl %eax, %Reg */
233 argp += 2;
234 goto retry;
235 } else
236 args = -1;
237 }
238 return (args);
239 }
240
241 static void
242 db_print_stack_entry(name, narg, argnp, argp, callpc, frame)
243 const char *name;
244 int narg;
245 char **argnp;
246 int *argp;
247 db_addr_t callpc;
248 void *frame;
249 {
250 int n = narg >= 0 ? narg : 5;
251
252 db_printf("%s(", name);
253 while (n) {
254 if (argnp)
255 db_printf("%s=", *argnp++);
256 db_printf("%r", db_get_value((int)argp, 4, false));
257 argp++;
258 if (--n != 0)
259 db_printf(",");
260 }
261 if (narg < 0)
262 db_printf(",...");
263 db_printf(") at ");
264 db_printsym(callpc, DB_STGY_PROC);
265 if (frame != NULL)
266 db_printf("/frame 0x%r", (register_t)frame);
267 db_printf("\n");
268 }
269
270 static void
271 decode_syscall(int number, struct thread *td)
272 {
273 struct proc *p;
274 c_db_sym_t sym;
275 db_expr_t diff;
276 sy_call_t *f;
277 const char *symname;
278
279 db_printf(" (%d", number);
280 p = (td != NULL) ? td->td_proc : NULL;
281 if (p != NULL && 0 <= number && number < p->p_sysent->sv_size) {
282 f = p->p_sysent->sv_table[number].sy_call;
283 sym = db_search_symbol((db_addr_t)f, DB_STGY_ANY, &diff);
284 if (sym != DB_SYM_NULL && diff == 0) {
285 db_symbol_values(sym, &symname, NULL);
286 db_printf(", %s, %s", p->p_sysent->sv_name, symname);
287 }
288 }
289 db_printf(")");
290 }
291
292 /*
293 * Figure out the next frame up in the call stack.
294 */
295 static void
296 db_nextframe(struct i386_frame **fp, db_addr_t *ip, struct thread *td)
297 {
298 struct trapframe *tf;
299 int frame_type;
300 int narg;
301 int eip, esp, ebp;
302 db_expr_t offset;
303 c_db_sym_t sym;
304 const char *name;
305
306 eip = db_get_value((int) &(*fp)->f_retaddr, 4, false);
307 ebp = db_get_value((int) &(*fp)->f_frame, 4, false);
308
309 /*
310 * Figure out frame type. We look at the address just before
311 * the saved instruction pointer as the saved EIP is after the
312 * call function, and if the function being called is marked as
313 * dead (such as panic() at the end of dblfault_handler()), then
314 * the instruction at the saved EIP will be part of a different
315 * function (syscall() in this example) rather than the one that
316 * actually made the call.
317 */
318 frame_type = NORMAL;
319
320 /*
321 * This is the number of arguments that a syscall / trap / interrupt
322 * service routine passes to its callee. This number is used only for
323 * special frame types. In most cases there is one argument: the trap
324 * frame address.
325 */
326 narg = 1;
327
328 if (eip >= PMAP_TRM_MIN_ADDRESS) {
329 sym = db_search_symbol(eip - 1 - setidt_disp, DB_STGY_ANY,
330 &offset);
331 } else {
332 sym = db_search_symbol(eip - 1, DB_STGY_ANY, &offset);
333 }
334 db_symbol_values(sym, &name, NULL);
335 if (name != NULL) {
336 if (strcmp(name, "calltrap") == 0 ||
337 strcmp(name, "fork_trampoline") == 0)
338 frame_type = TRAP;
339 else if (strncmp(name, "Xatpic_intr", 11) == 0 ||
340 strncmp(name, "Xapic_isr", 9) == 0) {
341 /* Additional argument: vector number. */
342 narg = 2;
343 frame_type = INTERRUPT;
344 } else if (strcmp(name, "Xlcall_syscall") == 0 ||
345 strcmp(name, "Xint0x80_syscall") == 0)
346 frame_type = SYSCALL;
347 else if (strcmp(name, "dblfault_handler") == 0)
348 frame_type = DOUBLE_FAULT;
349 else if (strcmp(name, "Xtimerint") == 0 ||
350 strcmp(name, "Xxen_intr_upcall") == 0)
351 frame_type = INTERRUPT;
352 else if (strcmp(name, "Xcpustop") == 0 ||
353 strcmp(name, "Xrendezvous") == 0 ||
354 strcmp(name, "Xipi_intr_bitmap_handler") == 0) {
355 /* No arguments. */
356 narg = 0;
357 frame_type = INTERRUPT;
358 }
359 }
360
361 /*
362 * Normal frames need no special processing.
363 */
364 if (frame_type == NORMAL) {
365 *ip = (db_addr_t) eip;
366 *fp = (struct i386_frame *) ebp;
367 return;
368 }
369
370 db_print_stack_entry(name, 0, 0, 0, eip, &(*fp)->f_frame);
371
372 /*
373 * For a double fault, we have to snag the values from the
374 * previous TSS since a double fault uses a task gate to
375 * switch to a known good state.
376 */
377 if (frame_type == DOUBLE_FAULT) {
378 esp = PCPU_GET(common_tssp)->tss_esp;
379 eip = PCPU_GET(common_tssp)->tss_eip;
380 ebp = PCPU_GET(common_tssp)->tss_ebp;
381 db_printf(
382 "--- trap 0x17, eip = %#r, esp = %#r, ebp = %#r ---\n",
383 eip, esp, ebp);
384 *ip = (db_addr_t) eip;
385 *fp = (struct i386_frame *) ebp;
386 return;
387 }
388
389 /*
390 * Point to base of trapframe which is just above the
391 * current frame. Note that struct i386_frame already accounts for one
392 * argument.
393 */
394 tf = (struct trapframe *)((char *)*fp + sizeof(struct i386_frame) +
395 4 * (narg - 1));
396
397 esp = get_esp(tf);
398 eip = tf->tf_eip;
399 ebp = tf->tf_ebp;
400 switch (frame_type) {
401 case TRAP:
402 db_printf("--- trap %#r", tf->tf_trapno);
403 break;
404 case SYSCALL:
405 db_printf("--- syscall");
406 decode_syscall(tf->tf_eax, td);
407 break;
408 case INTERRUPT:
409 db_printf("--- interrupt");
410 break;
411 default:
412 panic("The moon has moved again.");
413 }
414 db_printf(", eip = %#r, esp = %#r, ebp = %#r ---\n", eip, esp, ebp);
415
416 switch (frame_type) {
417 case TRAP:
418 case INTERRUPT:
419 if ((tf->tf_eflags & PSL_VM) != 0 ||
420 (tf->tf_cs & SEL_RPL_MASK) != 0)
421 ebp = 0;
422 break;
423 case SYSCALL:
424 ebp = 0;
425 break;
426 }
427
428 *ip = (db_addr_t) eip;
429 *fp = (struct i386_frame *) ebp;
430 }
431
432 static int
433 db_backtrace(struct thread *td, struct trapframe *tf, struct i386_frame *frame,
434 db_addr_t pc, register_t sp, int count)
435 {
436 struct i386_frame *actframe;
437 #define MAXNARG 16
438 char *argnames[MAXNARG], **argnp = NULL;
439 const char *name;
440 int *argp;
441 db_expr_t offset;
442 c_db_sym_t sym;
443 int instr, narg;
444 bool first;
445
446 if (db_segsize(tf) == 16) {
447 db_printf(
448 "--- 16-bit%s, cs:eip = %#x:%#x, ss:esp = %#x:%#x, ebp = %#x, tf = %p ---\n",
449 (tf->tf_eflags & PSL_VM) ? " (vm86)" : "",
450 tf->tf_cs, tf->tf_eip,
451 TF_HAS_STACKREGS(tf) ? tf->tf_ss : rss(),
452 TF_HAS_STACKREGS(tf) ? tf->tf_esp : (intptr_t)&tf->tf_esp,
453 tf->tf_ebp, tf);
454 return (0);
455 }
456
457 /* 'frame' can be null initially. Just print the pc then. */
458 if (frame == NULL)
459 goto out;
460
461 /*
462 * If an indirect call via an invalid pointer caused a trap,
463 * %pc contains the invalid address while the return address
464 * of the unlucky caller has been saved by CPU on the stack
465 * just before the trap frame. In this case, try to recover
466 * the caller's address so that the first frame is assigned
467 * to the right spot in the right function, for that is where
468 * the failure actually happened.
469 *
470 * This trick depends on the fault address stashed in tf_err
471 * by trap_fatal() before entering KDB.
472 */
473 if (kdb_frame && pc == kdb_frame->tf_err) {
474 /*
475 * Find where the trap frame actually ends.
476 * It won't contain tf_esp or tf_ss unless crossing rings.
477 */
478 if (TF_HAS_STACKREGS(kdb_frame))
479 instr = (int)(kdb_frame + 1);
480 else
481 instr = (int)&kdb_frame->tf_esp;
482 pc = db_get_value(instr, 4, false);
483 }
484
485 if (count == -1)
486 count = 1024;
487
488 first = true;
489 while (count-- && !db_pager_quit) {
490 sym = db_search_symbol(pc, DB_STGY_ANY, &offset);
491 db_symbol_values(sym, &name, NULL);
492
493 /*
494 * Attempt to determine a (possibly fake) frame that gives
495 * the caller's pc. It may differ from `frame' if the
496 * current function never sets up a standard frame or hasn't
497 * set one up yet or has just discarded one. The last two
498 * cases can be guessed fairly reliably for code generated
499 * by gcc. The first case is too much trouble to handle in
500 * general because the amount of junk on the stack depends
501 * on the pc (the special handling of "calltrap", etc. in
502 * db_nextframe() works because the `next' pc is special).
503 */
504 actframe = frame;
505 if (first) {
506 first = false;
507 if (sym == C_DB_SYM_NULL && sp != 0) {
508 /*
509 * If a symbol couldn't be found, we've probably
510 * jumped to a bogus location, so try and use
511 * the return address to find our caller.
512 */
513 db_print_stack_entry(name, 0, 0, 0, pc,
514 NULL);
515 pc = db_get_value(sp, 4, false);
516 if (db_search_symbol(pc, DB_STGY_PROC,
517 &offset) == C_DB_SYM_NULL)
518 break;
519 continue;
520 } else if (tf != NULL) {
521 instr = db_get_value(pc, 4, false);
522 if ((instr & 0xffffff) == 0x00e58955) {
523 /* pushl %ebp; movl %esp, %ebp */
524 actframe = (void *)(get_esp(tf) - 4);
525 } else if ((instr & 0xffff) == 0x0000e589) {
526 /* movl %esp, %ebp */
527 actframe = (void *)get_esp(tf);
528 if (tf->tf_ebp == 0) {
529 /* Fake frame better. */
530 frame = actframe;
531 }
532 } else if ((instr & 0xff) == 0x000000c3) {
533 /* ret */
534 actframe = (void *)(get_esp(tf) - 4);
535 } else if (offset == 0) {
536 /* Probably an assembler symbol. */
537 actframe = (void *)(get_esp(tf) - 4);
538 }
539 } else if (strcmp(name, "fork_trampoline") == 0) {
540 /*
541 * Don't try to walk back on a stack for a
542 * process that hasn't actually been run yet.
543 */
544 db_print_stack_entry(name, 0, 0, 0, pc,
545 actframe);
546 break;
547 }
548 }
549
550 argp = &actframe->f_arg0;
551 narg = MAXNARG;
552 if (sym != NULL && db_sym_numargs(sym, &narg, argnames)) {
553 argnp = argnames;
554 } else {
555 narg = db_numargs(frame);
556 }
557
558 db_print_stack_entry(name, narg, argnp, argp, pc, actframe);
559
560 if (actframe != frame) {
561 /* `frame' belongs to caller. */
562 pc = (db_addr_t)
563 db_get_value((int)&actframe->f_retaddr, 4, false);
564 continue;
565 }
566
567 db_nextframe(&frame, &pc, td);
568
569 out:
570 /*
571 * 'frame' can be null here, either because it was initially
572 * null or because db_nextframe() found no frame.
573 * db_nextframe() may also have found a non-kernel frame.
574 * !INKERNEL() classifies both. Stop tracing if either,
575 * after printing the pc if it is the kernel.
576 */
577 if (frame == NULL || frame <= actframe) {
578 sym = db_search_symbol(pc, DB_STGY_ANY, &offset);
579 db_symbol_values(sym, &name, NULL);
580 db_print_stack_entry(name, 0, 0, 0, pc, frame);
581 break;
582 }
583 }
584
585 return (0);
586 }
587
588 void
589 db_trace_self(void)
590 {
591 struct i386_frame *frame;
592 db_addr_t callpc;
593 register_t ebp;
594
595 __asm __volatile("movl %%ebp,%0" : "=r" (ebp));
596 frame = (struct i386_frame *)ebp;
597 callpc = (db_addr_t)db_get_value((int)&frame->f_retaddr, 4, false);
598 frame = frame->f_frame;
599 db_backtrace(curthread, NULL, frame, callpc, 0, -1);
600 }
601
602 int
603 db_trace_thread(struct thread *thr, int count)
604 {
605 struct pcb *ctx;
606 struct trapframe *tf;
607
608 ctx = kdb_thr_ctx(thr);
609 tf = thr == kdb_thread ? kdb_frame : NULL;
610 return (db_backtrace(thr, tf, (struct i386_frame *)ctx->pcb_ebp,
611 ctx->pcb_eip, ctx->pcb_esp, count));
612 }
613
614 int
615 i386_set_watch(watchnum, watchaddr, size, access, d)
616 int watchnum;
617 unsigned int watchaddr;
618 int size;
619 int access;
620 struct dbreg *d;
621 {
622 int i, len;
623
624 if (watchnum == -1) {
625 for (i = 0; i < 4; i++)
626 if (!DBREG_DR7_ENABLED(d->dr[7], i))
627 break;
628 if (i < 4)
629 watchnum = i;
630 else
631 return (-1);
632 }
633
634 switch (access) {
635 case DBREG_DR7_EXEC:
636 size = 1; /* size must be 1 for an execution breakpoint */
637 /* fall through */
638 case DBREG_DR7_WRONLY:
639 case DBREG_DR7_RDWR:
640 break;
641 default:
642 return (-1);
643 }
644
645 /*
646 * we can watch a 1, 2, or 4 byte sized location
647 */
648 switch (size) {
649 case 1:
650 len = DBREG_DR7_LEN_1;
651 break;
652 case 2:
653 len = DBREG_DR7_LEN_2;
654 break;
655 case 4:
656 len = DBREG_DR7_LEN_4;
657 break;
658 default:
659 return (-1);
660 }
661
662 /* clear the bits we are about to affect */
663 d->dr[7] &= ~DBREG_DR7_MASK(watchnum);
664
665 /* set drN register to the address, N=watchnum */
666 DBREG_DRX(d, watchnum) = watchaddr;
667
668 /* enable the watchpoint */
669 d->dr[7] |= DBREG_DR7_SET(watchnum, len, access,
670 DBREG_DR7_GLOBAL_ENABLE);
671
672 return (watchnum);
673 }
674
675
676 int
677 i386_clr_watch(watchnum, d)
678 int watchnum;
679 struct dbreg *d;
680 {
681
682 if (watchnum < 0 || watchnum >= 4)
683 return (-1);
684
685 d->dr[7] &= ~DBREG_DR7_MASK(watchnum);
686 DBREG_DRX(d, watchnum) = 0;
687
688 return (0);
689 }
690
691
692 int
693 db_md_set_watchpoint(addr, size)
694 db_expr_t addr;
695 db_expr_t size;
696 {
697 struct dbreg d;
698 int avail, i, wsize;
699
700 fill_dbregs(NULL, &d);
701
702 avail = 0;
703 for(i = 0; i < 4; i++) {
704 if (!DBREG_DR7_ENABLED(d.dr[7], i))
705 avail++;
706 }
707
708 if (avail * 4 < size)
709 return (-1);
710
711 for (i = 0; i < 4 && (size > 0); i++) {
712 if (!DBREG_DR7_ENABLED(d.dr[7], i)) {
713 if (size > 2)
714 wsize = 4;
715 else
716 wsize = size;
717 i386_set_watch(i, addr, wsize,
718 DBREG_DR7_WRONLY, &d);
719 addr += wsize;
720 size -= wsize;
721 }
722 }
723
724 set_dbregs(NULL, &d);
725
726 return(0);
727 }
728
729
730 int
731 db_md_clr_watchpoint(addr, size)
732 db_expr_t addr;
733 db_expr_t size;
734 {
735 struct dbreg d;
736 int i;
737
738 fill_dbregs(NULL, &d);
739
740 for(i = 0; i < 4; i++) {
741 if (DBREG_DR7_ENABLED(d.dr[7], i)) {
742 if ((DBREG_DRX((&d), i) >= addr) &&
743 (DBREG_DRX((&d), i) < addr+size))
744 i386_clr_watch(i, &d);
745
746 }
747 }
748
749 set_dbregs(NULL, &d);
750
751 return(0);
752 }
753
754
755 static const char *
756 watchtype_str(type)
757 int type;
758 {
759 switch (type) {
760 case DBREG_DR7_EXEC : return "execute"; break;
761 case DBREG_DR7_RDWR : return "read/write"; break;
762 case DBREG_DR7_WRONLY : return "write"; break;
763 default : return "invalid"; break;
764 }
765 }
766
767
768 void
769 db_md_list_watchpoints(void)
770 {
771 struct dbreg d;
772 int i, len, type;
773
774 fill_dbregs(NULL, &d);
775
776 db_printf("\nhardware watchpoints:\n");
777 db_printf(" watch status type len address\n");
778 db_printf(" ----- -------- ---------- --- ----------\n");
779 for (i = 0; i < 4; i++) {
780 if (DBREG_DR7_ENABLED(d.dr[7], i)) {
781 type = DBREG_DR7_ACCESS(d.dr[7], i);
782 len = DBREG_DR7_LEN(d.dr[7], i);
783 db_printf(" %-5d %-8s %10s %3d ",
784 i, "enabled", watchtype_str(type), len + 1);
785 db_printsym((db_addr_t)DBREG_DRX(&d, i), DB_STGY_ANY);
786 db_printf("\n");
787 } else {
788 db_printf(" %-5d disabled\n", i);
789 }
790 }
791
792 db_printf("\ndebug register values:\n");
793 for (i = 0; i < 8; i++)
794 if (i != 4 && i != 5)
795 db_printf(" dr%d 0x%08x\n", i, DBREG_DRX(&d, i));
796 db_printf("\n");
797 }
Cache object: 9e78ceee9ffc713d31c35b9111f982ac
|