diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 15d81577cfb..1f297ff9f73 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2016-02-12 Yao Qi + + * arch/arm-linux.c (arm_linux_get_next_pcs_fixup): Calculate + nextpc according to instruction. + 2016-02-12 Yao Qi * arch/arm-get-next-pcs.c (arm_get_next_pcs): Call diff --git a/gdb/arch/arm-linux.c b/gdb/arch/arm-linux.c index 457080c27ff..7e240fe7a6a 100644 --- a/gdb/arch/arm-linux.c +++ b/gdb/arch/arm-linux.c @@ -68,10 +68,72 @@ arm_linux_get_next_pcs_fixup (struct arm_get_next_pcs *self, /* The Linux kernel offers some user-mode helpers in a high page. We can not read this page (as of 2.6.23), and even if we could then we couldn't set breakpoints in it, and even if we could then the atomic - operations would fail when interrupted. They are all called as - functions and return to the address in LR, so step to there - instead. */ + operations would fail when interrupted. They are all (tail) called + as functions and return to the address in LR. However, when GDB single + step this instruction, this instruction isn't executed yet, and LR + may not be updated yet. In other words, GDB can get the target + address from LR if this instruction isn't BL or BLX. */ if (nextpc > 0xffff0000) - nextpc = regcache_raw_get_unsigned (self->regcache, ARM_LR_REGNUM); + { + int bl_blx_p = 0; + CORE_ADDR pc = regcache_read_pc (self->regcache); + int pc_incr = 0; + + if (self->ops->is_thumb (self)) + { + unsigned short inst1 + = self->ops->read_mem_uint (pc, 2, self->byte_order_for_code); + + if (bits (inst1, 8, 15) == 0x47 && bit (inst1, 7)) + { + /* BLX Rm */ + bl_blx_p = 1; + pc_incr = 2; + } + else if (thumb_insn_size (inst1) == 4) + { + unsigned short inst2; + + inst2 = self->ops->read_mem_uint (pc + 2, 2, + self->byte_order_for_code); + + if ((inst1 & 0xf800) == 0xf000 && bits (inst2, 14, 15) == 0x3) + { + /* BL