gdb/nat/x86-dregs.h - gdb

Data types defined

Macros defined

Source code

  1. /* Debug register code for x86 (i386 and x86-64).

  2.    Copyright (C) 2009-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. /* Support for hardware watchpoints and breakpoints using the x86
  15.    debug registers.

  16.    This provides several functions for inserting and removing
  17.    hardware-assisted breakpoints and watchpoints, testing if one or
  18.    more of the watchpoints triggered and at what address, checking
  19.    whether a given region can be watched, etc.

  20.    The functions below implement debug registers sharing by reference
  21.    counts, and allow to watch regions up to 16 bytes long
  22.    (32 bytes on 64 bit hosts).  */

  23. #ifndef X86_DREGS_H
  24. #define X86_DREGS_H 1

  25. /* Forward declaration.  */
  26. enum target_hw_bp_type;

  27. /* Low-level function vector.  */

  28. struct x86_dr_low_type
  29.   {
  30.     /* Set the debug control (DR7) register to a given value for
  31.        all LWPs.  May be NULL if the debug control register cannot
  32.        be set.  */
  33.     void (*set_control) (unsigned long);

  34.     /* Put an address into one debug register for all LWPs.  May
  35.        be NULL if debug registers cannot be set*/
  36.     void (*set_addr) (int, CORE_ADDR);

  37.     /* Return the address in a given debug register of the current
  38.        LWP.  */
  39.     CORE_ADDR (*get_addr) (int);

  40.     /* Return the value of the debug status (DR6) register for
  41.        current LWP.  */
  42.     unsigned long (*get_status) (void);

  43.     /* Return the value of the debug control (DR7) register for
  44.        current LWP.  */
  45.     unsigned long (*get_control) (void);

  46.     /* Number of bytes used for debug registers (4 or 8).  */
  47.     int debug_register_length;
  48.   };

  49. extern struct x86_dr_low_type x86_dr_low;

  50. /* Debug registers' indices.  */
  51. #define DR_FIRSTADDR 0
  52. #define DR_LASTADDR  3
  53. #define DR_NADDR     4        /* The number of debug address registers.  */
  54. #define DR_STATUS    6        /* Index of debug status register (DR6).  */
  55. #define DR_CONTROL   7        /* Index of debug control register (DR7).  */

  56. /* Global state needed to track h/w watchpoints.  */

  57. struct x86_debug_reg_state
  58. {
  59.   /* Mirror the inferior's DRi registers.  We keep the status and
  60.      control registers separated because they don't hold addresses.
  61.      Note that since we can change these mirrors while threads are
  62.      running, we never trust them to explain a cause of a trap.
  63.      For that, we need to peek directly in the inferior registers.  */
  64.   CORE_ADDR dr_mirror[DR_NADDR];
  65.   unsigned dr_status_mirror, dr_control_mirror;

  66.   /* Reference counts for each debug address register.  */
  67.   int dr_ref_count[DR_NADDR];
  68. };

  69. /* A macro to loop over all debug address registers.  */
  70. #define ALL_DEBUG_ADDRESS_REGISTERS(i) \
  71.   for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++)

  72. /* Insert a watchpoint to watch a memory region which starts at
  73.    address ADDR and whose length is LEN bytes.  Watch memory accesses
  74.    of the type TYPE.  Return 0 on success, -1 on failure.  */
  75. extern int x86_dr_insert_watchpoint (struct x86_debug_reg_state *state,
  76.                                      enum target_hw_bp_type type,
  77.                                      CORE_ADDR addr,
  78.                                      int len);

  79. /* Remove a watchpoint that watched the memory region which starts at
  80.    address ADDR, whose length is LEN bytes, and for accesses of the
  81.    type TYPE.  Return 0 on success, -1 on failure.  */
  82. extern int x86_dr_remove_watchpoint (struct x86_debug_reg_state *state,
  83.                                      enum target_hw_bp_type type,
  84.                                      CORE_ADDR addr,
  85.                                      int len);

  86. /* Return non-zero if we can watch a memory region that starts at
  87.    address ADDR and whose length is LEN bytes.  */
  88. extern int x86_dr_region_ok_for_watchpoint (struct x86_debug_reg_state *state,
  89.                                             CORE_ADDR addr, int len);

  90. /* If the inferior has some break/watchpoint that triggered, set the
  91.    address associated with that break/watchpoint and return true.
  92.    Otherwise, return false.  */
  93. extern int x86_dr_stopped_data_address (struct x86_debug_reg_state *state,
  94.                                         CORE_ADDR *addr_p);

  95. /* Return true if the inferior has some watchpoint that triggered.
  96.    Otherwise return false.  */
  97. extern int x86_dr_stopped_by_watchpoint (struct x86_debug_reg_state *state);

  98. #endif /* X86_DREGS_H */