ptrace.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. GDB intends to support the following hardware debug features of BookE
  2. processors:
  3. 4 hardware breakpoints (IAC)
  4. 2 hardware watchpoints (read, write and read-write) (DAC)
  5. 2 value conditions for the hardware watchpoints (DVC)
  6. For that, we need to extend ptrace so that GDB can query and set these
  7. resources. Since we're extending, we're trying to create an interface
  8. that's extendable and that covers both BookE and server processors, so
  9. that GDB doesn't need to special-case each of them. We added the
  10. following 3 new ptrace requests.
  11. 1. PTRACE_PPC_GETHWDEBUGINFO
  12. Query for GDB to discover the hardware debug features. The main info to
  13. be returned here is the minimum alignment for the hardware watchpoints.
  14. BookE processors don't have restrictions here, but server processors have
  15. an 8-byte alignment restriction for hardware watchpoints. We'd like to avoid
  16. adding special cases to GDB based on what it sees in AUXV.
  17. Since we're at it, we added other useful info that the kernel can return to
  18. GDB: this query will return the number of hardware breakpoints, hardware
  19. watchpoints and whether it supports a range of addresses and a condition.
  20. The query will fill the following structure provided by the requesting process:
  21. struct ppc_debug_info {
  22. unit32_t version;
  23. unit32_t num_instruction_bps;
  24. unit32_t num_data_bps;
  25. unit32_t num_condition_regs;
  26. unit32_t data_bp_alignment;
  27. unit32_t sizeof_condition; /* size of the DVC register */
  28. uint64_t features; /* bitmask of the individual flags */
  29. };
  30. features will have bits indicating whether there is support for:
  31. #define PPC_DEBUG_FEATURE_INSN_BP_RANGE 0x1
  32. #define PPC_DEBUG_FEATURE_INSN_BP_MASK 0x2
  33. #define PPC_DEBUG_FEATURE_DATA_BP_RANGE 0x4
  34. #define PPC_DEBUG_FEATURE_DATA_BP_MASK 0x8
  35. 2. PTRACE_SETHWDEBUG
  36. Sets a hardware breakpoint or watchpoint, according to the provided structure:
  37. struct ppc_hw_breakpoint {
  38. uint32_t version;
  39. #define PPC_BREAKPOINT_TRIGGER_EXECUTE 0x1
  40. #define PPC_BREAKPOINT_TRIGGER_READ 0x2
  41. #define PPC_BREAKPOINT_TRIGGER_WRITE 0x4
  42. uint32_t trigger_type; /* only some combinations allowed */
  43. #define PPC_BREAKPOINT_MODE_EXACT 0x0
  44. #define PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE 0x1
  45. #define PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE 0x2
  46. #define PPC_BREAKPOINT_MODE_MASK 0x3
  47. uint32_t addr_mode; /* address match mode */
  48. #define PPC_BREAKPOINT_CONDITION_MODE 0x3
  49. #define PPC_BREAKPOINT_CONDITION_NONE 0x0
  50. #define PPC_BREAKPOINT_CONDITION_AND 0x1
  51. #define PPC_BREAKPOINT_CONDITION_EXACT 0x1 /* different name for the same thing as above */
  52. #define PPC_BREAKPOINT_CONDITION_OR 0x2
  53. #define PPC_BREAKPOINT_CONDITION_AND_OR 0x3
  54. #define PPC_BREAKPOINT_CONDITION_BE_ALL 0x00ff0000 /* byte enable bits */
  55. #define PPC_BREAKPOINT_CONDITION_BE(n) (1<<((n)+16))
  56. uint32_t condition_mode; /* break/watchpoint condition flags */
  57. uint64_t addr;
  58. uint64_t addr2;
  59. uint64_t condition_value;
  60. };
  61. A request specifies one event, not necessarily just one register to be set.
  62. For instance, if the request is for a watchpoint with a condition, both the
  63. DAC and DVC registers will be set in the same request.
  64. With this GDB can ask for all kinds of hardware breakpoints and watchpoints
  65. that the BookE supports. COMEFROM breakpoints available in server processors
  66. are not contemplated, but that is out of the scope of this work.
  67. ptrace will return an integer (handle) uniquely identifying the breakpoint or
  68. watchpoint just created. This integer will be used in the PTRACE_DELHWDEBUG
  69. request to ask for its removal. Return -ENOSPC if the requested breakpoint
  70. can't be allocated on the registers.
  71. Some examples of using the structure to:
  72. - set a breakpoint in the first breakpoint register
  73. p.version = PPC_DEBUG_CURRENT_VERSION;
  74. p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
  75. p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
  76. p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
  77. p.addr = (uint64_t) address;
  78. p.addr2 = 0;
  79. p.condition_value = 0;
  80. - set a watchpoint which triggers on reads in the second watchpoint register
  81. p.version = PPC_DEBUG_CURRENT_VERSION;
  82. p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
  83. p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
  84. p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
  85. p.addr = (uint64_t) address;
  86. p.addr2 = 0;
  87. p.condition_value = 0;
  88. - set a watchpoint which triggers only with a specific value
  89. p.version = PPC_DEBUG_CURRENT_VERSION;
  90. p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
  91. p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
  92. p.condition_mode = PPC_BREAKPOINT_CONDITION_AND | PPC_BREAKPOINT_CONDITION_BE_ALL;
  93. p.addr = (uint64_t) address;
  94. p.addr2 = 0;
  95. p.condition_value = (uint64_t) condition;
  96. - set a ranged hardware breakpoint
  97. p.version = PPC_DEBUG_CURRENT_VERSION;
  98. p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
  99. p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
  100. p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
  101. p.addr = (uint64_t) begin_range;
  102. p.addr2 = (uint64_t) end_range;
  103. p.condition_value = 0;
  104. 3. PTRACE_DELHWDEBUG
  105. Takes an integer which identifies an existing breakpoint or watchpoint
  106. (i.e., the value returned from PTRACE_SETHWDEBUG), and deletes the
  107. corresponding breakpoint or watchpoint..