Commit | Line | Data |
---|---|---|
e6f9de87 DE |
1 | /* Misc. low level support for i386. |
2 | ||
3 | Copyright (C) 2009 | |
4 | Free Software Foundation, Inc. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | /* Support for hardware watchpoints and breakpoints using the i386 | |
22 | debug registers. | |
23 | ||
24 | This provides several functions for inserting and removing | |
25 | hardware-assisted breakpoints and watchpoints, testing if one or | |
26 | more of the watchpoints triggered and at what address, checking | |
27 | whether a given region can be watched, etc. | |
28 | ||
29 | The functions below implement debug registers sharing by reference | |
30 | counts, and allow to watch regions up to 16 bytes long | |
31 | (32 bytes on 64 bit hosts). */ | |
32 | ||
33 | ||
34 | /* Debug registers' indices. */ | |
35 | #define DR_FIRSTADDR 0 | |
36 | #define DR_LASTADDR 3 | |
37 | #define DR_NADDR 4 /* The number of debug address registers. */ | |
38 | #define DR_STATUS 6 | |
39 | #define DR_CONTROL 7 | |
40 | ||
41 | /* Global state needed to track h/w watchpoints. */ | |
42 | ||
43 | struct i386_debug_reg_state | |
44 | { | |
45 | /* Mirror the inferior's DRi registers. We keep the status and | |
46 | control registers separated because they don't hold addresses. */ | |
47 | CORE_ADDR dr_mirror[DR_NADDR]; | |
48 | unsigned dr_status_mirror, dr_control_mirror; | |
49 | ||
50 | /* Reference counts for each debug register. */ | |
51 | int dr_ref_count[DR_NADDR]; | |
52 | }; | |
53 | ||
54 | /* Initialize STATE. */ | |
55 | extern void i386_low_init_dregs (struct i386_debug_reg_state *state); | |
56 | ||
57 | /* Insert a watchpoint to watch a memory region which starts at | |
58 | address ADDR and whose length is LEN bytes. Watch memory accesses | |
59 | of the type TYPE_FROM_PACKET. Return 0 on success, -1 on failure. */ | |
60 | extern int i386_low_insert_watchpoint (struct i386_debug_reg_state *state, | |
61 | char type_from_packet, CORE_ADDR addr, | |
62 | int len); | |
63 | ||
64 | /* Remove a watchpoint that watched the memory region which starts at | |
65 | address ADDR, whose length is LEN bytes, and for accesses of the | |
66 | type TYPE_FROM_PACKET. Return 0 on success, -1 on failure. */ | |
67 | extern int i386_low_remove_watchpoint (struct i386_debug_reg_state *state, | |
68 | char type_from_packet, CORE_ADDR addr, | |
69 | int len); | |
70 | ||
71 | /* Return non-zero if we can watch a memory region that starts at | |
72 | address ADDR and whose length is LEN bytes. */ | |
73 | extern int i386_low_region_ok_for_watchpoint (struct i386_debug_reg_state *state, | |
74 | CORE_ADDR addr, int len); | |
75 | ||
76 | /* If the inferior has some break/watchpoint that triggered, set the | |
77 | address associated with that break/watchpoint and return true. | |
78 | Otherwise, return false. */ | |
79 | extern int i386_low_stopped_data_address (struct i386_debug_reg_state *state, | |
80 | CORE_ADDR *addr_p); | |
81 | ||
82 | /* Return true if the inferior has some watchpoint that triggered. | |
83 | Otherwise return false. */ | |
84 | extern int i386_low_stopped_by_watchpoint (struct i386_debug_reg_state *state); | |
85 | \f | |
86 | /* Each target needs to provide several low-level functions | |
87 | that will be called to insert watchpoints and hardware breakpoints | |
88 | into the inferior, remove them, and check their status. These | |
89 | functions are: | |
90 | ||
91 | i386_dr_low_set_control -- set the debug control (DR7) | |
92 | register to a given value | |
93 | ||
94 | i386_dr_low_set_addr -- put an address into one debug register | |
95 | ||
96 | i386_dr_low_get_status -- return the value of the debug | |
97 | status (DR6) register. | |
98 | */ | |
99 | ||
100 | /* Update the inferior's debug register REGNUM from STATE. */ | |
101 | extern void i386_dr_low_set_addr (const struct i386_debug_reg_state *state, | |
102 | int regnum); | |
103 | ||
104 | /* Update the inferior's DR7 debug control register from STATE. */ | |
105 | extern void i386_dr_low_set_control (const struct i386_debug_reg_state *state); | |
106 | ||
107 | /* Get the value of the inferior's DR6 debug status register | |
108 | and record it in STATE. */ | |
109 | extern void i386_dr_low_get_status (struct i386_debug_reg_state *state); |