1 |
330 |
jeremybenn |
/* Misc. low level support for i386.
|
2 |
|
|
|
3 |
|
|
Copyright (C) 2009, 2010 Free Software Foundation, Inc.
|
4 |
|
|
|
5 |
|
|
This file is part of GDB.
|
6 |
|
|
|
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.
|
11 |
|
|
|
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.
|
16 |
|
|
|
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/>. */
|
19 |
|
|
|
20 |
|
|
/* Support for hardware watchpoints and breakpoints using the i386
|
21 |
|
|
debug registers.
|
22 |
|
|
|
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.
|
27 |
|
|
|
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). */
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/* Debug registers' indices. */
|
34 |
|
|
#define DR_FIRSTADDR 0
|
35 |
|
|
#define DR_LASTADDR 3
|
36 |
|
|
#define DR_NADDR 4 /* The number of debug address registers. */
|
37 |
|
|
#define DR_STATUS 6
|
38 |
|
|
#define DR_CONTROL 7
|
39 |
|
|
|
40 |
|
|
/* Global state needed to track h/w watchpoints. */
|
41 |
|
|
|
42 |
|
|
struct i386_debug_reg_state
|
43 |
|
|
{
|
44 |
|
|
/* Mirror the inferior's DRi registers. We keep the status and
|
45 |
|
|
control registers separated because they don't hold addresses. */
|
46 |
|
|
CORE_ADDR dr_mirror[DR_NADDR];
|
47 |
|
|
unsigned dr_status_mirror, dr_control_mirror;
|
48 |
|
|
|
49 |
|
|
/* Reference counts for each debug register. */
|
50 |
|
|
int dr_ref_count[DR_NADDR];
|
51 |
|
|
};
|
52 |
|
|
|
53 |
|
|
/* Initialize STATE. */
|
54 |
|
|
extern void i386_low_init_dregs (struct i386_debug_reg_state *state);
|
55 |
|
|
|
56 |
|
|
/* Insert a watchpoint to watch a memory region which starts at
|
57 |
|
|
address ADDR and whose length is LEN bytes. Watch memory accesses
|
58 |
|
|
of the type TYPE_FROM_PACKET. Return 0 on success, -1 on failure. */
|
59 |
|
|
extern int i386_low_insert_watchpoint (struct i386_debug_reg_state *state,
|
60 |
|
|
char type_from_packet, CORE_ADDR addr,
|
61 |
|
|
int len);
|
62 |
|
|
|
63 |
|
|
/* Remove a watchpoint that watched the memory region which starts at
|
64 |
|
|
address ADDR, whose length is LEN bytes, and for accesses of the
|
65 |
|
|
type TYPE_FROM_PACKET. Return 0 on success, -1 on failure. */
|
66 |
|
|
extern int i386_low_remove_watchpoint (struct i386_debug_reg_state *state,
|
67 |
|
|
char type_from_packet, CORE_ADDR addr,
|
68 |
|
|
int len);
|
69 |
|
|
|
70 |
|
|
/* Return non-zero if we can watch a memory region that starts at
|
71 |
|
|
address ADDR and whose length is LEN bytes. */
|
72 |
|
|
extern int i386_low_region_ok_for_watchpoint (struct i386_debug_reg_state *state,
|
73 |
|
|
CORE_ADDR addr, int len);
|
74 |
|
|
|
75 |
|
|
/* If the inferior has some break/watchpoint that triggered, set the
|
76 |
|
|
address associated with that break/watchpoint and return true.
|
77 |
|
|
Otherwise, return false. */
|
78 |
|
|
extern int i386_low_stopped_data_address (struct i386_debug_reg_state *state,
|
79 |
|
|
CORE_ADDR *addr_p);
|
80 |
|
|
|
81 |
|
|
/* Return true if the inferior has some watchpoint that triggered.
|
82 |
|
|
Otherwise return false. */
|
83 |
|
|
extern int i386_low_stopped_by_watchpoint (struct i386_debug_reg_state *state);
|
84 |
|
|
|
85 |
|
|
/* Each target needs to provide several low-level functions
|
86 |
|
|
that will be called to insert watchpoints and hardware breakpoints
|
87 |
|
|
into the inferior, remove them, and check their status. These
|
88 |
|
|
functions are:
|
89 |
|
|
|
90 |
|
|
i386_dr_low_set_control -- set the debug control (DR7)
|
91 |
|
|
register to a given value
|
92 |
|
|
|
93 |
|
|
i386_dr_low_set_addr -- put an address into one debug register
|
94 |
|
|
|
95 |
|
|
i386_dr_low_get_status -- return the value of the debug
|
96 |
|
|
status (DR6) register.
|
97 |
|
|
*/
|
98 |
|
|
|
99 |
|
|
/* Update the inferior's debug register REGNUM from STATE. */
|
100 |
|
|
extern void i386_dr_low_set_addr (const struct i386_debug_reg_state *state,
|
101 |
|
|
int regnum);
|
102 |
|
|
|
103 |
|
|
/* Update the inferior's DR7 debug control register from STATE. */
|
104 |
|
|
extern void i386_dr_low_set_control (const struct i386_debug_reg_state *state);
|
105 |
|
|
|
106 |
|
|
/* Get the value of the inferior's DR6 debug status register
|
107 |
|
|
and record it in STATE. */
|
108 |
|
|
extern void i386_dr_low_get_status (struct i386_debug_reg_state *state);
|