diff options
author | Yao Qi <yao.qi@linaro.org> | 2015-06-23 14:03:11 +0100 |
---|---|---|
committer | Yao Qi <yao.qi@linaro.org> | 2015-06-23 14:03:11 +0100 |
commit | 0bdb2f78497a1b3be65d1428cc02f7d4e1d3a888 (patch) | |
tree | 59ef29eda0d1965b4313c735b9e75bd81919f70b /gdb/arm-linux-nat.c | |
parent | c217058957a45a93481da35e1531ed120750d739 (diff) | |
download | gdb-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/arm-linux-nat.c')
-rw-r--r-- | gdb/arm-linux-nat.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c index 10aea07..c167bce 100644 --- a/gdb/arm-linux-nat.c +++ b/gdb/arm-linux-nat.c @@ -95,7 +95,7 @@ fetch_fpregister (struct regcache *regcache, int regno) tid = GET_THREAD_ID (inferior_ptid); /* Read the floating point state. */ - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -136,7 +136,7 @@ fetch_fpregs (struct regcache *regcache) tid = GET_THREAD_ID (inferior_ptid); /* Read the floating point state. */ - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -176,7 +176,7 @@ store_fpregister (const struct regcache *regcache, int regno) tid = GET_THREAD_ID (inferior_ptid); /* Read the floating point state. */ - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -203,7 +203,7 @@ store_fpregister (const struct regcache *regcache, int regno) if (regno >= ARM_F0_REGNUM && regno <= ARM_F7_REGNUM) collect_nwfpe_register (regcache, regno, fp); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -235,7 +235,7 @@ store_fpregs (const struct regcache *regcache) tid = GET_THREAD_ID (inferior_ptid); /* Read the floating point state. */ - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { elf_fpregset_t fpregs; struct iovec iov; @@ -263,7 +263,7 @@ store_fpregs (const struct regcache *regcache) if (REG_VALID == regcache_register_status (regcache, regno)) collect_nwfpe_register (regcache, regno, fp); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -294,7 +294,7 @@ fetch_register (struct regcache *regcache, int regno) /* Get the thread id for the ptrace call. */ tid = GET_THREAD_ID (inferior_ptid); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -347,7 +347,7 @@ fetch_regs (struct regcache *regcache) /* Get the thread id for the ptrace call. */ tid = GET_THREAD_ID (inferior_ptid); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -397,7 +397,7 @@ store_register (const struct regcache *regcache, int regno) tid = GET_THREAD_ID (inferior_ptid); /* Get the general registers from the process. */ - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -424,7 +424,7 @@ store_register (const struct regcache *regcache, int regno) regcache_raw_collect (regcache, ARM_PC_REGNUM, (char *) ®s[ARM_PC_REGNUM]); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -453,7 +453,7 @@ store_regs (const struct regcache *regcache) tid = GET_THREAD_ID (inferior_ptid); /* Fetch the general registers. */ - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -481,7 +481,7 @@ store_regs (const struct regcache *regcache) regcache_raw_collect (regcache, ARM_PS_REGNUM, (char *) ®s[ARM_CPSR_GREGNUM]); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -593,7 +593,7 @@ fetch_vfp_regs (struct regcache *regcache) /* Get the thread id for the ptrace call. */ tid = GET_THREAD_ID (inferior_ptid); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -629,7 +629,7 @@ store_vfp_regs (const struct regcache *regcache) /* Get the thread id for the ptrace call. */ tid = GET_THREAD_ID (inferior_ptid); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -653,7 +653,7 @@ store_vfp_regs (const struct regcache *regcache) regcache_raw_collect (regcache, ARM_FPSCR_REGNUM, (char *) regbuf + 32 * 8); - if (have_ptrace_getregset) + if (have_ptrace_getregset == TRIBOOL_TRUE) { struct iovec iov; @@ -797,7 +797,7 @@ arm_linux_read_description (struct target_ops *ops) { CORE_ADDR arm_hwcap = 0; - if (have_ptrace_getregset == -1) + if (have_ptrace_getregset == TRIBOOL_UNKNOWN) { elf_gregset_t gpregs; struct iovec iov; @@ -808,9 +808,9 @@ arm_linux_read_description (struct target_ops *ops) /* Check if PTRACE_GETREGSET works. */ if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iov) < 0) - have_ptrace_getregset = 0; + have_ptrace_getregset = TRIBOOL_FALSE; else - have_ptrace_getregset = 1; + have_ptrace_getregset = TRIBOOL_TRUE; } if (target_auxv_search (ops, AT_HWCAP, &arm_hwcap) != 1) |