Skip to content

Commit

Permalink
Export a breakpoint() function to userland for arm and arm64.
Browse files Browse the repository at this point in the history
Enable ptrace() tests using breakpoint() on these architectures.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D15191
  • Loading branch information
bsdjhb committed Jul 6, 2018
1 parent e38a7de commit 465d5a9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
15 changes: 14 additions & 1 deletion sys/arm/include/cpufunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
static __inline void
breakpoint(void)
{
__asm(".word 0xe7ffffff");
__asm("udf 0xffff");
}

struct cpu_functions {
Expand Down Expand Up @@ -495,6 +495,19 @@ extern u_int arm_cache_level;
extern u_int arm_cache_loc;
extern u_int arm_cache_type[14];

#else /* !_KERNEL */

static __inline void
breakpoint(void)
{

/*
* This matches the instruction used by GDB for software
* breakpoints.
*/
__asm("udf 0xfdee");
}

#endif /* _KERNEL */
#endif /* _MACHINE_CPUFUNC_H_ */

Expand Down
12 changes: 6 additions & 6 deletions sys/arm64/include/cpufunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
#ifndef _MACHINE_CPUFUNC_H_
#define _MACHINE_CPUFUNC_H_

#ifdef _KERNEL

#include <machine/armreg.h>

void pan_enable(void);

static __inline void
breakpoint(void)
{

__asm("brk #0");
}

#ifdef _KERNEL

#include <machine/armreg.h>

void pan_enable(void);

static __inline register_t
dbg_disable(void)
{
Expand Down
11 changes: 8 additions & 3 deletions tests/sys/kern/ptrace_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,22 @@ __FBSDID("$FreeBSD$");
/*
* Architectures with a user-visible breakpoint().
*/
#if defined(__amd64__) || defined(__i386__) || defined(__mips__) || \
defined(__riscv) || defined(__sparc64__)
#if defined(__aarch64__) || defined(__amd64__) || defined(__arm__) || \
defined(__i386__) || defined(__mips__) || defined(__riscv) || \
defined(__sparc64__)
#define HAVE_BREAKPOINT
#endif

/*
* Adjust PC to skip over a breakpoint when stopped for a breakpoint trap.
*/
#ifdef HAVE_BREAKPOINT
#if defined(__amd64__) || defined(__i386__)
#if defined(__aarch64__)
#define SKIP_BREAK(reg) ((reg)->elr += 4)
#elif defined(__amd64__) || defined(__i386__)
#define SKIP_BREAK(reg)
#elif defined(__arm__)
#define SKIP_BREAK(reg) ((reg)->r_pc += 4)
#elif defined(__mips__)
#define SKIP_BREAK(reg) ((reg)->r_regs[PC] += 4)
#elif defined(__riscv)
Expand Down

0 comments on commit 465d5a9

Please sign in to comment.