ptrace.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #define PPC_DEBUG_FEATURE_DATA_BP_DAWR 0x10
  36. 2. PTRACE_SETHWDEBUG
  37. Sets a hardware breakpoint or watchpoint, according to the provided structure:
  38. struct ppc_hw_breakpoint {
  39. uint32_t version;
  40. #define PPC_BREAKPOINT_TRIGGER_EXECUTE 0x1
  41. #define PPC_BREAKPOINT_TRIGGER_READ 0x2
  42. #define PPC_BREAKPOINT_TRIGGER_WRITE 0x4
  43. uint32_t trigger_type; /* only some combinations allowed */
  44. #define PPC_BREAKPOINT_MODE_EXACT 0x0
  45. #define PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE 0x1
  46. #define PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE 0x2
  47. #define PPC_BREAKPOINT_MODE_MASK 0x3
  48. uint32_t addr_mode; /* address match mode */
  49. #define PPC_BREAKPOINT_CONDITION_MODE 0x3
  50. #define PPC_BREAKPOINT_CONDITION_NONE 0x0
  51. #define PPC_BREAKPOINT_CONDITION_AND 0x1
  52. #define PPC_BREAKPOINT_CONDITION_EXACT 0x1 /* different name for the same thing as above */
  53. #define PPC_BREAKPOINT_CONDITION_OR 0x2
  54. #define PPC_BREAKPOINT_CONDITION_AND_OR 0x3
  55. #define PPC_BREAKPOINT_CONDITION_BE_ALL 0x00ff0000 /* byte enable bits */
  56. #define PPC_BREAKPOINT_CONDITION_BE(n) (1<<((n)+16))
  57. uint32_t condition_mode; /* break/watchpoint condition flags */
  58. uint64_t addr;
  59. uint64_t addr2;
  60. uint64_t condition_value;
  61. };
  62. A request specifies one event, not necessarily just one register to be set.
  63. For instance, if the request is for a watchpoint with a condition, both the
  64. DAC and DVC registers will be set in the same request.
  65. With this GDB can ask for all kinds of hardware breakpoints and watchpoints
  66. that the BookE supports. COMEFROM breakpoints available in server processors
  67. are not contemplated, but that is out of the scope of this work.
  68. ptrace will return an integer (handle) uniquely identifying the breakpoint or
  69. watchpoint just created. This integer will be used in the PTRACE_DELHWDEBUG
  70. request to ask for its removal. Return -ENOSPC if the requested breakpoint
  71. can't be allocated on the registers.
  72. Some examples of using the structure to:
  73. - set a breakpoint in the first breakpoint register
  74. p.version = PPC_DEBUG_CURRENT_VERSION;
  75. p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
  76. p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
  77. p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
  78. p.addr = (uint64_t) address;
  79. p.addr2 = 0;
  80. p.condition_value = 0;
  81. - set a watchpoint which triggers on reads in the second watchpoint register
  82. p.version = PPC_DEBUG_CURRENT_VERSION;
  83. p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
  84. p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
  85. p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
  86. p.addr = (uint64_t) address;
  87. p.addr2 = 0;
  88. p.condition_value = 0;
  89. - set a watchpoint which triggers only with a specific value
  90. p.version = PPC_DEBUG_CURRENT_VERSION;
  91. p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
  92. p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
  93. p.condition_mode = PPC_BREAKPOINT_CONDITION_AND | PPC_BREAKPOINT_CONDITION_BE_ALL;
  94. p.addr = (uint64_t) address;
  95. p.addr2 = 0;
  96. p.condition_value = (uint64_t) condition;
  97. - set a ranged hardware breakpoint
  98. p.version = PPC_DEBUG_CURRENT_VERSION;
  99. p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
  100. p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
  101. p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
  102. p.addr = (uint64_t) begin_range;
  103. p.addr2 = (uint64_t) end_range;
  104. p.condition_value = 0;
  105. - set a watchpoint in server processors (BookS)
  106. p.version = 1;
  107. p.trigger_type = PPC_BREAKPOINT_TRIGGER_RW;
  108. p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
  109. or
  110. p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
  111. p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
  112. p.addr = (uint64_t) begin_range;
  113. /* For PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE addr2 needs to be specified, where
  114. * addr2 - addr <= 8 Bytes.
  115. */
  116. p.addr2 = (uint64_t) end_range;
  117. p.condition_value = 0;
  118. 3. PTRACE_DELHWDEBUG
  119. Takes an integer which identifies an existing breakpoint or watchpoint
  120. (i.e., the value returned from PTRACE_SETHWDEBUG), and deletes the
  121. corresponding breakpoint or watchpoint..