aboutsummaryrefslogtreecommitdiff
path: root/gdb/linux-nat.h
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2015-06-23 14:03:11 +0100
committerYao Qi <yao.qi@linaro.org>2015-06-23 14:03:11 +0100
commit0bdb2f78497a1b3be65d1428cc02f7d4e1d3a888 (patch)
tree59ef29eda0d1965b4313c735b9e75bd81919f70b /gdb/linux-nat.h
parentc217058957a45a93481da35e1531ed120750d739 (diff)
downloadgdb-0bdb2f78497a1b3be65d1428cc02f7d4e1d3a888.zip
gdb-0bdb2f78497a1b3be65d1428cc02f7d4e1d3a888.tar.gz
gdb-0bdb2f78497a1b3be65d1428cc02f7d4e1d3a888.tar.bz2
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 <yao.qi@linaro.org> * 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.
Diffstat (limited to 'gdb/linux-nat.h')
-rw-r--r--gdb/linux-nat.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
index 3d766b5..cae263a 100644
--- a/gdb/linux-nat.h
+++ b/gdb/linux-nat.h
@@ -116,7 +116,8 @@ struct lwp_info
extern struct lwp_info *lwp_list;
/* Does the current host support PTRACE_GETREGSET? */
-extern int have_ptrace_getregset;
+enum tribool { TRIBOOL_UNKNOWN = -1, TRIBOOL_FALSE = 0, TRIBOOL_TRUE = 1 };
+extern enum tribool have_ptrace_getregset;
/* Iterate over each active thread (light-weight process). */
#define ALL_LWPS(LP) \