Line 0
Link Here
|
|
|
1 |
--- gdb/amd64bsd-nat.c.orig 2011-09-23 01:35:24.211306143 +0100 |
2 |
+++ gdb/amd64bsd-nat.c 2011-09-23 01:28:28.444487431 +0100 |
3 |
@@ -33,6 +33,7 @@ |
4 |
|
5 |
#include "amd64-tdep.h" |
6 |
#include "amd64-nat.h" |
7 |
+#include "amd64bsd-nat.h" |
8 |
#include "inf-ptrace.h" |
9 |
|
10 |
|
11 |
@@ -126,3 +127,80 @@ |
12 |
t->to_store_registers = amd64bsd_store_inferior_registers; |
13 |
return t; |
14 |
} |
15 |
+ |
16 |
+ |
17 |
+/* Support for debug registers. */ |
18 |
+ |
19 |
+#ifdef HAVE_PT_GETDBREGS |
20 |
+ |
21 |
+/* Not all versions of FreeBSD/i386 that support the debug registers |
22 |
+ have this macro. */ |
23 |
+#ifndef DBREG_DRX |
24 |
+#define DBREG_DRX(d, x) ((&d->dr0)[x]) |
25 |
+#endif |
26 |
+ |
27 |
+static void |
28 |
+amd64bsd_dr_set (int regnum, unsigned long value) |
29 |
+{ |
30 |
+ struct dbreg dbregs; |
31 |
+ |
32 |
+ if (ptrace (PT_GETDBREGS, PIDGET (inferior_ptid), |
33 |
+ (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) |
34 |
+ perror_with_name (_("Couldn't get debug registers")); |
35 |
+ |
36 |
+ /* For some mysterious reason, some of the reserved bits in the |
37 |
+ debug control register get set. Mask these off, otherwise the |
38 |
+ ptrace call below will fail. */ |
39 |
+ DBREG_DRX ((&dbregs), 7) &= ~(0x0000fc00); |
40 |
+ |
41 |
+ DBREG_DRX ((&dbregs), regnum) = value; |
42 |
+ |
43 |
+ if (ptrace (PT_SETDBREGS, PIDGET (inferior_ptid), |
44 |
+ (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) |
45 |
+ perror_with_name (_("Couldn't write debug registers")); |
46 |
+} |
47 |
+ |
48 |
+void |
49 |
+amd64bsd_dr_set_control (unsigned long control) |
50 |
+{ |
51 |
+ amd64bsd_dr_set (7, control); |
52 |
+} |
53 |
+ |
54 |
+void |
55 |
+amd64bsd_dr_set_addr (int regnum, CORE_ADDR addr) |
56 |
+{ |
57 |
+ gdb_assert (regnum >= 0 && regnum <= 4); |
58 |
+ |
59 |
+ amd64bsd_dr_set (regnum, addr); |
60 |
+} |
61 |
+ |
62 |
+void |
63 |
+amd64bsd_dr_reset_addr (int regnum) |
64 |
+{ |
65 |
+ gdb_assert (regnum >= 0 && regnum <= 4); |
66 |
+ |
67 |
+ amd64bsd_dr_set (regnum, 0); |
68 |
+} |
69 |
+ |
70 |
+unsigned long |
71 |
+amd64bsd_dr_get_status (void) |
72 |
+{ |
73 |
+ struct dbreg dbregs; |
74 |
+ |
75 |
+ /* FIXME: kettenis/2001-03-31: Calling perror_with_name if the |
76 |
+ ptrace call fails breaks debugging remote targets. The correct |
77 |
+ way to fix this is to add the hardware breakpoint and watchpoint |
78 |
+ stuff to the target vector. For now, just return zero if the |
79 |
+ ptrace call fails. */ |
80 |
+ if (ptrace (PT_GETDBREGS, PIDGET (inferior_ptid), |
81 |
+ (PTRACE_TYPE_ARG3) &dbregs, 0) == -1) |
82 |
+#if 0 |
83 |
+ perror_with_name (_("Couldn't read debug registers")); |
84 |
+#else |
85 |
+ return 0; |
86 |
+#endif |
87 |
+ |
88 |
+ return DBREG_DRX ((&dbregs), 6); |
89 |
+} |
90 |
+ |
91 |
+#endif /* PT_GETDBREGS */ |