Cleanup print_pc

Apparently, there are only two types of instruction pointer printers
depending on the architecture: those that print a register that was
fetched earlier, and those that fetch a register themselves using upeek.
With this change, architectures of the first type have ARCH_PC_REG
defined in their arch_regs.c file, architectures of the first type
have ARCH_PC_PEEK_ADDR defined there, and the common code in syscall.c
uses these macros to print the instruction pointer.

* Makefile.am (EXTRA_DIST): Remove linux/*/print_pc.c.
* linux/*/print_pc.c: Remove.
* linux/aarch64/arch_regs.c(ARCH_PC_REG): Define macro.
* linux/arc/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/arm/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/avr32/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/i386/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/ia64/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/metag/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/mips/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/nios2/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/or1k/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/powerpc64/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/powerpc/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/s390/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/s390x/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/sparc64/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/sparc/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/tile/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/x32/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/x86_64/arch_regs.c(ARCH_PC_REG): Likewise.
* linux/alpha/arch_regs.c(ARCH_PC_PEEK_ADDR): Define macro.
* linux/bfin/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* linux/crisv10/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* linux/crisv32/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* linux/hppa/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* linux/m68k/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* linux/microblaze/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* linux/sh64/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* linux/sh/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* linux/xtensa/arch_regs.c(ARCH_PC_PEEK_ADDR): Likewise.
* syscall.c (print_pc): Stop including "print_pc.c".
Use ARCH_PC_REG or ARCH_PC_PEEK_ADDR.
This commit is contained in:
Дмитрий Левин 2015-11-30 03:30:51 +00:00
parent 16510517f1
commit 5105d4ac96
60 changed files with 42 additions and 138 deletions

View File

