← Documents Documentation/arch/powerpc/ptrace.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Ptrace

PowerPC BookE와 BookS의 hardware breakpoint/watchpoint ptrace interface와 GDB 사용 예입니다.

Source pathDocumentation/arch/powerpc/ptrace.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

ptrace.rst:1-157

GDB는 먼저 hardware debug capability와 alignment를 조회하고, 하나의 logical request로 DAC/DVC resource를 묶어 설치한 뒤 kernel이 돌려준 integer handle로 삭제합니다. BookS range watchpoint의 8-byte 제약과 `-ENOSPC` 처리도 ABI의 일부입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Ptrace hardware debug 확장

1-16

GDB는 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가 추가되었습니다.

PowerPC hardware debug request lifecycle
`PPC_PTRACE_GETHWDBGINFO`Capability와 alignment 확인`PPC_PTRACE_SETHWDEBUG`Integer handle`PPC_PTRACE_DELHWDEBUG`

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 */
};
FieldType의미
`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
FeatureBit의미
`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 bitDVC 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`를 반환합니다.

조건부 watchpoint register 구성
`ppc_hw_breakpoint``addr`/`addr2`DACAddress match
`ppc_hw_breakpoint``condition_mode`/`condition_value`DVCValue match
DAC + DVCSingle watchpoint handle

하나의 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-152

BookS 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를 삭제합니다.