From 0bdb2f78497a1b3be65d1428cc02f7d4e1d3a888 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Tue, 23 Jun 2015 14:03:11 +0100 Subject: Convert have_ptrace_getregset to a tri-state boolean have_ptrace_getregset is a tri-state variable (-1, 0, 1), and we have some conditions like "if (have_ptrace_getregset)", which is not correct. I'll explain why it is not correct in the following example. This fix to this problem to replace the test (have_ptrace_getregset) to test (have_ptrace_getregset == 1) or (have_ptrace_getregset == -1) etc. However Doug thinks it hinders readability https://sourceware.org/ml/gdb-patches/2015-05/msg00692.html so I decide to add a new enum tribool and change have_ptrace_getregset to it, in order to make these tests more readable. have_ptrace_getregset is initialised to -1, and is adjusted to 0 or 1 in $ARCH_linux_read_description according to the capability of the kernel. However, it is possible that have_ptrace_getregset is used before it is set to 0 or 1, which means it is still -1. This is shown below. (gdb) run Starting program: gdb/testsuite/gdb.base/break Breakpoint 2, amd64_linux_fetch_inferior_registers (ops=0xceaa80, regcache=0xe72000, regnum=16) at git/gdb/amd64-linux-nat.c:128 128 { top?p have_ptrace_getregset $1 = TRIBOOL_UNKNOWN top?c Continuing. Breakpoint 2, amd64_linux_fetch_inferior_registers (ops=0xceaa80, regcache=0xe72000, regnum=16) at git/gdb/amd64-linux-nat.c:128 128 { top?c Continuing. Breakpoint 1, x86_linux_read_description (ops=0xceaa80) at git/gdb/x86-linux-nat.c:117 117 { PTRACE_GETREGSET command is used even GDB doesn't know whether PTRACE_GETREGSET is supported or not. It is wrong, but works on x86. However it doesn't work on arm-linux if the kernel doesn't support PTRACE_GETREGSET at all. We'll get: (gdb) run Starting program: gdb/testsuite/gdb.base/break warning: Unable to fetch general register. PC register is not available gdb: 2015-06-23 Yao Qi * amd64-linux-nat.c (amd64_linux_fetch_inferior_registers): Check whether have_ptrace_getregset is TRIBOOL_TRUE explicitly. (amd64_linux_store_inferior_registers): Likewise. * arm-linux-nat.c (fetch_fpregister): Likewise. (fetch_fpregs, store_fpregister): Likewise. (store_fpregister, store_fpregs): Likewise. (fetch_register, fetch_regs): Likewise. (store_register, store_regs): Likewise. (fetch_vfp_regs, store_vfp_regs): Likewise. (arm_linux_read_description): Check have_ptrace_getregset is TRIBOOL_UNKNOWN. Set have_ptrace_getregset to TRIBOOL_TRUE or TRIBOOL_FALSE. * i386-linux-nat.c (fetch_xstateregs): Check have_ptrace_getregset is not TRIBOOL_TRUE. (store_xstateregs): Likewise. * linux-nat.c (have_ptrace_getregset): Change its type to enum tribool. * linux-nat.h (tribool): New enum. * x86-linux-nat.c (x86_linux_read_description): Use enum tribool. Check whether have_ptrace_getregset is TRIBOOL_TRUE. --- gdb/x86-linux-nat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gdb/x86-linux-nat.c') diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index 5d8f7c7..04917d0 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -162,13 +162,13 @@ x86_linux_read_description (struct target_ops *ops) if (ptrace (PTRACE_GETFPXREGS, tid, 0, (int) &fpxregs) < 0) { have_ptrace_getfpxregs = 0; - have_ptrace_getregset = 0; + have_ptrace_getregset = TRIBOOL_FALSE; return tdesc_i386_mmx_linux; } } #endif - if (have_ptrace_getregset == -1) + if (have_ptrace_getregset == TRIBOOL_UNKNOWN) { uint64_t xstateregs[(X86_XSTATE_SSE_SIZE / sizeof (uint64_t))]; struct iovec iov; @@ -179,10 +179,10 @@ x86_linux_read_description (struct target_ops *ops) /* Check if PTRACE_GETREGSET works. */ if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE, &iov) < 0) - have_ptrace_getregset = 0; + have_ptrace_getregset = TRIBOOL_FALSE; else { - have_ptrace_getregset = 1; + have_ptrace_getregset = TRIBOOL_TRUE; /* Get XCR0 from XSAVE extended state. */ xcr0 = xstateregs[(I386_LINUX_XSAVE_XCR0_OFFSET @@ -194,7 +194,7 @@ x86_linux_read_description (struct target_ops *ops) PTRACE_GETREGSET is not available then set xcr0_features_bits to zero so that the "no-features" descriptions are returned by the switches below. */ - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) xcr0_features_bits = xcr0 & X86_XSTATE_ALL_MASK; else xcr0_features_bits = 0; -- cgit v1.1