@ -227,7 +227,6 @@ EXTRA_DIST = \
linux/aarch64/ioctls_arch1.h \
linux/aarch64/ioctls_inc0.h \
linux/aarch64/ioctls_inc1.h \
linux/aarch64/print_pc.c \
linux/aarch64/signalent1.h \
linux/aarch64/syscallent.h \
linux/aarch64/syscallent1.h \
@ -242,7 +241,6 @@ EXTRA_DIST = \
linux/alpha/get_syscall_result.c\
linux/alpha/ioctls_arch0.h \
linux/alpha/ioctls_inc0.h \
linux/alpha/print_pc.c \
linux/alpha/signalent.h \
linux/alpha/syscallent.h \
linux/alpha/userent.h \
@ -252,7 +250,6 @@ EXTRA_DIST = \
linux/arc/get_syscall_args.c \
linux/arc/ioctls_arch0.h \
linux/arc/ioctls_inc0.h \
linux/arc/print_pc.c \
linux/arc/syscallent.h \
linux/arch_regs.h \
linux/arch_sigreturn.c \
@ -264,7 +261,6 @@ EXTRA_DIST = \
linux/arm/get_syscall_args.c \
linux/arm/ioctls_arch0.h \
linux/arm/ioctls_inc0.h \
linux/arm/print_pc.c \
linux/arm/syscallent.h \
linux/arm/userent.h \
linux/avr32/arch_regs.c \
@ -273,7 +269,6 @@ EXTRA_DIST = \
linux/avr32/get_syscall_args.c \
linux/avr32/ioctls_arch0.h \
linux/avr32/ioctls_inc0.h \
linux/avr32/print_pc.c \
linux/avr32/syscallent.h \
linux/avr32/userent.h \
linux/bfin/arch_regs.c \
@ -283,7 +278,6 @@ EXTRA_DIST = \
linux/bfin/get_syscall_result.c \
linux/bfin/ioctls_arch0.h \
linux/bfin/ioctls_inc0.h \
linux/bfin/print_pc.c \
linux/bfin/syscallent.h \
linux/bfin/userent.h \
linux/crisv10/arch_regs.c \
@ -292,7 +286,6 @@ EXTRA_DIST = \
linux/crisv10/get_scno.c \
linux/crisv10/get_syscall_args.c \
linux/crisv10/get_syscall_result.c \
linux/crisv10/print_pc.c \
linux/crisv10/userent.h \
linux/crisv32/arch_regs.c \
linux/crisv32/arch_sigreturn.c \
@ -300,7 +293,6 @@ EXTRA_DIST = \
linux/crisv32/get_scno.c \
linux/crisv32/get_syscall_args.c \
linux/crisv32/get_syscall_result.c \
linux/crisv32/print_pc.c \
linux/crisv32/userent.h \
linux/dummy.h \
linux/errnoent.h \
@ -313,7 +305,6 @@ EXTRA_DIST = \
linux/hppa/get_syscall_result.c \
linux/hppa/ioctls_arch0.h \
linux/hppa/ioctls_inc0.h \
linux/hppa/print_pc.c \
linux/hppa/signalent.h \
linux/hppa/syscallent.h \
linux/i386/arch_regs.c \
@ -324,7 +315,6 @@ EXTRA_DIST = \
linux/i386/get_syscall_args.c \
linux/i386/ioctls_arch0.h \
linux/i386/ioctls_inc0.h \
linux/i386/print_pc.c \
linux/i386/syscallent.h \
linux/i386/userent.h \
linux/i386/userent0.h \
@ -337,7 +327,6 @@ EXTRA_DIST = \
linux/ia64/get_syscall_args.c \
linux/ia64/ioctls_arch0.h \
linux/ia64/ioctls_inc0.h \
linux/ia64/print_pc.c \
linux/ia64/syscallent.h \
linux/ia64/userent.h \
linux/inet_diag.h \
@ -349,7 +338,6 @@ EXTRA_DIST = \
linux/m68k/get_syscall_result.c \
linux/m68k/ioctls_arch0.h \
linux/m68k/ioctls_inc0.h \
linux/m68k/print_pc.c \
linux/m68k/syscallent.h \
linux/m68k/userent.h \
linux/metag/arch_regs.c \
@ -358,7 +346,6 @@ EXTRA_DIST = \
linux/metag/get_syscall_args.c \
linux/metag/ioctls_arch0.h \
linux/metag/ioctls_inc0.h \
linux/metag/print_pc.c \
linux/metag/syscallent.h \
linux/microblaze/arch_regs.c \
linux/microblaze/arch_sigreturn.c \
@ -368,7 +355,6 @@ EXTRA_DIST = \
linux/microblaze/get_syscall_result.c \
linux/microblaze/ioctls_arch0.h \
linux/microblaze/ioctls_inc0.h \
linux/microblaze/print_pc.c \
linux/microblaze/syscallent.h \
linux/microblaze/userent.h \
linux/mips/arch_getrval2.c \
@ -382,7 +368,6 @@ EXTRA_DIST = \
linux/mips/get_syscall_args.c \
linux/mips/ioctls_arch0.h \
linux/mips/ioctls_inc0.h \
linux/mips/print_pc.c \
linux/mips/signalent.h \
linux/mips/syscallent-compat.h \
linux/mips/syscallent-n32.h \
@ -397,7 +382,6 @@ EXTRA_DIST = \
linux/nios2/get_syscall_args.c \
linux/nios2/ioctls_arch0.h \
linux/nios2/ioctls_inc0.h \
linux/nios2/print_pc.c \
linux/nios2/syscallent.h \
linux/or1k/arch_regs.c \
linux/or1k/get_error.c \
@ -405,7 +389,6 @@ EXTRA_DIST = \
linux/or1k/get_syscall_args.c \
linux/or1k/ioctls_arch0.h \
linux/or1k/ioctls_inc0.h \
linux/or1k/print_pc.c \
linux/or1k/syscallent.h \
linux/or1k/userent.h \
linux/personality.h \
@ -419,7 +402,6 @@ EXTRA_DIST = \
linux/powerpc/getregs_old.c \
linux/powerpc/ioctls_arch0.h \
linux/powerpc/ioctls_inc0.h \
linux/powerpc/print_pc.c \
linux/powerpc/syscallent.h \
linux/powerpc/userent.h \
linux/powerpc64/arch_regs.c \
@ -435,7 +417,6 @@ EXTRA_DIST = \
linux/powerpc64/ioctls_arch1.h \
linux/powerpc64/ioctls_inc0.h \
linux/powerpc64/ioctls_inc1.h \
linux/powerpc64/print_pc.c \
linux/powerpc64/signalent1.h \
linux/powerpc64/syscallent.h \
linux/powerpc64/syscallent1.h \
@ -449,7 +430,6 @@ EXTRA_DIST = \
linux/s390/get_syscall_args.c \
linux/s390/ioctls_arch0.h \
linux/s390/ioctls_inc0.h \
linux/s390/print_pc.c \
linux/s390/syscallent.h \
linux/s390/userent.h \
linux/s390/userent0.h \
@ -462,7 +442,6 @@ EXTRA_DIST = \
linux/s390x/get_syscall_args.c \
linux/s390x/ioctls_arch0.h \
linux/s390x/ioctls_inc0.h \
linux/s390x/print_pc.c \
linux/s390x/syscallent.h \
linux/s390x/userent.h \
linux/sh/arch_getrval2.c \
@ -473,7 +452,6 @@ EXTRA_DIST = \
linux/sh/get_syscall_result.c \
linux/sh/ioctls_arch0.h \
linux/sh/ioctls_inc0.h \
linux/sh/print_pc.c \
linux/sh/syscallent.h \
linux/sh/userent.h \
linux/sh/userent0.h \
@ -485,7 +463,6 @@ EXTRA_DIST = \
linux/sh64/get_syscall_result.c \
linux/sh64/ioctls_arch0.h \
linux/sh64/ioctls_inc0.h \
linux/sh64/print_pc.c \
linux/sh64/syscallent.h \
linux/sh64/userent.h \
linux/signalent.h \
@ -501,7 +478,6 @@ EXTRA_DIST = \
linux/sparc/get_syscall_args.c \
linux/sparc/ioctls_arch0.h \
linux/sparc/ioctls_inc0.h \
linux/sparc/print_pc.c \
linux/sparc/signalent.h \
linux/sparc/syscallent.h \
linux/sparc/userent.h \
@ -518,7 +494,6 @@ EXTRA_DIST = \
linux/sparc64/ioctls_arch1.h \
linux/sparc64/ioctls_inc0.h \
linux/sparc64/ioctls_inc1.h \
linux/sparc64/print_pc.c \
linux/sparc64/signalent.h \
linux/sparc64/signalent1.h \
linux/sparc64/syscallent.h \
@ -537,7 +512,6 @@ EXTRA_DIST = \
linux/tile/ioctls_arch1.h \
linux/tile/ioctls_inc0.h \
linux/tile/ioctls_inc1.h \
linux/tile/print_pc.c \
linux/tile/signalent1.h \
linux/tile/syscallent.h \
linux/tile/syscallent1.h \
@ -557,7 +531,6 @@ EXTRA_DIST = \
linux/x32/ioctls_arch1.h \
linux/x32/ioctls_inc0.h \
linux/x32/ioctls_inc1.h \
linux/x32/print_pc.c \
linux/x32/signalent1.h \
linux/x32/syscallent.h \
linux/x32/syscallent1.h \
@ -578,7 +551,6 @@ EXTRA_DIST = \
linux/x86_64/ioctls_inc0.h \
linux/x86_64/ioctls_inc1.h \
linux/x86_64/ioctls_inc2.h \
linux/x86_64/print_pc.c \
linux/x86_64/signalent1.h \
linux/x86_64/signalent2.h \
linux/x86_64/syscallent.h \
@ -592,7 +564,6 @@ EXTRA_DIST = \
linux/xtensa/get_syscall_result.c \
linux/xtensa/ioctls_arch0.h \
linux/xtensa/ioctls_inc0.h \
linux/xtensa/print_pc.c \
linux/xtensa/syscallent.h \
linux/xtensa/userent.h \
maint/ioctls_gen.sh \

