tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/powerpc/ptrace/ptrace-hwbreak.c- Extension
.c- Size
- 17681 bytes
- Lines
- 628
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/ptrace.hunistd.hstddef.hsys/user.hstdio.hstdlib.hsignal.hsys/types.hsys/wait.hsys/syscall.hlinux/limits.hptrace.hreg.h
Detected Declarations
struct gstructfunction get_dbginfofunction dawr_presentfunction write_varfunction read_varfunction test_workloadfunction check_successfunction ptrace_set_debugregfunction ptrace_sethwdebugfunction ptrace_delhwdebugfunction test_set_debugregfunction test_set_debugreg_kernel_userspacefunction get_ppc_hw_breakpointfunction test_sethwdebug_exactfunction test_sethwdebug_exact_kernel_userspacefunction test_sethwdebug_range_alignedfunction test_multi_sethwdebug_rangefunction test_multi_sethwdebug_range_dawr_overlapfunction test_sethwdebug_range_unalignedfunction test_sethwdebug_range_unaligned_darfunction test_sethwdebug_dawr_max_rangefunction run_testsfunction ptrace_hwbreakfunction main
Annotated Snippet
struct gstruct {
__u8 a[A_LEN]; /* double word aligned */
__u8 b[B_LEN]; /* double word unaligned */
};
static volatile struct gstruct gstruct __attribute__((aligned(512)));
static volatile char cwd[PATH_MAX] __attribute__((aligned(8)));
static void get_dbginfo(pid_t child_pid, struct ppc_debug_info *dbginfo)
{
if (ptrace(PPC_PTRACE_GETHWDBGINFO, child_pid, NULL, dbginfo)) {
perror("Can't get breakpoint info");
exit(-1);
}
}
static bool dawr_present(struct ppc_debug_info *dbginfo)
{
return !!(dbginfo->features & PPC_DEBUG_FEATURE_DATA_BP_DAWR);
}
static void write_var(int len)
{
volatile __u8 *pcvar;
volatile __u16 *psvar;
volatile __u32 *pivar;
volatile __u64 *plvar;
switch (len) {
case 1:
pcvar = (volatile __u8 *)&glvar;
*pcvar = 0xff;
break;
case 2:
psvar = (volatile __u16 *)&glvar;
*psvar = 0xffff;
break;
case 4:
pivar = (volatile __u32 *)&glvar;
*pivar = 0xffffffff;
break;
case 8:
plvar = (volatile __u64 *)&glvar;
*plvar = 0xffffffffffffffffLL;
break;
}
}
static void read_var(int len)
{
__u8 cvar __attribute__((unused));
__u16 svar __attribute__((unused));
__u32 ivar __attribute__((unused));
__u64 lvar __attribute__((unused));
switch (len) {
case 1:
cvar = (volatile __u8)glvar;
break;
case 2:
svar = (volatile __u16)glvar;
break;
case 4:
ivar = (volatile __u32)glvar;
break;
case 8:
lvar = (volatile __u64)glvar;
break;
}
}
static void test_workload(void)
{
__u8 cvar __attribute__((unused));
__u32 ivar __attribute__((unused));
int len = 0;
if (ptrace(PTRACE_TRACEME, 0, NULL, 0)) {
perror("Child can't be traced?");
exit(-1);
}
/* Wake up father so that it sets up the first test */
kill(getpid(), SIGUSR1);
/* PTRACE_SET_DEBUGREG, WO test */
for (len = 1; len <= sizeof(glvar); len <<= 1)
write_var(len);
/* PTRACE_SET_DEBUGREG, RO test */
Annotation
- Immediate include surface: `sys/ptrace.h`, `unistd.h`, `stddef.h`, `sys/user.h`, `stdio.h`, `stdlib.h`, `signal.h`, `sys/types.h`.
- Detected declarations: `struct gstruct`, `function get_dbginfo`, `function dawr_present`, `function write_var`, `function read_var`, `function test_workload`, `function check_success`, `function ptrace_set_debugreg`, `function ptrace_sethwdebug`, `function ptrace_delhwdebug`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.