x86-nat.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Native-dependent code for x86 (i386 and x86-64).
  2. Low level functions to implement Operating System specific
  3. code to manipulate x86 debug registers.
  4. Copyright (C) 2009-2022 Free Software Foundation, Inc.
  5. This file is part of GDB.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #ifndef X86_NAT_H
  17. #define X86_NAT_H 1
  18. #include "breakpoint.h"
  19. #include "nat/x86-dregs.h"
  20. #include "target.h"
  21. /* Hardware-assisted breakpoints and watchpoints. */
  22. /* Use this function to set x86_dr_low debug_register_length field
  23. rather than setting it directly to check that the length is only
  24. set once. It also enables the 'maint set/show show-debug-regs'
  25. command. */
  26. extern void x86_set_debug_register_length (int len);
  27. /* Use this function to reset the x86-nat.c debug register state. */
  28. extern void x86_cleanup_dregs (void);
  29. /* Return the debug register state for process PID. If no existing
  30. state is found for this process, return nullptr. */
  31. struct x86_debug_reg_state *x86_lookup_debug_reg_state (pid_t pid);
  32. /* Called whenever GDB is no longer debugging process PID. It deletes
  33. data structures that keep track of debug register state. */
  34. extern void x86_forget_process (pid_t pid);
  35. /* Helper functions used by x86_nat_target below. See their
  36. definitions. */
  37. extern int x86_can_use_hw_breakpoint (enum bptype type, int cnt, int othertype);
  38. extern int x86_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len);
  39. extern int x86_stopped_by_watchpoint ();
  40. extern int x86_stopped_data_address (CORE_ADDR *addr_p);
  41. extern int x86_insert_watchpoint (CORE_ADDR addr, int len,
  42. enum target_hw_bp_type type,
  43. struct expression *cond);
  44. extern int x86_remove_watchpoint (CORE_ADDR addr, int len,
  45. enum target_hw_bp_type type,
  46. struct expression *cond);
  47. extern int x86_insert_hw_breakpoint (struct gdbarch *gdbarch,
  48. struct bp_target_info *bp_tgt);
  49. extern int x86_remove_hw_breakpoint (struct gdbarch *gdbarch,
  50. struct bp_target_info *bp_tgt);
  51. extern int x86_stopped_by_hw_breakpoint ();
  52. /* Convenience template mixin used to add x86 watchpoints support to a
  53. target. */
  54. template <typename BaseTarget>
  55. struct x86_nat_target : public BaseTarget
  56. {
  57. /* Hook in the x86 hardware watchpoints/breakpoints support. */
  58. int can_use_hw_breakpoint (enum bptype type, int cnt, int othertype) override
  59. { return x86_can_use_hw_breakpoint (type, cnt, othertype); }
  60. int region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) override
  61. { return x86_region_ok_for_hw_watchpoint (addr, len); }
  62. int insert_watchpoint (CORE_ADDR addr, int len,
  63. enum target_hw_bp_type type,
  64. struct expression *cond) override
  65. { return x86_insert_watchpoint (addr, len, type, cond); }
  66. int remove_watchpoint (CORE_ADDR addr, int len,
  67. enum target_hw_bp_type type,
  68. struct expression *cond) override
  69. { return x86_remove_watchpoint (addr, len, type, cond); }
  70. int insert_hw_breakpoint (struct gdbarch *gdbarch,
  71. struct bp_target_info *bp_tgt) override
  72. { return x86_insert_hw_breakpoint (gdbarch, bp_tgt); }
  73. int remove_hw_breakpoint (struct gdbarch *gdbarch,
  74. struct bp_target_info *bp_tgt) override
  75. { return x86_remove_hw_breakpoint (gdbarch, bp_tgt); }
  76. bool stopped_by_watchpoint () override
  77. { return x86_stopped_by_watchpoint (); }
  78. bool stopped_data_address (CORE_ADDR *addr_p) override
  79. { return x86_stopped_data_address (addr_p); }
  80. /* A target must provide an implementation of the
  81. "supports_stopped_by_hw_breakpoint" target method before this
  82. callback will be used. */
  83. bool stopped_by_hw_breakpoint () override
  84. { return x86_stopped_by_hw_breakpoint (); }
  85. };
  86. #endif /* X86_NAT_H */