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