ptrace.rst 6.1 KB

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