15796c8dcSSimon Schubert /* Native-dependent code for the i386. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert Low level functions to implement Oeprating System specific 45796c8dcSSimon Schubert code to manipulate I386 debug registers. 55796c8dcSSimon Schubert 6*ef5ccd6cSJohn Marino Copyright (C) 2009-2013 Free Software Foundation, Inc. 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This file is part of GDB. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 115796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 125796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 135796c8dcSSimon Schubert (at your option) any later version. 145796c8dcSSimon Schubert 155796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 165796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 175796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 185796c8dcSSimon Schubert GNU General Public License for more details. 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 215796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert #ifndef I386_NAT_H 245796c8dcSSimon Schubert #define I386_NAT_H 1 255796c8dcSSimon Schubert 265796c8dcSSimon Schubert /* Hardware-assisted breakpoints and watchpoints. */ 275796c8dcSSimon Schubert 285796c8dcSSimon Schubert /* Add watchpoint methods to the provided target_ops. 295796c8dcSSimon Schubert Targets using i386 family debug registers for watchpoints should call 305796c8dcSSimon Schubert this. */ 315796c8dcSSimon Schubert struct target_ops; 325796c8dcSSimon Schubert extern void i386_use_watchpoints (struct target_ops *); 335796c8dcSSimon Schubert 345796c8dcSSimon Schubert /* Support for hardware watchpoints and breakpoints using the i386 355796c8dcSSimon Schubert debug registers. 365796c8dcSSimon Schubert 375796c8dcSSimon Schubert This provides several functions for inserting and removing 385796c8dcSSimon Schubert hardware-assisted breakpoints and watchpoints, testing if one or 395796c8dcSSimon Schubert more of the watchpoints triggered and at what address, checking 405796c8dcSSimon Schubert whether a given region can be watched, etc. 415796c8dcSSimon Schubert 425796c8dcSSimon Schubert In addition, each target should provide several low-level functions 435796c8dcSSimon Schubert regrouped into i386_dr_low_type struct below. These functions 445796c8dcSSimon Schubert that will be called to insert watchpoints and hardware breakpoints 455796c8dcSSimon Schubert into the inferior, remove them, and check their status. These 465796c8dcSSimon Schubert functions are: 475796c8dcSSimon Schubert 485796c8dcSSimon Schubert set_control -- set the debug control (DR7) 49cf7f2e2dSJohn Marino register to a given value for all LWPs 505796c8dcSSimon Schubert 515796c8dcSSimon Schubert set_addr -- put an address into one debug 52cf7f2e2dSJohn Marino register for all LWPs 535796c8dcSSimon Schubert 54*ef5ccd6cSJohn Marino get_addr -- return the address in a given debug 55*ef5ccd6cSJohn Marino register of the current LWP 565796c8dcSSimon Schubert 575796c8dcSSimon Schubert get_status -- return the value of the debug 58cf7f2e2dSJohn Marino status (DR6) register for current LWP 59cf7f2e2dSJohn Marino 60*ef5ccd6cSJohn Marino get_control -- return the value of the debug 61*ef5ccd6cSJohn Marino control (DR7) register for current LWP 625796c8dcSSimon Schubert 635796c8dcSSimon Schubert Additionally, the native file should set the debug_register_length 645796c8dcSSimon Schubert field to 4 or 8 depending on the number of bytes used for 655796c8dcSSimon Schubert deubg registers. */ 665796c8dcSSimon Schubert 675796c8dcSSimon Schubert struct i386_dr_low_type 685796c8dcSSimon Schubert { 695796c8dcSSimon Schubert void (*set_control) (unsigned long); 705796c8dcSSimon Schubert void (*set_addr) (int, CORE_ADDR); 71*ef5ccd6cSJohn Marino CORE_ADDR (*get_addr) (int); 725796c8dcSSimon Schubert unsigned long (*get_status) (void); 73*ef5ccd6cSJohn Marino unsigned long (*get_control) (void); 745796c8dcSSimon Schubert int debug_register_length; 755796c8dcSSimon Schubert }; 765796c8dcSSimon Schubert 775796c8dcSSimon Schubert extern struct i386_dr_low_type i386_dr_low; 785796c8dcSSimon Schubert 79*ef5ccd6cSJohn Marino /* Debug registers' indices. */ 80*ef5ccd6cSJohn Marino #define DR_FIRSTADDR 0 81*ef5ccd6cSJohn Marino #define DR_LASTADDR 3 82*ef5ccd6cSJohn Marino #define DR_NADDR 4 /* The number of debug address registers. */ 83*ef5ccd6cSJohn Marino #define DR_STATUS 6 /* Index of debug status register (DR6). */ 84*ef5ccd6cSJohn Marino #define DR_CONTROL 7 /* Index of debug control register (DR7). */ 85*ef5ccd6cSJohn Marino 86*ef5ccd6cSJohn Marino /* Global state needed to track h/w watchpoints. */ 87*ef5ccd6cSJohn Marino 88*ef5ccd6cSJohn Marino struct i386_debug_reg_state 89*ef5ccd6cSJohn Marino { 90*ef5ccd6cSJohn Marino /* Mirror the inferior's DRi registers. We keep the status and 91*ef5ccd6cSJohn Marino control registers separated because they don't hold addresses. 92*ef5ccd6cSJohn Marino Note that since we can change these mirrors while threads are 93*ef5ccd6cSJohn Marino running, we never trust them to explain a cause of a trap. 94*ef5ccd6cSJohn Marino For that, we need to peek directly in the inferior registers. */ 95*ef5ccd6cSJohn Marino CORE_ADDR dr_mirror[DR_NADDR]; 96*ef5ccd6cSJohn Marino unsigned dr_status_mirror, dr_control_mirror; 97*ef5ccd6cSJohn Marino 98*ef5ccd6cSJohn Marino /* Reference counts for each debug register. */ 99*ef5ccd6cSJohn Marino int dr_ref_count[DR_NADDR]; 100*ef5ccd6cSJohn Marino }; 101*ef5ccd6cSJohn Marino 1025796c8dcSSimon Schubert /* Use this function to set i386_dr_low debug_register_length field 1035796c8dcSSimon Schubert rather than setting it directly to check that the length is only 1045796c8dcSSimon Schubert set once. It also enables the 'maint set/show show-debug-regs' 1055796c8dcSSimon Schubert command. */ 1065796c8dcSSimon Schubert 1075796c8dcSSimon Schubert extern void i386_set_debug_register_length (int len); 1085796c8dcSSimon Schubert 1095796c8dcSSimon Schubert /* Use this function to reset the i386-nat.c debug register state. */ 1105796c8dcSSimon Schubert 1115796c8dcSSimon Schubert extern void i386_cleanup_dregs (void); 1125796c8dcSSimon Schubert 113*ef5ccd6cSJohn Marino /* Return a pointer to the local mirror of the debug registers of 114*ef5ccd6cSJohn Marino process PID. */ 115*ef5ccd6cSJohn Marino 116*ef5ccd6cSJohn Marino extern struct i386_debug_reg_state *i386_debug_reg_state (pid_t pid); 117*ef5ccd6cSJohn Marino 118*ef5ccd6cSJohn Marino /* Called whenever GDB is no longer debugging process PID. It deletes 119*ef5ccd6cSJohn Marino data structures that keep track of debug register state. */ 120*ef5ccd6cSJohn Marino 121*ef5ccd6cSJohn Marino extern void i386_forget_process (pid_t pid); 122*ef5ccd6cSJohn Marino 1235796c8dcSSimon Schubert #endif /* I386_NAT_H */ 124