View File

@ -35,3 +35,4 @@ static struct iovec aarch64_io = {
#define ARCH_REGS_FOR_GETREGSET arm_regs_union
#define ARCH_IOVEC_FOR_GETREGSET aarch64_io
#define ARCH_PC_REG ((aarch64_io.iov_len == sizeof(arm_regs)) ? arm_regs.ARM_pc : aarch64_regs.pc)

View File

@ -1,4 +0,0 @@
if (aarch64_io.iov_len == sizeof(arm_regs))
tprintf(fmt, (unsigned long) arm_regs.ARM_pc);
else
tprintf(fmt, (unsigned long) aarch64_regs.pc);

View File

@ -1,2 +1,3 @@
static long alpha_r0;
static long alpha_a3;
#define ARCH_PC_PEEK_ADDR REG_PC

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, REG_PC, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1,2 +1,3 @@
static struct user_regs_struct arc_regs;
#define ARCH_REGS_FOR_GETREGSET arc_regs
#define ARCH_PC_REG arc_regs.efa

View File

@ -1 +0,0 @@
tprintf(fmt, arc_regs.efa);

View File

@ -2,3 +2,4 @@ static struct pt_regs arm_regs;
long *const arm_sp_ptr = &arm_regs.ARM_sp;
#define ARCH_REGS_FOR_GETREGS arm_regs
#define ARCH_PC_REG arm_regs.ARM_pc

View File

@ -1 +0,0 @@
tprintf(fmt, arm_regs.ARM_pc);

View File

@ -1,2 +1,3 @@
static struct pt_regs avr32_regs;
#define ARCH_REGS_FOR_GETREGS avr32_regs
#define ARCH_PC_REG avr32_regs.pc

View File

@ -1 +0,0 @@
tprintf(fmt, avr32_regs.pc);

View File

@ -1 +1,2 @@
static long bfin_r0;
#define ARCH_PC_PEEK_ADDR PT_PC

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, PT_PC, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1 +1,2 @@
static long cris_r10;
#define ARCH_PC_PEEK_ADDR (4 * PT_IRP)

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, 4*PT_IRP, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1 +1,2 @@
#include "crisv10/arch_regs.c"
#define ARCH_PC_PEEK_ADDR (4 * PT_ERP)

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, 4*PT_ERP, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1 +1,2 @@
static long hppa_r28;
#define ARCH_PC_PEEK_ADDR PT_IAOQ0

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, PT_IAOQ0, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -2,3 +2,4 @@ static struct user_regs_struct i386_regs;
long *const i386_esp_ptr = &i386_regs.esp;
#define ARCH_REGS_FOR_GETREGS i386_regs
#define ARCH_PC_REG i386_regs.eip

View File

@ -1 +0,0 @@
tprintf(fmt, i386_regs.eip);

View File

@ -5,3 +5,4 @@ unsigned long *const ia64_frame_ptr = &ia64_regs.gr[12];
#define ia64_ia32mode (ia64_regs.cr_ipsr & IA64_PSR_IS)
#define ARCH_REGS_FOR_GETREGS ia64_regs
#define ARCH_PC_REG ia64_regs.br[0]

View File

@ -1 +0,0 @@
tprintf(fmt, ia64_regs.br[0]);

View File

@ -1 +1,2 @@
static long m68k_d0;
#define ARCH_PC_PEEK_ADDR (4 * PT_PC)

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1,2 +1,3 @@
static struct user_gp_regs metag_regs;
#define ARCH_REGS_FOR_GETREGSET metag_regs
#define ARCH_PC_REG metag_regs.pc

View File

@ -1 +0,0 @@
tprintf(fmt, metag_regs.pc);

View File

@ -1 +1,2 @@
static long microblaze_r3;
#define ARCH_PC_PEEK_ADDR PT_PC

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, PT_PC, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1,3 +1,4 @@
struct mips_regs mips_regs; /* not static */
/* PTRACE_GETREGS on MIPS is available since linux v2.6.15. */
#define ARCH_REGS_FOR_GETREGS mips_regs
#define ARCH_PC_REG mips_REG_EPC

View File

@ -1 +0,0 @@
tprintf(fmt, (unsigned long) mips_REG_EPC);

View File

@ -1,2 +1,3 @@
static struct user_pt_regs nios2_regs;
# define ARCH_REGS_FOR_GETREGSET nios2_regs
#define ARCH_PC_REG nios2_regs.regs[PTR_EA]

View File

@ -1 +0,0 @@
tprintf(fmt, nios2_regs.regs[PTR_EA]);

View File

@ -1,2 +1,3 @@
static struct user_regs_struct or1k_regs;
#define ARCH_REGS_FOR_GETREGSET or1k_regs
#define ARCH_PC_REG or1k_regs.pc

View File

@ -1 +0,0 @@
tprintf(fmt, or1k_regs.pc);

View File

@ -1,3 +1,4 @@
struct pt_regs ppc_regs; /* not static */
#define ARCH_REGS_FOR_GETREGS ppc_regs
#define ARCH_PC_REG ppc_regs.nip

View File

@ -1 +0,0 @@
tprintf(fmt, ppc_regs.nip);

View File

@ -1 +1,2 @@
#include "powerpc/arch_regs.c"
#define ARCH_PC_REG ppc_regs.nip

View File

@ -1 +0,0 @@
#include "powerpc/print_pc.c"

View File

@ -2,3 +2,4 @@
static struct user_regs_struct s390_regset;
unsigned long *const s390_frame_ptr = &s390_regset.gprs[15];
#define ARCH_REGS_FOR_GETREGSET s390_regset
#define ARCH_PC_REG s390_regset.psw.addr

View File

@ -1 +0,0 @@
tprintf(fmt, s390_regset.psw.addr);

View File

@ -1 +1,2 @@
#include "s390/arch_regs.c"
#define ARCH_PC_REG s390_regset.psw.addr

View File

@ -1 +0,0 @@
#include "s390/print_pc.c"

View File

@ -1 +1,2 @@
static long sh_r0;
#define ARCH_PC_PEEK_ADDR (4 * REG_PC)

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, 4*REG_PC, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1 +1,2 @@
static long sh64_r9;
#define ARCH_PC_PEEK_ADDR REG_PC

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, REG_PC, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1,2 +1,3 @@
struct pt_regs sparc_regs; /* not static */
#define ARCH_REGS_FOR_GETREGS sparc_regs
#define ARCH_PC_REG sparc_regs.pc

View File

@ -1 +0,0 @@
tprintf(fmt, sparc_regs.pc);

View File

@ -1 +1,2 @@
#include "sparc/arch_regs.c"
#define ARCH_PC_REG sparc_regs.tpc

View File

@ -1 +0,0 @@
tprintf(fmt, sparc_regs.tpc);

View File

@ -1,2 +1,3 @@
struct pt_regs tile_regs; /* not static */
#define ARCH_REGS_FOR_GETREGS tile_regs
#define ARCH_PC_REG tile_regs.pc

View File

@ -1 +0,0 @@
tprintf(fmt, (unsigned long) tile_regs.pc);

View File

@ -1 +1,2 @@
#include "x86_64/arch_regs.c"
#define ARCH_PC_REG (x86_io.iov_len == sizeof(i386_regs) ? i386_regs.eip : x86_64_regs.rip)

View File

@ -1 +0,0 @@
#include "x86_64/print_pc.c"

View File

@ -38,3 +38,4 @@ static struct iovec x86_io = {
#define ARCH_REGS_FOR_GETREGSET x86_regs_union
#define ARCH_IOVEC_FOR_GETREGSET x86_io
#define ARCH_PC_REG (x86_io.iov_len == sizeof(i386_regs) ? i386_regs.eip : x86_64_regs.rip)

View File

@ -1,4 +0,0 @@
if (x86_io.iov_len == sizeof(i386_regs))
tprintf(fmt, (unsigned long) i386_regs.eip);
else
tprintf(fmt, (unsigned long) x86_64_regs.rip);

View File

@ -1 +1,2 @@
static long xtensa_a2;
#define ARCH_PC_PEEK_ADDR REG_PC

View File

@ -1,6 +0,0 @@
long pc;
if (upeek(tcp->pid, REG_PC, &pc) < 0) {
PRINTBADPC;
return;
}
tprintf(fmt, pc);

View File

@ -1197,32 +1197,21 @@ is_negated_errno(kernel_ulong_t val)
void
print_pc(struct tcb *tcp)
{
const char *fmt;
const char *bad;
#ifdef current_wordsize
# define pc_wordsize current_wordsize
#if defined ARCH_PC_REG
# define ARCH_GET_PC 0
#elif defined ARCH_PC_PEEK_ADDR
long pc;
# define ARCH_PC_REG pc
# define ARCH_GET_PC upeek(tcp->pid, ARCH_PC_PEEK_ADDR, &pc)
#else
# define pc_wordsize personality_wordsize[tcp->currpers]
# error Neither ARCH_PC_REG nor ARCH_PC_PEEK_ADDR is defined
#endif
if (pc_wordsize == 4) {
fmt = "[%08lx] ";
bad = "[????????] ";
} else {
fmt = "[%016lx] ";
bad = "[????????????????] ";
}
#undef pc_wordsize
#define PRINTBADPC tprints(bad)
if (get_regs_error) {
PRINTBADPC;
return;
}
#include "print_pc.c"
if (get_regs_error || ARCH_GET_PC)
tprints(current_wordsize == 4 ? "[????????] "
: "[????????????????] ");
else
tprintf(current_wordsize == 4 ? "[%08lx] " : "[%016lx] ",
(unsigned long) ARCH_PC_REG);
}
#if defined X86_64 || defined POWERPC