rename amd64 architecture to x86_64
[dragonfly.git] / sys / platform / pc64 / x86_64 / db_trace.c
CommitLineData
d7f50089 1/*
c8fe38ae
MD
2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 * 3. Neither the name of The DragonFly Project nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific, prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * --
32 *
d7f50089
YY
33 * Mach Operating System
34 * Copyright (c) 1991,1990 Carnegie Mellon University
35 * All Rights Reserved.
36 *
37 * Permission to use, copy, modify and distribute this software and its
38 * documentation is hereby granted, provided that both the copyright
39 * notice and this permission notice appear in all copies of the
40 * software, derivative works or modified versions, and any portions
41 * thereof, and that both notices appear in supporting documentation.
42 *
43 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
44 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
45 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 *
47 * Carnegie Mellon requests users of this software to return to
48 *
49 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
50 * School of Computer Science
51 * Carnegie Mellon University
52 * Pittsburgh PA 15213-3890
53 *
54 * any improvements or extensions that they make and grant Carnegie the
55 * rights to redistribute these changes.
56 *
57 * $FreeBSD: src/sys/i386/i386/db_trace.c,v 1.35.2.3 2002/02/21 22:31:25 silby Exp $
d7f50089
YY
58 */
59
60#include <sys/param.h>
61#include <sys/systm.h>
62#include <sys/linker_set.h>
63#include <sys/lock.h>
64#include <sys/proc.h>
65#include <sys/reg.h>
66
67#include <machine/cpu.h>
68#include <machine/md_var.h>
69
70#include <vm/vm.h>
71#include <vm/vm_param.h>
72#include <vm/pmap.h>
73#include <vm/vm_map.h>
74#include <ddb/ddb.h>
75#include <dlfcn.h> /* DLL */
76
77#include <sys/user.h>
78
79#include <ddb/db_access.h>
80#include <ddb/db_sym.h>
81#include <ddb/db_variables.h>
82
83db_varfcn_t db_dr0;
84db_varfcn_t db_dr1;
85db_varfcn_t db_dr2;
86db_varfcn_t db_dr3;
87db_varfcn_t db_dr4;
88db_varfcn_t db_dr5;
89db_varfcn_t db_dr6;
90db_varfcn_t db_dr7;
91
92/*
93 * Machine register set.
94 */
95struct db_variable db_regs[] = {
60233e58
SW
96 { "cs", &ddb_regs.tf_cs, NULL },
97/* { "ds", &ddb_regs.tf_ds, NULL },
98 { "es", &ddb_regs.tf_es, NULL },
99 { "fs", &ddb_regs.tf_fs, NULL },
100 { "gs", &ddb_regs.tf_gs, NULL }, */
101 { "ss", &ddb_regs.tf_ss, NULL },
102 { "rax", &ddb_regs.tf_rax, NULL },
103 { "rcx", &ddb_regs.tf_rcx, NULL },
104 { "rdx", &ddb_regs.tf_rdx, NULL },
105 { "rbx", &ddb_regs.tf_rbx, NULL },
106 { "rsp", &ddb_regs.tf_rsp, NULL },
107 { "rbp", &ddb_regs.tf_rbp, NULL },
108 { "rsi", &ddb_regs.tf_rsi, NULL },
109 { "rdi", &ddb_regs.tf_rdi, NULL },
110 { "rip", &ddb_regs.tf_rip, NULL },
111 { "rfl", &ddb_regs.tf_rflags, NULL },
112 { "r8", &ddb_regs.tf_r8, NULL },
113 { "r9", &ddb_regs.tf_r9, NULL },
114 { "r10", &ddb_regs.tf_r10, NULL },
115 { "r11", &ddb_regs.tf_r11, NULL },
116 { "r12", &ddb_regs.tf_r12, NULL },
117 { "r13", &ddb_regs.tf_r13, NULL },
118 { "r14", &ddb_regs.tf_r14, NULL },
119 { "r15", &ddb_regs.tf_r15, NULL },
d7f50089
YY
120 { "dr0", NULL, db_dr0 },
121 { "dr1", NULL, db_dr1 },
122 { "dr2", NULL, db_dr2 },
123 { "dr3", NULL, db_dr3 },
124 { "dr4", NULL, db_dr4 },
125 { "dr5", NULL, db_dr5 },
126 { "dr6", NULL, db_dr6 },
127 { "dr7", NULL, db_dr7 },
128};
129struct db_variable *db_eregs = db_regs + sizeof(db_regs)/sizeof(db_regs[0]);
130
131/*
132 * Stack trace.
133 */
134#define INKERNEL(va) (((vm_offset_t)(va)) >= USRSTACK)
135
c1543a89
SS
136struct x86_64_frame {
137 struct x86_64_frame *f_frame;
d7f50089
YY
138 long f_retaddr;
139 long f_arg0;
140};
141
142#define NORMAL 0
143#define TRAP 1
144#define INTERRUPT 2
145#define SYSCALL 3
146
c1543a89
SS
147static void db_nextframe(struct x86_64_frame **, db_addr_t *);
148static int db_numargs(struct x86_64_frame *);
c8fe38ae
MD
149static void db_print_stack_entry(const char *, int, char **, long *, db_addr_t);
150static void dl_symbol_values(long callpc, const char **name);
d7f50089
YY
151
152
153static char *watchtype_str(int type);
c1543a89 154static int kx86_64_set_watch(int watchnum, unsigned int watchaddr,
d7f50089 155 int size, int access, struct dbreg * d);
c1543a89 156static int kx86_64_clr_watch(int watchnum, struct dbreg * d);
d7f50089
YY
157int db_md_set_watchpoint(db_expr_t addr, db_expr_t size);
158int db_md_clr_watchpoint(db_expr_t addr, db_expr_t size);
159void db_md_list_watchpoints(void);
160
161
162/*
163 * Figure out how many arguments were passed into the frame at "fp".
164 */
165static int
c1543a89 166db_numargs(struct x86_64_frame *fp)
d7f50089 167{
c8fe38ae
MD
168#if 1
169 return (0); /* regparm, needs dwarf2 info */
170#else
d7f50089
YY
171 int args;
172#if 0
173 int *argp;
174 int inst;
175
176 argp = (int *)db_get_value((int)&fp->f_retaddr, 4, FALSE);
177 /*
178 * XXX etext is wrong for LKMs. We should attempt to interpret
179 * the instruction at the return address in all cases. This
180 * may require better fault handling.
181 */
182 if (argp < (int *)btext || argp >= (int *)etext) {
183 args = 5;
184 } else {
185 inst = db_get_value((int)argp, 4, FALSE);
186 if ((inst & 0xff) == 0x59) /* popl %ecx */
187 args = 1;
188 else if ((inst & 0xffff) == 0xc483) /* addl $Ibs, %esp */
189 args = ((inst >> 16) & 0xff) / 4;
190 else
191 args = 5;
192 }
193#endif
194 args = 5;
195 return(args);
c8fe38ae 196#endif
d7f50089
YY
197}
198
199static void
c8fe38ae 200db_print_stack_entry(const char *name, int narg, char **argnp, long *argp,
d7f50089
YY
201 db_addr_t callpc)
202{
203 db_printf("%s(", name);
204 while (narg) {
205 if (argnp)
206 db_printf("%s=", *argnp++);
973c11b9 207 db_printf("%ld", (long)db_get_value((long)argp, 8, FALSE));
d7f50089
YY
208 argp++;
209 if (--narg != 0)
210 db_printf(",");
c8fe38ae 211 }
d7f50089
YY
212 db_printf(") at ");
213 db_printsym(callpc, DB_STGY_PROC);
214 db_printf("\n");
215}
216
217/*
218 * Figure out the next frame up in the call stack.
219 */
220static void
c1543a89 221db_nextframe(struct x86_64_frame **fp, db_addr_t *ip)
d7f50089
YY
222{
223 struct trapframe *tf;
224 int frame_type;
c8fe38ae 225 long rip, rsp, rbp;
d7f50089
YY
226 db_expr_t offset;
227 const char *sym, *name;
228
79dca14e
MD
229 if ((unsigned long)*fp < PAGE_SIZE) {
230 *fp = NULL;
231 return;
232 }
c8fe38ae
MD
233 rip = db_get_value((long) &(*fp)->f_retaddr, 8, FALSE);
234 rbp = db_get_value((long) &(*fp)->f_frame, 8, FALSE);
d7f50089
YY
235
236 /*
237 * Figure out frame type.
238 */
239
240 frame_type = NORMAL;
241
c8fe38ae 242 sym = db_search_symbol(rip, DB_STGY_ANY, &offset);
d7f50089 243 db_symbol_values(sym, &name, NULL);
c8fe38ae 244 dl_symbol_values(rip, &name);
d7f50089
YY
245 if (name != NULL) {
246 if (!strcmp(name, "calltrap")) {
247 frame_type = TRAP;
248 } else if (!strncmp(name, "Xresume", 7)) {
249 frame_type = INTERRUPT;
250 } else if (!strcmp(name, "_Xsyscall")) {
251 frame_type = SYSCALL;
252 }
253 }
254
255 /*
256 * Normal frames need no special processing.
257 */
258 if (frame_type == NORMAL) {
c8fe38ae 259 *ip = (db_addr_t) rip;
c1543a89 260 *fp = (struct x86_64_frame *) rbp;
d7f50089
YY
261 return;
262 }
263
c8fe38ae 264 db_print_stack_entry(name, 0, 0, 0, rip);
d7f50089
YY
265
266 /*
267 * Point to base of trapframe which is just above the
268 * current frame.
269 */
c8fe38ae 270 tf = (struct trapframe *)((long)*fp + 16);
d7f50089
YY
271
272#if 0
c8fe38ae 273 rsp = (ISPL(tf->tf_cs) == SEL_UPL) ? tf->tf_rsp : (long)&tf->tf_rsp;
d7f50089 274#endif
c8fe38ae 275 rsp = (long)&tf->tf_rsp;
d7f50089
YY
276
277 switch (frame_type) {
278 case TRAP:
279 {
c8fe38ae
MD
280 rip = tf->tf_rip;
281 rbp = tf->tf_rbp;
d7f50089 282 db_printf(
973c11b9 283 "--- trap %016lx, rip = %016lx, rsp = %016lx, rbp = %016lx ---\n",
c8fe38ae 284 tf->tf_trapno, rip, rsp, rbp);
d7f50089
YY
285 }
286 break;
287 case SYSCALL:
288 {
c8fe38ae
MD
289 rip = tf->tf_rip;
290 rbp = tf->tf_rbp;
d7f50089 291 db_printf(
973c11b9 292 "--- syscall %016lx, rip = %016lx, rsp = %016lx, rbp = %016lx ---\n",
c8fe38ae 293 tf->tf_rax, rip, rsp, rbp);
d7f50089
YY
294 }
295 break;
296 case INTERRUPT:
c8fe38ae 297 tf = (struct trapframe *)((long)*fp + 16);
d7f50089 298 {
c8fe38ae
MD
299 rip = tf->tf_rip;
300 rbp = tf->tf_rbp;
d7f50089 301 db_printf(
973c11b9 302 "--- interrupt, rip = %016lx, rsp = %016lx, rbp = %016lx ---\n",
c8fe38ae 303 rip, rsp, rbp);
d7f50089
YY
304 }
305 break;
306 default:
307 break;
308 }
309
c8fe38ae 310 *ip = (db_addr_t) rip;
c1543a89 311 *fp = (struct x86_64_frame *) rbp;
d7f50089
YY
312}
313
314void
315db_stack_trace_cmd(db_expr_t addr, boolean_t have_addr, db_expr_t count,
316 char *modif)
317{
c1543a89 318 struct x86_64_frame *frame;
973c11b9 319 long *argp;
d7f50089
YY
320 db_addr_t callpc;
321 boolean_t first;
322 int i;
323
324 if (count == -1)
325 count = 1024;
326
327 if (!have_addr) {
c1543a89 328 frame = (struct x86_64_frame *)BP_REGS(&ddb_regs);
d7f50089 329 if (frame == NULL)
c1543a89 330 frame = (struct x86_64_frame *)(SP_REGS(&ddb_regs) - 8);
d7f50089
YY
331 callpc = PC_REGS(&ddb_regs);
332 } else {
333 /*
334 * Look for something that might be a frame pointer, just as
335 * a convenience.
336 */
c1543a89 337 frame = (struct x86_64_frame *)addr;
c8fe38ae 338 for (i = 0; i < 4096; i += 8) {
c1543a89 339 struct x86_64_frame *check;
d7f50089 340
c1543a89 341 check = (struct x86_64_frame *)db_get_value((long)((char *)&frame->f_frame + i), 8, FALSE);
d7f50089
YY
342 if ((char *)check - (char *)frame >= 0 &&
343 (char *)check - (char *)frame < 4096
344 ) {
345 break;
346 }
347 db_printf("%p does not look like a stack frame, skipping\n", (char *)&frame->f_frame + i);
348 }
349 if (i == 4096) {
350 db_printf("Unable to find anything that looks like a stack frame\n");
351 return;
352 }
353 frame = (void *)((char *)frame + i);
354 db_printf("Trace beginning at frame %p\n", frame);
c8fe38ae 355 callpc = (db_addr_t)db_get_value((long)&frame->f_retaddr, 8, FALSE);
d7f50089
YY
356 }
357
358 first = TRUE;
359 while (count--) {
c1543a89 360 struct x86_64_frame *actframe;
d7f50089
YY
361 int narg;
362 const char * name;
363 db_expr_t offset;
364 c_db_sym_t sym;
365#define MAXNARG 16
366 char *argnames[MAXNARG], **argnp = NULL;
367
368 sym = db_search_symbol(callpc, DB_STGY_ANY, &offset);
369 db_symbol_values(sym, &name, NULL);
370 dl_symbol_values(callpc, &name);
371
372 /*
373 * Attempt to determine a (possibly fake) frame that gives
374 * the caller's pc. It may differ from `frame' if the
375 * current function never sets up a standard frame or hasn't
376 * set one up yet or has just discarded one. The last two
377 * cases can be guessed fairly reliably for code generated
378 * by gcc. The first case is too much trouble to handle in
379 * general because the amount of junk on the stack depends
380 * on the pc (the special handling of "calltrap", etc. in
381 * db_nextframe() works because the `next' pc is special).
382 */
383 actframe = frame;
384 if (first) {
385 if (!have_addr) {
386 int instr;
387
388 instr = db_get_value(callpc, 4, FALSE);
c8fe38ae
MD
389 if ((instr & 0xffffffff) == 0xe5894855) {
390 /* pushq %rbp; movq %rsp, %rbp */
c1543a89 391 actframe = (struct x86_64_frame *)
c8fe38ae
MD
392 (SP_REGS(&ddb_regs) - 8);
393 } else if ((instr & 0xffffff) == 0xe58948) {
394 /* movq %rsp, %rbp */
c1543a89 395 actframe = (struct x86_64_frame *)
d7f50089
YY
396 SP_REGS(&ddb_regs);
397 if (ddb_regs.tf_rbp == 0) {
398 /* Fake caller's frame better. */
399 frame = actframe;
400 }
c8fe38ae 401 } else if ((instr & 0xff) == 0xc3) {
d7f50089 402 /* ret */
c1543a89 403 actframe = (struct x86_64_frame *)
c8fe38ae 404 (SP_REGS(&ddb_regs) - 8);
d7f50089
YY
405 } else if (offset == 0) {
406 /* Probably a symbol in assembler code. */
c1543a89 407 actframe = (struct x86_64_frame *)
c8fe38ae 408 (SP_REGS(&ddb_regs) - 8);
d7f50089
YY
409 }
410 } else if (name != NULL &&
411 strcmp(name, "fork_trampoline") == 0) {
412 /*
413 * Don't try to walk back on a stack for a
414 * process that hasn't actually been run yet.
415 */
416 db_print_stack_entry(name, 0, 0, 0, callpc);
417 break;
418 }
419 first = FALSE;
420 }
421
422 argp = &actframe->f_arg0;
423 narg = MAXNARG;
424 if (sym != NULL && db_sym_numargs(sym, &narg, argnames)) {
425 argnp = argnames;
426 } else {
427 narg = db_numargs(frame);
428 }
429
430 db_print_stack_entry(name, narg, argnp, argp, callpc);
431
432 if (actframe != frame) {
433 /* `frame' belongs to caller. */
434 callpc = (db_addr_t)
c8fe38ae 435 db_get_value((long)&actframe->f_retaddr, 8, FALSE);
d7f50089
YY
436 continue;
437 }
438
439 db_nextframe(&frame, &callpc);
440 if (frame == 0)
441 break;
442 }
443}
444
445void
1e5fb84b 446print_backtrace(void)
d7f50089 447{
c8fe38ae 448 register_t rbp;
d7f50089 449
c8fe38ae
MD
450 __asm __volatile("movq %%rbp, %0" : "=r" (rbp));
451 db_stack_trace_cmd(rbp, 1, -1, NULL);
d7f50089
YY
452}
453
454#define DB_DRX_FUNC(reg) \
455int \
456db_ ## reg (struct db_variable *vp, db_expr_t *valuep, int op) \
457{ \
458 if (op == DB_VAR_GET) \
459 *valuep = r ## reg (); \
460 else \
461 load_ ## reg (*valuep); \
462 \
463 return(0); \
464}
465
466DB_DRX_FUNC(dr0)
467DB_DRX_FUNC(dr1)
468DB_DRX_FUNC(dr2)
469DB_DRX_FUNC(dr3)
470DB_DRX_FUNC(dr4)
471DB_DRX_FUNC(dr5)
472DB_DRX_FUNC(dr6)
473DB_DRX_FUNC(dr7)
474
475static int
c1543a89 476kx86_64_set_watch(int watchnum, unsigned int watchaddr, int size, int access,
d7f50089
YY
477 struct dbreg *d)
478{
479 int i;
480 unsigned int mask;
481
482 if (watchnum == -1) {
483 for (i = 0, mask = 0x3; i < 4; i++, mask <<= 2)
484 if ((d->dr[7] & mask) == 0)
485 break;
486 if (i < 4)
487 watchnum = i;
488 else
489 return(-1);
490 }
c8fe38ae 491
d7f50089
YY
492 switch (access) {
493 case DBREG_DR7_EXEC:
494 size = 1; /* size must be 1 for an execution breakpoint */
495 /* fall through */
496 case DBREG_DR7_WRONLY:
497 case DBREG_DR7_RDWR:
498 break;
499 default:
500 return(-1);
501 }
502
503 /*
c8fe38ae 504 * we can watch a 1, 2, 4, or 8 byte sized location
d7f50089
YY
505 */
506 switch (size) {
507 case 1:
508 mask = 0x00;
509 break;
510 case 2:
511 mask = 0x01 << 2;
512 break;
513 case 4:
514 mask = 0x03 << 2;
c8fe38ae
MD
515 case 8:
516 mask = 0x02 << 2;
d7f50089
YY
517 break;
518 default:
519 return(-1);
520 }
521
522 mask |= access;
523
524 /* clear the bits we are about to affect */
525 d->dr[7] &= ~((0x3 << (watchnum * 2)) | (0x0f << (watchnum * 4 + 16)));
526
527 /* set drN register to the address, N=watchnum */
528 DBREG_DRX(d, watchnum) = watchaddr;
529
530 /* enable the watchpoint */
531 d->dr[7] |= (0x2 << (watchnum * 2)) | (mask << (watchnum * 4 + 16));
532
533 return(watchnum);
534}
535
536
537int
c1543a89 538kx86_64_clr_watch(int watchnum, struct dbreg *d)
d7f50089
YY
539{
540 if (watchnum < 0 || watchnum >= 4)
541 return(-1);
c8fe38ae 542
d7f50089
YY
543 d->dr[7] &= ~((0x3 << (watchnum * 2)) | (0x0f << (watchnum * 4 + 16)));
544 DBREG_DRX(d, watchnum) = 0;
c8fe38ae 545
d7f50089
YY
546 return(0);
547}
548
549
550int
551db_md_set_watchpoint(db_expr_t addr, db_expr_t size)
552{
553 int avail, wsize;
554 int i;
555 struct dbreg d;
556
557 fill_dbregs(NULL, &d);
c8fe38ae 558
d7f50089 559 avail = 0;
c8fe38ae 560 for (i = 0; i < 4; i++) {
d7f50089
YY
561 if ((d.dr[7] & (3 << (i * 2))) == 0)
562 avail++;
563 }
c8fe38ae
MD
564
565 if (avail * 8 < size)
d7f50089 566 return(-1);
c8fe38ae 567
d7f50089
YY
568 for (i=0; i < 4 && (size != 0); i++) {
569 if ((d.dr[7] & (3 << (i * 2))) == 0) {
c8fe38ae
MD
570 if (size >= 8 || (avail == 1 && size > 4))
571 wsize = 8;
572 else if (size > 2)
d7f50089
YY
573 wsize = 4;
574 else
575 wsize = size;
576 if (wsize == 3)
577 wsize++;
c1543a89 578 kx86_64_set_watch(i, addr, wsize, DBREG_DR7_WRONLY, &d);
d7f50089
YY
579 addr += wsize;
580 size -= wsize;
581 }
582 }
583
584 set_dbregs(NULL, &d);
585
586 return(0);
587}
588
589int
590db_md_clr_watchpoint(db_expr_t addr, db_expr_t size)
591{
d7f50089 592 struct dbreg d;
c8fe38ae 593 int i;
d7f50089
YY
594
595 fill_dbregs(NULL, &d);
596
c8fe38ae 597 for(i = 0; i < 4; i++) {
d7f50089
YY
598 if (d.dr[7] & (3 << (i * 2))) {
599 if ((DBREG_DRX((&d), i) >= addr) &&
600 (DBREG_DRX((&d), i) < addr + size))
c1543a89 601 kx86_64_clr_watch(i, &d);
d7f50089
YY
602 }
603 }
604
605 set_dbregs(NULL, &d);
606
607 return(0);
608}
609
610static char *
611watchtype_str(int type)
612{
613 switch (type) {
614 case DBREG_DR7_EXEC:
615 return "execute";
616 case DBREG_DR7_RDWR:
617 return "read/write";
618 case DBREG_DR7_WRONLY:
619 return "write";
620 default:
621 return "invalid";
622 }
623}
624
625void
626db_md_list_watchpoints(void)
627{
628 int i;
629 struct dbreg d;
630
631 fill_dbregs(NULL, &d);
632
633 db_printf("\nhardware watchpoints:\n");
634 db_printf(" watch status type len address\n"
635 " ----- -------- ---------- --- ----------\n");
c8fe38ae 636 for (i = 0; i < 4; i++) {
d7f50089
YY
637 if (d.dr[7] & (0x03 << (i * 2))) {
638 unsigned type, len;
639 type = (d.dr[7] >> (16 + (i * 4))) & 3;
640 len = (d.dr[7] >> (16 + (i * 4) + 2)) & 3;
973c11b9 641 db_printf(" %-5d %-8s %10s %3d 0x%08lx\n",
d7f50089
YY
642 i, "enabled", watchtype_str(type),
643 len + 1, DBREG_DRX((&d), i));
644 } else {
645 db_printf(" %-5d disabled\n", i);
646 }
647 }
648
649 db_printf("\ndebug register values:\n");
c8fe38ae 650 for (i = 0; i < 8; i++)
973c11b9 651 db_printf(" dr%d 0x%08lx\n", i, DBREG_DRX((&d),i));
d7f50089
YY
652 db_printf("\n");
653}
654
655/*
656 * See if dladdr() can get the symbol name via the standard dynamic loader.
657 */
658static
659void
c8fe38ae 660dl_symbol_values(long callpc, const char **name)
d7f50089 661{
bfc09ba0 662#if 0
d7f50089 663 Dl_info info;
d7f50089
YY
664 if (*name == NULL) {
665 if (dladdr((const void *)callpc, &info) != 0) {
666 if (info.dli_saddr <= (const void *)callpc)
667 *name = info.dli_sname;
668 }
669 }
bfc09ba0 670#endif
d7f50089
YY
671}
672