요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
======
Ptrace
======
GDB intends to support the following hardware debug features of BookE
processors:
4 hardware breakpoints (IAC)
2 hardware watchpoints (read, write and read-write) (DAC)
2 value conditions for the hardware watchpoints (DVC)
For that, we need to extend ptrace so that GDB can query and set these
resources. Since we're extending, we're trying to create an interface
that's extendable and that covers both BookE and server processors, so
that GDB doesn't need to special-case each of them. We added the
following 3 new ptrace requests.
1. PPC_PTRACE_GETHWDBGINFO
============================
Query for GDB to discover the hardware debug features. The main info to
be returned here is the minimum alignment for the hardware watchpoints.
BookE processors don't have restrictions here, but server processors have
an 8-byte alignment restriction for hardware watchpoints. We'd like to avoid
adding special cases to GDB based on what it sees in AUXV.
Since we're at it, we added other useful info that the kernel can return to
GDB: this query will return the number of hardware breakpoints, hardware
watchpoints and whether it supports a range of addresses and a condition.
The query will fill the following structure provided by the requesting process::
struct ppc_debug_info {
unit32_t version;
unit32_t num_instruction_bps;
unit32_t num_data_bps;
unit32_t num_condition_regs;
unit32_t data_bp_alignment;
unit32_t sizeof_condition; /* size of the DVC register */
uint64_t features; /* bitmask of the individual flags */
};
features will have bits indicating whether there is support for::
#define PPC_DEBUG_FEATURE_INSN_BP_RANGE 0x1
#define PPC_DEBUG_FEATURE_INSN_BP_MASK 0x2
#define PPC_DEBUG_FEATURE_DATA_BP_RANGE 0x4
#define PPC_DEBUG_FEATURE_DATA_BP_MASK 0x8
#define PPC_DEBUG_FEATURE_DATA_BP_DAWR 0x10
#define PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 0x20
2. PPC_PTRACE_SETHWDEBUG
Sets a hardware breakpoint or watchpoint, according to the provided structure::
struct ppc_hw_breakpoint {
uint32_t version;
#define PPC_BREAKPOINT_TRIGGER_EXECUTE 0x1
#define PPC_BREAKPOINT_TRIGGER_READ 0x2
#define PPC_BREAKPOINT_TRIGGER_WRITE 0x4
uint32_t trigger_type; /* only some combinations allowed */
#define PPC_BREAKPOINT_MODE_EXACT 0x0
#define PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE 0x1
#define PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE 0x2
#define PPC_BREAKPOINT_MODE_MASK 0x3
uint32_t addr_mode; /* address match mode */
#define PPC_BREAKPOINT_CONDITION_MODE 0x3
#define PPC_BREAKPOINT_CONDITION_NONE 0x0
#define PPC_BREAKPOINT_CONDITION_AND 0x1
#define PPC_BREAKPOINT_CONDITION_EXACT 0x1 /* different name for the same thing as above */
#define PPC_BREAKPOINT_CONDITION_OR 0x2
#define PPC_BREAKPOINT_CONDITION_AND_OR 0x3
#define PPC_BREAKPOINT_CONDITION_BE_ALL 0x00ff0000 /* byte enable bits */
#define PPC_BREAKPOINT_CONDITION_BE(n) (1<<((n)+16))
uint32_t condition_mode; /* break/watchpoint condition flags */
uint64_t addr;
uint64_t addr2;
uint64_t condition_value;
};
A request specifies one event, not necessarily just one register to be set.
For instance, if the request is for a watchpoint with a condition, both the
DAC and DVC registers will be set in the same request.
With this GDB can ask for all kinds of hardware breakpoints and watchpoints
that the BookE supports. COMEFROM breakpoints available in server processors
are not contemplated, but that is out of the scope of this work.
ptrace will return an integer (handle) uniquely identifying the breakpoint or
watchpoint just created. This integer will be used in the PPC_PTRACE_DELHWDEBUG
request to ask for its removal. Return -ENOSPC if the requested breakpoint
can't be allocated on the registers.
Some examples of using the structure to:
- set a breakpoint in the first breakpoint register::
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
p.addr = (uint64_t) address;
p.addr2 = 0;
p.condition_value = 0;
- set a watchpoint which triggers on reads in the second watchpoint register::
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
p.addr = (uint64_t) address;
p.addr2 = 0;
p.condition_value = 0;
- set a watchpoint which triggers only with a specific value::
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
p.condition_mode = PPC_BREAKPOINT_CONDITION_AND | PPC_BREAKPOINT_CONDITION_BE_ALL;
p.addr = (uint64_t) address;
p.addr2 = 0;
p.condition_value = (uint64_t) condition;
- set a ranged hardware breakpoint::
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
p.addr = (uint64_t) begin_range;
p.addr2 = (uint64_t) end_range;
p.condition_value = 0;
- set a watchpoint in server processors (BookS)::
p.version = 1;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_RW;
p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
or
p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
p.addr = (uint64_t) begin_range;
/* For PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE addr2 needs to be specified, where
* addr2 - addr <= 8 Bytes.
*/
p.addr2 = (uint64_t) end_range;
p.condition_value = 0;
3. PPC_PTRACE_DELHWDEBUG
Takes an integer which identifies an existing breakpoint or watchpoint
(i.e., the value returned from PTRACE_SETHWDEBUG), and deletes the
corresponding breakpoint or watchpoint..
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Ptrace hardware debug 확장
1-16GDB는 BookE processor의 hardware debug 기능으로 4개 instruction address comparator(IAC) breakpoint, read/write/read-write를 지원하는 2개 data address comparator(DAC) watchpoint, watchpoint용 2개 data value comparator(DVC) condition을 지원하려 합니다.
이를 위해 GDB가 resource를 조회하고 설정할 수 있도록 ptrace를 확장합니다. Interface는 BookE와 server processor를 함께 포괄하고 이후 확장할 수 있게 설계하여 GDB가 processor별 special case를 두지 않도록 했으며, 3개 ptrace request가 추가되었습니다.
GDB가 capability를 조회하고 breakpoint 또는 watchpoint를 설치한 뒤 handle로 제거합니다.
PPC_PTRACE_GETHWDBGINFO
17-50이 query는 GDB가 hardware debug 기능을 발견하도록 합니다. 가장 중요한 반환 정보는 hardware watchpoint의 최소 alignment입니다. BookE에는 제한이 없지만 server processor는 8-byte alignment 제한이 있습니다. Kernel이 이를 직접 반환하면 GDB가 AUXV 값에 따라 별도 분기할 필요가 없습니다.
Kernel은 breakpoint 수, watchpoint 수, address range와 condition 지원 여부도 반환하며 요청 process가 제공한 `struct ppc_debug_info`를 채웁니다.
struct ppc_debug_info {
unit32_t version;
unit32_t num_instruction_bps;
unit32_t num_data_bps;
unit32_t num_condition_regs;
unit32_t data_bp_alignment;
unit32_t sizeof_condition; /* size of the DVC register */
uint64_t features; /* bitmask of the individual flags */
};
| Field | Type | 의미 |
|---|---|---|
| `version` | `unit32_t` | Interface version |
| `num_instruction_bps` | `unit32_t` | Hardware instruction breakpoint 수 |
| `num_data_bps` | `unit32_t` | Hardware data watchpoint 수 |
| `num_condition_regs` | `unit32_t` | Condition register 수 |
| `data_bp_alignment` | `unit32_t` | Data breakpoint 최소 alignment |
| `sizeof_condition` | `unit32_t` | DVC register 크기 |
| `features` | `uint64_t` | 개별 capability flag bitmask |
`features` bitmask는 다음 capability를 나타냅니다.
#define PPC_DEBUG_FEATURE_INSN_BP_RANGE 0x1
#define PPC_DEBUG_FEATURE_INSN_BP_MASK 0x2
#define PPC_DEBUG_FEATURE_DATA_BP_RANGE 0x4
#define PPC_DEBUG_FEATURE_DATA_BP_MASK 0x8
#define PPC_DEBUG_FEATURE_DATA_BP_DAWR 0x10
#define PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 0x20
| Feature | Bit | 의미 |
|---|---|---|
| `PPC_DEBUG_FEATURE_INSN_BP_RANGE` | `0x1` | Instruction breakpoint range |
| `PPC_DEBUG_FEATURE_INSN_BP_MASK` | `0x2` | Instruction breakpoint mask |
| `PPC_DEBUG_FEATURE_DATA_BP_RANGE` | `0x4` | Data breakpoint range |
| `PPC_DEBUG_FEATURE_DATA_BP_MASK` | `0x8` | Data breakpoint mask |
| `PPC_DEBUG_FEATURE_DATA_BP_DAWR` | `0x10` | DAWR data breakpoint |
| `PPC_DEBUG_FEATURE_DATA_BP_ARCH_31` | `0x20` | Power ISA 3.1 data breakpoint |
PPC_PTRACE_SETHWDEBUG
51-94제공한 `struct ppc_hw_breakpoint`에 따라 hardware breakpoint 또는 watchpoint를 설정합니다.
struct ppc_hw_breakpoint {
uint32_t version;
#define PPC_BREAKPOINT_TRIGGER_EXECUTE 0x1
#define PPC_BREAKPOINT_TRIGGER_READ 0x2
#define PPC_BREAKPOINT_TRIGGER_WRITE 0x4
uint32_t trigger_type; /* only some combinations allowed */
#define PPC_BREAKPOINT_MODE_EXACT 0x0
#define PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE 0x1
#define PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE 0x2
#define PPC_BREAKPOINT_MODE_MASK 0x3
uint32_t addr_mode; /* address match mode */
#define PPC_BREAKPOINT_CONDITION_MODE 0x3
#define PPC_BREAKPOINT_CONDITION_NONE 0x0
#define PPC_BREAKPOINT_CONDITION_AND 0x1
#define PPC_BREAKPOINT_CONDITION_EXACT 0x1 /* different name for the same thing as above */
#define PPC_BREAKPOINT_CONDITION_OR 0x2
#define PPC_BREAKPOINT_CONDITION_AND_OR 0x3
#define PPC_BREAKPOINT_CONDITION_BE_ALL 0x00ff0000 /* byte enable bits */
#define PPC_BREAKPOINT_CONDITION_BE(n) (1<<((n)+16))
uint32_t condition_mode; /* break/watchpoint condition flags */
uint64_t addr;
uint64_t addr2;
uint64_t condition_value;
};
| Field | 값 | 역할 |
|---|---|---|
| `trigger_type` | `EXECUTE`, `READ`, `WRITE` 조합 | Breakpoint 또는 watchpoint trigger |
| `addr_mode` | `EXACT`, `RANGE_INCLUSIVE`, `RANGE_EXCLUSIVE`, `MASK` | Address matching 방식 |
| `condition_mode` | `NONE`, `AND`/`EXACT`, `OR`, `AND_OR`, byte-enable bit | DVC value condition |
| `addr`, `addr2`, `condition_value` | 64-bit 값 | Address, 두 번째 address/mask, 비교 값 |
Request 하나는 register 하나가 아니라 event 하나를 지정합니다. 예를 들어 value condition이 있는 watchpoint는 같은 request에서 DAC와 DVC register를 함께 설정합니다.
이 interface로 GDB는 BookE가 지원하는 hardware breakpoint와 watchpoint를 요청할 수 있습니다. Server processor의 COMEFROM breakpoint는 이 작업 범위에 포함되지 않습니다.
Ptrace는 새 breakpoint 또는 watchpoint를 고유하게 식별하는 integer handle을 반환합니다. 이후 `PPC_PTRACE_DELHWDEBUG`에서 이 handle을 사용합니다. 필요한 register resource를 할당할 수 없으면 `-ENOSPC`를 반환합니다.
하나의 logical request가 address와 value condition에 필요한 hardware register를 함께 점유합니다.
Exact execution breakpoint 예
95-106첫 번째 breakpoint register에 exact-address execution breakpoint를 설정하는 예입니다.
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
p.addr = (uint64_t) address;
p.addr2 = 0;
p.condition_value = 0;
Read watchpoint 예
107-116두 번째 watchpoint register에서 read access에 trigger되는 exact-address watchpoint를 설정합니다.
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
p.addr = (uint64_t) address;
p.addr2 = 0;
p.condition_value = 0;
특정 값 조건 watchpoint 예
117-126모든 byte를 enable하고 지정 value와 AND/EXACT condition이 맞을 때만 trigger되는 read watchpoint입니다.
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_READ;
p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
p.condition_mode = PPC_BREAKPOINT_CONDITION_AND | PPC_BREAKPOINT_CONDITION_BE_ALL;
p.addr = (uint64_t) address;
p.addr2 = 0;
p.condition_value = (uint64_t) condition;
Inclusive range breakpoint 예
127-136`begin_range`부터 `end_range`까지를 포함하는 hardware execution breakpoint를 설정합니다.
p.version = PPC_DEBUG_CURRENT_VERSION;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_EXECUTE;
p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
p.addr = (uint64_t) begin_range;
p.addr2 = (uint64_t) end_range;
p.condition_value = 0;
Server processor BookS watchpoint 예
137-152BookS server processor에서는 read-write trigger를 사용하며 inclusive range 또는 exact mode를 선택합니다. Inclusive range라면 `addr2`를 지정해야 하고 `addr2 - addr`는 8 bytes 이하여야 합니다.
p.version = 1;
p.trigger_type = PPC_BREAKPOINT_TRIGGER_RW;
p.addr_mode = PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE;
or
p.addr_mode = PPC_BREAKPOINT_MODE_EXACT;
p.condition_mode = PPC_BREAKPOINT_CONDITION_NONE;
p.addr = (uint64_t) begin_range;
/* For PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE addr2 needs to be specified, where
* addr2 - addr <= 8 Bytes.
*/
p.addr2 = (uint64_t) end_range;
p.condition_value = 0;
PPC_PTRACE_DELHWDEBUG
153-157기존 breakpoint 또는 watchpoint를 식별하는 integer, 즉 `PTRACE_SETHWDEBUG`가 반환한 handle을 받아 대응하는 hardware debug event를 삭제합니다.
요약과 해설
ptrace.rst:1-157GDB는 먼저 hardware debug capability와 alignment를 조회하고, 하나의 logical request로 DAC/DVC resource를 묶어 설치한 뒤 kernel이 돌려준 integer handle로 삭제합니다. BookS range watchpoint의 8-byte 제약과 `-ENOSPC` 처리도 ABI의 일부입니다.