* [patch, arm] Use cached dsc->is_thumb instead of re-computing @ 2011-03-04 13:30 Yao Qi 2011-03-04 14:08 ` Ulrich Weigand 0 siblings, 1 reply; 7+ messages in thread From: Yao Qi @ 2011-03-04 13:30 UTC (permalink / raw) To: gdb-patches; +Cc: Ulrich Weigand [-- Attachment #1: Type: text/plain, Size: 720 bytes --] On 03/01/2011 05:01 PM, Yao Qi wrote: >>>> >> > + if (displaced_in_arm_mode (regs)) >> > It would be somewhat nicer here to use dsc->is_thumb instead of re-computing >> > its value. However, the displaced_read_reg function doesn't have the dsc >> > argument, which is annoying (and asymmetrical to displaced_write_reg ...). >> > >> > So if you want to make the effort to change all call sites to pass in dsc, >> > this would be nice, but I guess I'm also OK with doing it as above. >> > > Let us move this change to another patch. > During writing thumb displaced stepping, we find that displaced_read_reg can be refactored to avoid calling displaced_in_arm_mode every time. OK to apply? -- Yao (é½å°§) [-- Attachment #2: arm-displaced-read-refactor-0303.patch --] [-- Type: text/x-patch, Size: 18242 bytes --] 2011-03-03 Yao Qi <yao@codesourcery.com> * arm-tdep.c (displaced_read_reg): Add `dsc' parameter. Use cached result instead of calling displaced_in_arm_mode again. (branch_write_pc, alu_write_pc, load_write_pc): Add `dsc' parameter. (displaced_write_reg, copy_preload, copy_preload_reg): Callers update. (cleanup_copro_load_store, copy_copro_load_store): Likewise. (cleanup_branch, copy_bx_blx_reg, copy_alu_imm): Likewise. (cleanup_alu_reg, copy_alu_reg, cleanup_alu_shifted_reg): Likewise. (copy_alu_shifted_reg, cleanup_load, cleanup_store): Likewise. (copy_extra_ld_st, copy_ldr_str_ldrb_strb): Likewise. (cleanup_block_load_all, cleanup_block_store_pc): Likewise. (cleanup_block_load_pc, copy_block_xfer): Likewise. * arm-linux-tdep.c (arm_linux_copy_svc): Callers update. (arm_catch_kernel_helper_return): Likewise. * gdb/arm-tdep.h : Update function declarations. diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c index f60ecc3..6e49cb1 100644 --- a/gdb/arm-linux-tdep.c +++ b/gdb/arm-linux-tdep.c @@ -805,7 +805,7 @@ arm_linux_copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to, CORE_ADDR return_to = 0; struct frame_info *frame; - unsigned int svc_number = displaced_read_reg (regs, from, 7); + unsigned int svc_number = displaced_read_reg (regs, dsc, from, 7); int is_sigreturn = 0; if (debug_displaced) @@ -918,7 +918,7 @@ arm_catch_kernel_helper_return (struct gdbarch *gdbarch, CORE_ADDR from, Insn: ldr pc, [r14, #4] Cleanup: r14 <- tmp[0], pc <- tmp[0]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, ARM_LR_REGNUM); + dsc->tmp[0] = displaced_read_reg (regs, dsc, from, ARM_LR_REGNUM); displaced_write_reg (regs, dsc, ARM_LR_REGNUM, (ULONGEST) to + 4, CANNOT_WRITE_PC); write_memory_unsigned_integer (to + 8, 4, byte_order, from); diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 2cf2eec..b277faf 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -5118,7 +5118,8 @@ static int displaced_in_arm_mode (struct regcache *regs); location. */ ULONGEST -displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno) +displaced_read_reg (struct regcache *regs, struct displaced_step_closure *dsc, + CORE_ADDR from, int regno) { ULONGEST ret; @@ -5130,7 +5131,7 @@ displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno) - When executing a Thumb instruction, PC reads as the address of the current instruction plus 4. */ - if (displaced_in_arm_mode (regs)) + if (!dsc->is_thumb) from += 8; else from += 4; @@ -5164,9 +5165,10 @@ displaced_in_arm_mode (struct regcache *regs) /* Write to the PC as from a branch instruction. */ static void -branch_write_pc (struct regcache *regs, ULONGEST val) +branch_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { - if (displaced_in_arm_mode (regs)) + if (!dsc->is_thumb) /* Note: If bits 0/1 are set, this branch would be unpredictable for architecture versions < 6. */ regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM, @@ -5209,23 +5211,25 @@ bx_write_pc (struct regcache *regs, ULONGEST val) /* Write to the PC as if from a load instruction. */ static void -load_write_pc (struct regcache *regs, ULONGEST val) +load_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { if (DISPLACED_STEPPING_ARCH_VERSION >= 5) bx_write_pc (regs, val); else - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); } /* Write to the PC as if from an ALU instruction. */ static void -alu_write_pc (struct regcache *regs, ULONGEST val) +alu_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { - if (DISPLACED_STEPPING_ARCH_VERSION >= 7 && displaced_in_arm_mode (regs)) + if (DISPLACED_STEPPING_ARCH_VERSION >= 7 && !dsc->is_thumb) bx_write_pc (regs, val); else - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); } /* Helper for writing to registers for displaced stepping. Writing to the PC @@ -5244,7 +5248,7 @@ displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, switch (write_pc) { case BRANCH_WRITE_PC: - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); break; case BX_WRITE_PC: @@ -5252,11 +5256,11 @@ displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, break; case LOAD_WRITE_PC: - load_write_pc (regs, val); + load_write_pc (regs, dsc, val); break; case ALU_WRITE_PC: - alu_write_pc (regs, val); + alu_write_pc (regs, dsc, val); break; case CANNOT_WRITE_PC: @@ -5361,8 +5365,8 @@ copy_preload (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, -> {pli/pld} [r0, #+/-imm]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - rn_val = displaced_read_reg (regs, from, rn); + dsc->tmp[0] = displaced_read_reg (regs, dsc, from, 0); + rn_val = displaced_read_reg (regs, dsc, from, rn); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); dsc->u.preload.immed = 1; @@ -5399,10 +5403,10 @@ copy_preload_reg (struct gdbarch *gdbarch, uint32_t insn, -> {pli/pld} [r0, r1 {, shift}]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); + dsc->tmp[0] = displaced_read_reg (regs, dsc, from, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, from, 1); + rn_val = displaced_read_reg (regs, dsc, from, rn); + rm_val = displaced_read_reg (regs, dsc, from, rm); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rm_val, CANNOT_WRITE_PC); @@ -5422,7 +5426,7 @@ cleanup_copro_load_store (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rn_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rn_val = displaced_read_reg (regs, dsc, dsc->insn_addr, 0); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); @@ -5454,8 +5458,8 @@ copy_copro_load_store (struct gdbarch *gdbarch, uint32_t insn, ldc/ldc2 are handled identically. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - rn_val = displaced_read_reg (regs, from, rn); + dsc->tmp[0] = displaced_read_reg (regs, dsc, from, 0); + rn_val = displaced_read_reg (regs, dsc, from, rn); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); dsc->u.ldst.writeback = bit (insn, 25); @@ -5476,7 +5480,7 @@ cleanup_branch (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, from, ARM_PS_REGNUM); int branch_taken = condition_true (dsc->u.branch.cond, status); enum pc_write_style write_pc = dsc->u.branch.exchange ? BX_WRITE_PC : BRANCH_WRITE_PC; @@ -5486,7 +5490,7 @@ cleanup_branch (struct gdbarch *gdbarch, struct regcache *regs, if (dsc->u.branch.link) { - ULONGEST pc = displaced_read_reg (regs, from, ARM_PC_REGNUM); + ULONGEST pc = displaced_read_reg (regs, dsc, from, ARM_PC_REGNUM); displaced_write_reg (regs, dsc, ARM_LR_REGNUM, pc - 4, CANNOT_WRITE_PC); } @@ -5566,7 +5570,7 @@ copy_bx_blx_reg (struct gdbarch *gdbarch, uint32_t insn, Don't set r14 in cleanup for BX. */ - dsc->u.branch.dest = displaced_read_reg (regs, from, rm); + dsc->u.branch.dest = displaced_read_reg (regs, dsc, from, rm); dsc->u.branch.cond = cond; dsc->u.branch.link = link; @@ -5585,7 +5589,7 @@ static void cleanup_alu_imm (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rd_val = displaced_read_reg (regs, dsc, dsc->insn_addr, 0); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, dsc->tmp[1], CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, dsc->rd, rd_val, ALU_WRITE_PC); @@ -5622,10 +5626,10 @@ copy_alu_imm (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, Cleanup: rd <- r0; r0 <- tmp1; r1 <- tmp2 */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, rn); - rd_val = displaced_read_reg (regs, from, rd); + dsc->tmp[0] = displaced_read_reg (regs, dsc, from, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, from, 1); + rn_val = displaced_read_reg (regs, dsc, from, rn); + rd_val = displaced_read_reg (regs, dsc, from, rd); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); dsc->rd = rd; @@ -5649,7 +5653,7 @@ cleanup_alu_reg (struct gdbarch *gdbarch, ULONGEST rd_val; int i; - rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + rd_val = displaced_read_reg (regs, dsc, dsc->insn_addr, 0); for (i = 0; i < 3; i++) displaced_write_reg (regs, dsc, i, dsc->tmp[i], CANNOT_WRITE_PC); @@ -5688,12 +5692,12 @@ copy_alu_reg (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, Cleanup: rd <- r0; r0, r1, r2 <- tmp1, tmp2, tmp3 */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); - rd_val = displaced_read_reg (regs, from, rd); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); + dsc->tmp[0] = displaced_read_reg (regs, dsc, from, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, from, 1); + dsc->tmp[2] = displaced_read_reg (regs, dsc, from, 2); + rd_val = displaced_read_reg (regs, dsc, from, rd); + rn_val = displaced_read_reg (regs, dsc, from, rn); + rm_val = displaced_read_reg (regs, dsc, from, rm); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rm_val, CANNOT_WRITE_PC); @@ -5716,7 +5720,7 @@ cleanup_alu_shifted_reg (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rd_val = displaced_read_reg (regs, dsc, dsc->insn_addr, 0); int i; for (i = 0; i < 4; i++) @@ -5762,12 +5766,12 @@ copy_alu_shifted_reg (struct gdbarch *gdbarch, uint32_t insn, */ for (i = 0; i < 4; i++) - dsc->tmp[i] = displaced_read_reg (regs, from, i); + dsc->tmp[i] = displaced_read_reg (regs, dsc, from, i); - rd_val = displaced_read_reg (regs, from, rd); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); - rs_val = displaced_read_reg (regs, from, rs); + rd_val = displaced_read_reg (regs, dsc, from, rd); + rn_val = displaced_read_reg (regs, dsc, from, rn); + rm_val = displaced_read_reg (regs, dsc, from, rm); + rs_val = displaced_read_reg (regs, dsc, from, rs); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rm_val, CANNOT_WRITE_PC); @@ -5793,10 +5797,10 @@ cleanup_load (struct gdbarch *gdbarch, struct regcache *regs, ULONGEST rt_val, rt_val2 = 0, rn_val; CORE_ADDR from = dsc->insn_addr; - rt_val = displaced_read_reg (regs, from, 0); + rt_val = displaced_read_reg (regs, dsc, from, 0); if (dsc->u.ldst.xfersize == 8) - rt_val2 = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, 2); + rt_val2 = displaced_read_reg (regs, dsc, from, 1); + rn_val = displaced_read_reg (regs, dsc, from, 2); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); if (dsc->u.ldst.xfersize > 4) @@ -5821,7 +5825,7 @@ cleanup_store (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { CORE_ADDR from = dsc->insn_addr; - ULONGEST rn_val = displaced_read_reg (regs, from, 2); + ULONGEST rn_val = displaced_read_reg (regs, dsc, from, 2); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); if (dsc->u.ldst.xfersize > 4) @@ -5870,18 +5874,18 @@ copy_extra_ld_st (struct gdbarch *gdbarch, uint32_t insn, int unpriveleged, internal_error (__FILE__, __LINE__, _("copy_extra_ld_st: instruction decode error")); - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); + dsc->tmp[0] = displaced_read_reg (regs, dsc, from, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, from, 1); + dsc->tmp[2] = displaced_read_reg (regs, dsc, from, 2); if (!immed) - dsc->tmp[3] = displaced_read_reg (regs, from, 3); + dsc->tmp[3] = displaced_read_reg (regs, dsc, from, 3); - rt_val = displaced_read_reg (regs, from, rt); + rt_val = displaced_read_reg (regs, dsc, from, rt); if (bytesize[opcode] == 8) - rt_val2 = displaced_read_reg (regs, from, rt + 1); - rn_val = displaced_read_reg (regs, from, rn); + rt_val2 = displaced_read_reg (regs, dsc, from, rt + 1); + rn_val = displaced_read_reg (regs, dsc, from, rn); if (!immed) - rm_val = displaced_read_reg (regs, from, rm); + rm_val = displaced_read_reg (regs, dsc, from, rm); displaced_write_reg (regs, dsc, 0, rt_val, CANNOT_WRITE_PC); if (bytesize[opcode] == 8) @@ -5937,17 +5941,17 @@ copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn, : (byte ? "strb" : "str"), usermode ? "t" : "", (unsigned long) insn); - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); + dsc->tmp[0] = displaced_read_reg (regs, dsc, from, 0); + dsc->tmp[2] = displaced_read_reg (regs, dsc, from, 2); if (!immed) - dsc->tmp[3] = displaced_read_reg (regs, from, 3); + dsc->tmp[3] = displaced_read_reg (regs, dsc, from, 3); if (!load) - dsc->tmp[4] = displaced_read_reg (regs, from, 4); + dsc->tmp[4] = displaced_read_reg (regs, dsc, from, 4); - rt_val = displaced_read_reg (regs, from, rt); - rn_val = displaced_read_reg (regs, from, rn); + rt_val = displaced_read_reg (regs, dsc, from, rt); + rn_val = displaced_read_reg (regs, dsc, from, rn); if (!immed) - rm_val = displaced_read_reg (regs, from, rm); + rm_val = displaced_read_reg (regs, dsc, from, rm); displaced_write_reg (regs, dsc, 0, rt_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rn_val, CANNOT_WRITE_PC); @@ -6056,7 +6060,7 @@ cleanup_block_load_all (struct gdbarch *gdbarch, struct regcache *regs, CORE_ADDR xfer_addr = dsc->u.block.xfer_addr; int exception_return = dsc->u.block.load && dsc->u.block.user && (regmask & 0x8000) != 0; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, from, ARM_PS_REGNUM); int do_transfer = condition_true (dsc->u.block.cond, status); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); @@ -6110,7 +6114,7 @@ cleanup_block_store_pc (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, from, ARM_PS_REGNUM); int store_executed = condition_true (dsc->u.block.cond, status); CORE_ADDR pc_stored_at, transferred_regs = bitcount (dsc->u.block.regmask); CORE_ADDR stm_insn_addr; @@ -6162,7 +6166,7 @@ cleanup_block_load_pc (struct gdbarch *gdbarch, struct displaced_step_closure *dsc) { ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, from, ARM_PS_REGNUM); int load_executed = condition_true (dsc->u.block.cond, status), i; unsigned int mask = dsc->u.block.regmask, write_reg = ARM_PC_REGNUM; unsigned int regs_loaded = bitcount (mask); @@ -6185,7 +6189,7 @@ cleanup_block_load_pc (struct gdbarch *gdbarch, if (read_reg != write_reg) { - ULONGEST rval = displaced_read_reg (regs, from, read_reg); + ULONGEST rval = displaced_read_reg (regs, dsc, from, read_reg); displaced_write_reg (regs, dsc, write_reg, rval, LOAD_WRITE_PC); if (debug_displaced) fprintf_unfiltered (gdb_stdlog, _("displaced: LDM: move " @@ -6265,7 +6269,7 @@ copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, fprintf_unfiltered (gdb_stdlog, "displaced: copying block transfer insn " "%.8lx\n", (unsigned long) insn); - dsc->u.block.xfer_addr = displaced_read_reg (regs, from, rn); + dsc->u.block.xfer_addr = displaced_read_reg (regs, dsc, from, rn); dsc->u.block.rn = rn; dsc->u.block.load = load; @@ -6301,7 +6305,7 @@ copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, unsigned int to = 0, from = 0, i, new_rn; for (i = 0; i < num_in_list; i++) - dsc->tmp[i] = displaced_read_reg (regs, from, i); + dsc->tmp[i] = displaced_read_reg (regs, dsc, from, i); /* Writeback makes things complicated. We need to avoid clobbering the base register with one of the registers in our modified diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h index 362be2e..e77d99a 100644 --- a/gdb/arm-tdep.h +++ b/gdb/arm-tdep.h @@ -302,7 +302,8 @@ extern void arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct displaced_step_closure *dsc); extern ULONGEST - displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno); + displaced_read_reg (struct regcache *regs, struct displaced_step_closure *dsc, + CORE_ADDR from, int regno); extern void displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, int regno, ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch, arm] Use cached dsc->is_thumb instead of re-computing 2011-03-04 13:30 [patch, arm] Use cached dsc->is_thumb instead of re-computing Yao Qi @ 2011-03-04 14:08 ` Ulrich Weigand 2011-03-07 9:02 ` Yao Qi 0 siblings, 1 reply; 7+ messages in thread From: Ulrich Weigand @ 2011-03-04 14:08 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches Yao Qi wrote: > During writing thumb displaced stepping, we find that displaced_read_reg > can be refactored to avoid calling displaced_in_arm_mode every time. Hmm, you now pass *both* DSC and FROM -- the latter is actually redundant now, since every caller must pass in dsc->insn_addr as FROM anyway ... Can you update the patch to pass DSC *instead of* FROM, and use dsc->insn_addr internally? Thanks, Ulrich -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch, arm] Use cached dsc->is_thumb instead of re-computing 2011-03-04 14:08 ` Ulrich Weigand @ 2011-03-07 9:02 ` Yao Qi 2011-03-07 15:50 ` Ulrich Weigand 0 siblings, 1 reply; 7+ messages in thread From: Yao Qi @ 2011-03-07 9:02 UTC (permalink / raw) To: Ulrich Weigand; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 385 bytes --] On 03/04/2011 10:08 PM, Ulrich Weigand wrote: > Hmm, you now pass *both* DSC and FROM -- the latter is actually redundant > now, since every caller must pass in dsc->insn_addr as FROM anyway ... > > Can you update the patch to pass DSC *instead of* FROM, and use > dsc->insn_addr internally? Yes, FROM is redundant to displaced_read_reg. How about this one? -- Yao (é½å°§) [-- Attachment #2: arm-displaced-read-refactor-0307.patch --] [-- Type: text/x-patch, Size: 22490 bytes --] gdb/ * arm-tdep.c (displaced_read_reg): Add `dsc' parameter, remove `from' parameter. Use cached result instead of calling displaced_in_arm_mode again. (branch_write_pc, alu_write_pc, load_write_pc): Add `dsc' parameter. (displaced_write_reg, copy_preload, copy_preload_reg): Callers update. (cleanup_copro_load_store, copy_copro_load_store): Likewise. (cleanup_branch, copy_bx_blx_reg, copy_alu_imm): Likewise. (cleanup_alu_reg, copy_alu_reg, cleanup_alu_shifted_reg): Likewise. (copy_alu_shifted_reg, cleanup_load, cleanup_store): Likewise. (copy_extra_ld_st, copy_ldr_str_ldrb_strb): Likewise. (cleanup_block_load_all, cleanup_block_store_pc): Likewise. (cleanup_block_load_pc, copy_block_xfer): Likewise. * arm-linux-tdep.c (arm_linux_copy_svc): Callers update. (arm_catch_kernel_helper_return): Likewise. * gdb/arm-tdep.h : Update function declarations. diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c index f60ecc3..d2cf0d9 100644 --- a/gdb/arm-linux-tdep.c +++ b/gdb/arm-linux-tdep.c @@ -805,7 +805,7 @@ arm_linux_copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to, CORE_ADDR return_to = 0; struct frame_info *frame; - unsigned int svc_number = displaced_read_reg (regs, from, 7); + unsigned int svc_number = displaced_read_reg (regs, dsc, 7); int is_sigreturn = 0; if (debug_displaced) @@ -918,7 +918,7 @@ arm_catch_kernel_helper_return (struct gdbarch *gdbarch, CORE_ADDR from, Insn: ldr pc, [r14, #4] Cleanup: r14 <- tmp[0], pc <- tmp[0]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, ARM_LR_REGNUM); + dsc->tmp[0] = displaced_read_reg (regs, dsc, ARM_LR_REGNUM); displaced_write_reg (regs, dsc, ARM_LR_REGNUM, (ULONGEST) to + 4, CANNOT_WRITE_PC); write_memory_unsigned_integer (to + 8, 4, byte_order, from); diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 2cf2eec..1561306 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -5118,9 +5118,11 @@ static int displaced_in_arm_mode (struct regcache *regs); location. */ ULONGEST -displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno) +displaced_read_reg (struct regcache *regs, struct displaced_step_closure *dsc, + int regno) { ULONGEST ret; + CORE_ADDR from = dsc->insn_addr; if (regno == ARM_PC_REGNUM) { @@ -5130,7 +5132,7 @@ displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno) - When executing a Thumb instruction, PC reads as the address of the current instruction plus 4. */ - if (displaced_in_arm_mode (regs)) + if (!dsc->is_thumb) from += 8; else from += 4; @@ -5164,9 +5166,10 @@ displaced_in_arm_mode (struct regcache *regs) /* Write to the PC as from a branch instruction. */ static void -branch_write_pc (struct regcache *regs, ULONGEST val) +branch_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { - if (displaced_in_arm_mode (regs)) + if (!dsc->is_thumb) /* Note: If bits 0/1 are set, this branch would be unpredictable for architecture versions < 6. */ regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM, @@ -5209,23 +5212,25 @@ bx_write_pc (struct regcache *regs, ULONGEST val) /* Write to the PC as if from a load instruction. */ static void -load_write_pc (struct regcache *regs, ULONGEST val) +load_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { if (DISPLACED_STEPPING_ARCH_VERSION >= 5) bx_write_pc (regs, val); else - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); } /* Write to the PC as if from an ALU instruction. */ static void -alu_write_pc (struct regcache *regs, ULONGEST val) +alu_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { - if (DISPLACED_STEPPING_ARCH_VERSION >= 7 && displaced_in_arm_mode (regs)) + if (DISPLACED_STEPPING_ARCH_VERSION >= 7 && !dsc->is_thumb) bx_write_pc (regs, val); else - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); } /* Helper for writing to registers for displaced stepping. Writing to the PC @@ -5244,7 +5249,7 @@ displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, switch (write_pc) { case BRANCH_WRITE_PC: - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); break; case BX_WRITE_PC: @@ -5252,11 +5257,11 @@ displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, break; case LOAD_WRITE_PC: - load_write_pc (regs, val); + load_write_pc (regs, dsc, val); break; case ALU_WRITE_PC: - alu_write_pc (regs, val); + alu_write_pc (regs, dsc, val); break; case CANNOT_WRITE_PC: @@ -5346,7 +5351,6 @@ copy_preload (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, { unsigned int rn = bits (insn, 16, 19); ULONGEST rn_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000f0000ul)) return copy_unmodified (gdbarch, insn, "preload", dsc); @@ -5361,8 +5365,8 @@ copy_preload (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, -> {pli/pld} [r0, #+/-imm]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - rn_val = displaced_read_reg (regs, from, rn); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + rn_val = displaced_read_reg (regs, dsc, rn); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); dsc->u.preload.immed = 1; @@ -5384,7 +5388,6 @@ copy_preload_reg (struct gdbarch *gdbarch, uint32_t insn, unsigned int rn = bits (insn, 16, 19); unsigned int rm = bits (insn, 0, 3); ULONGEST rn_val, rm_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000f000ful)) return copy_unmodified (gdbarch, insn, "preload reg", dsc); @@ -5399,10 +5402,10 @@ copy_preload_reg (struct gdbarch *gdbarch, uint32_t insn, -> {pli/pld} [r0, r1 {, shift}]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, 1); + rn_val = displaced_read_reg (regs, dsc, rn); + rm_val = displaced_read_reg (regs, dsc, rm); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rm_val, CANNOT_WRITE_PC); @@ -5422,7 +5425,7 @@ cleanup_copro_load_store (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rn_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rn_val = displaced_read_reg (regs, dsc, 0); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); @@ -5437,7 +5440,6 @@ copy_copro_load_store (struct gdbarch *gdbarch, uint32_t insn, { unsigned int rn = bits (insn, 16, 19); ULONGEST rn_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000f0000ul)) return copy_unmodified (gdbarch, insn, "copro load/store", dsc); @@ -5454,8 +5456,8 @@ copy_copro_load_store (struct gdbarch *gdbarch, uint32_t insn, ldc/ldc2 are handled identically. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - rn_val = displaced_read_reg (regs, from, rn); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + rn_val = displaced_read_reg (regs, dsc, rn); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); dsc->u.ldst.writeback = bit (insn, 25); @@ -5475,8 +5477,7 @@ static void cleanup_branch (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM); int branch_taken = condition_true (dsc->u.branch.cond, status); enum pc_write_style write_pc = dsc->u.branch.exchange ? BX_WRITE_PC : BRANCH_WRITE_PC; @@ -5486,7 +5487,7 @@ cleanup_branch (struct gdbarch *gdbarch, struct regcache *regs, if (dsc->u.branch.link) { - ULONGEST pc = displaced_read_reg (regs, from, ARM_PC_REGNUM); + ULONGEST pc = displaced_read_reg (regs, dsc, ARM_PC_REGNUM); displaced_write_reg (regs, dsc, ARM_LR_REGNUM, pc - 4, CANNOT_WRITE_PC); } @@ -5551,7 +5552,6 @@ copy_bx_blx_reg (struct gdbarch *gdbarch, uint32_t insn, BLX: x12xxx3x. */ int link = bit (insn, 5); unsigned int rm = bits (insn, 0, 3); - CORE_ADDR from = dsc->insn_addr; if (debug_displaced) fprintf_unfiltered (gdb_stdlog, "displaced: copying %s register insn " @@ -5566,7 +5566,7 @@ copy_bx_blx_reg (struct gdbarch *gdbarch, uint32_t insn, Don't set r14 in cleanup for BX. */ - dsc->u.branch.dest = displaced_read_reg (regs, from, rm); + dsc->u.branch.dest = displaced_read_reg (regs, dsc, rm); dsc->u.branch.cond = cond; dsc->u.branch.link = link; @@ -5585,7 +5585,7 @@ static void cleanup_alu_imm (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rd_val = displaced_read_reg (regs, dsc, 0); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, dsc->tmp[1], CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, dsc->rd, rd_val, ALU_WRITE_PC); @@ -5600,7 +5600,6 @@ copy_alu_imm (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, unsigned int op = bits (insn, 21, 24); int is_mov = (op == 0xd); ULONGEST rd_val, rn_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000ff000ul)) return copy_unmodified (gdbarch, insn, "ALU immediate", dsc); @@ -5622,10 +5621,10 @@ copy_alu_imm (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, Cleanup: rd <- r0; r0 <- tmp1; r1 <- tmp2 */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, rn); - rd_val = displaced_read_reg (regs, from, rd); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, 1); + rn_val = displaced_read_reg (regs, dsc, rn); + rd_val = displaced_read_reg (regs, dsc, rd); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); dsc->rd = rd; @@ -5649,7 +5648,7 @@ cleanup_alu_reg (struct gdbarch *gdbarch, ULONGEST rd_val; int i; - rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + rd_val = displaced_read_reg (regs, dsc, 0); for (i = 0; i < 3; i++) displaced_write_reg (regs, dsc, i, dsc->tmp[i], CANNOT_WRITE_PC); @@ -5667,7 +5666,6 @@ copy_alu_reg (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, unsigned int op = bits (insn, 21, 24); int is_mov = (op == 0xd); ULONGEST rd_val, rn_val, rm_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000ff00ful)) return copy_unmodified (gdbarch, insn, "ALU reg", dsc); @@ -5688,12 +5686,12 @@ copy_alu_reg (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, Cleanup: rd <- r0; r0, r1, r2 <- tmp1, tmp2, tmp3 */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); - rd_val = displaced_read_reg (regs, from, rd); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, 1); + dsc->tmp[2] = displaced_read_reg (regs, dsc, 2); + rd_val = displaced_read_reg (regs, dsc, rd); + rn_val = displaced_read_reg (regs, dsc, rn); + rm_val = displaced_read_reg (regs, dsc, rm); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rm_val, CANNOT_WRITE_PC); @@ -5716,7 +5714,7 @@ cleanup_alu_shifted_reg (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rd_val = displaced_read_reg (regs, dsc, 0); int i; for (i = 0; i < 4; i++) @@ -5737,7 +5735,6 @@ copy_alu_shifted_reg (struct gdbarch *gdbarch, uint32_t insn, unsigned int op = bits (insn, 21, 24); int is_mov = (op == 0xd), i; ULONGEST rd_val, rn_val, rm_val, rs_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000fff0ful)) return copy_unmodified (gdbarch, insn, "ALU shifted reg", dsc); @@ -5762,12 +5759,12 @@ copy_alu_shifted_reg (struct gdbarch *gdbarch, uint32_t insn, */ for (i = 0; i < 4; i++) - dsc->tmp[i] = displaced_read_reg (regs, from, i); + dsc->tmp[i] = displaced_read_reg (regs, dsc, i); - rd_val = displaced_read_reg (regs, from, rd); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); - rs_val = displaced_read_reg (regs, from, rs); + rd_val = displaced_read_reg (regs, dsc, rd); + rn_val = displaced_read_reg (regs, dsc, rn); + rm_val = displaced_read_reg (regs, dsc, rm); + rs_val = displaced_read_reg (regs, dsc, rs); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rm_val, CANNOT_WRITE_PC); @@ -5791,12 +5788,11 @@ cleanup_load (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { ULONGEST rt_val, rt_val2 = 0, rn_val; - CORE_ADDR from = dsc->insn_addr; - rt_val = displaced_read_reg (regs, from, 0); + rt_val = displaced_read_reg (regs, dsc, 0); if (dsc->u.ldst.xfersize == 8) - rt_val2 = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, 2); + rt_val2 = displaced_read_reg (regs, dsc, 1); + rn_val = displaced_read_reg (regs, dsc, 2); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); if (dsc->u.ldst.xfersize > 4) @@ -5820,8 +5816,7 @@ static void cleanup_store (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - CORE_ADDR from = dsc->insn_addr; - ULONGEST rn_val = displaced_read_reg (regs, from, 2); + ULONGEST rn_val = displaced_read_reg (regs, dsc, 2); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); if (dsc->u.ldst.xfersize > 4) @@ -5854,7 +5849,6 @@ copy_extra_ld_st (struct gdbarch *gdbarch, uint32_t insn, int unpriveleged, int immed = (op1 & 0x4) != 0; int opcode; ULONGEST rt_val, rt_val2 = 0, rn_val, rm_val = 0; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000ff00ful)) return copy_unmodified (gdbarch, insn, "extra load/store", dsc); @@ -5870,18 +5864,18 @@ copy_extra_ld_st (struct gdbarch *gdbarch, uint32_t insn, int unpriveleged, internal_error (__FILE__, __LINE__, _("copy_extra_ld_st: instruction decode error")); - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, 1); + dsc->tmp[2] = displaced_read_reg (regs, dsc, 2); if (!immed) - dsc->tmp[3] = displaced_read_reg (regs, from, 3); + dsc->tmp[3] = displaced_read_reg (regs, dsc, 3); - rt_val = displaced_read_reg (regs, from, rt); + rt_val = displaced_read_reg (regs, dsc, rt); if (bytesize[opcode] == 8) - rt_val2 = displaced_read_reg (regs, from, rt + 1); - rn_val = displaced_read_reg (regs, from, rn); + rt_val2 = displaced_read_reg (regs, dsc, rt + 1); + rn_val = displaced_read_reg (regs, dsc, rn); if (!immed) - rm_val = displaced_read_reg (regs, from, rm); + rm_val = displaced_read_reg (regs, dsc, rm); displaced_write_reg (regs, dsc, 0, rt_val, CANNOT_WRITE_PC); if (bytesize[opcode] == 8) @@ -5926,7 +5920,6 @@ copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn, unsigned int rn = bits (insn, 16, 19); unsigned int rm = bits (insn, 0, 3); /* Only valid if !immed. */ ULONGEST rt_val, rn_val, rm_val = 0; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000ff00ful)) return copy_unmodified (gdbarch, insn, "load/store", dsc); @@ -5937,17 +5930,17 @@ copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn, : (byte ? "strb" : "str"), usermode ? "t" : "", (unsigned long) insn); - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[2] = displaced_read_reg (regs, dsc, 2); if (!immed) - dsc->tmp[3] = displaced_read_reg (regs, from, 3); + dsc->tmp[3] = displaced_read_reg (regs, dsc, 3); if (!load) - dsc->tmp[4] = displaced_read_reg (regs, from, 4); + dsc->tmp[4] = displaced_read_reg (regs, dsc, 4); - rt_val = displaced_read_reg (regs, from, rt); - rn_val = displaced_read_reg (regs, from, rn); + rt_val = displaced_read_reg (regs, dsc, rt); + rn_val = displaced_read_reg (regs, dsc, rn); if (!immed) - rm_val = displaced_read_reg (regs, from, rm); + rm_val = displaced_read_reg (regs, dsc, rm); displaced_write_reg (regs, dsc, 0, rt_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rn_val, CANNOT_WRITE_PC); @@ -6047,7 +6040,6 @@ static void cleanup_block_load_all (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST from = dsc->insn_addr; int inc = dsc->u.block.increment; int bump_before = dsc->u.block.before ? (inc ? 4 : -4) : 0; int bump_after = dsc->u.block.before ? 0 : (inc ? 4 : -4); @@ -6056,7 +6048,7 @@ cleanup_block_load_all (struct gdbarch *gdbarch, struct regcache *regs, CORE_ADDR xfer_addr = dsc->u.block.xfer_addr; int exception_return = dsc->u.block.load && dsc->u.block.user && (regmask & 0x8000) != 0; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM); int do_transfer = condition_true (dsc->u.block.cond, status); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); @@ -6109,8 +6101,7 @@ static void cleanup_block_store_pc (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM); int store_executed = condition_true (dsc->u.block.cond, status); CORE_ADDR pc_stored_at, transferred_regs = bitcount (dsc->u.block.regmask); CORE_ADDR stm_insn_addr; @@ -6161,8 +6152,7 @@ cleanup_block_load_pc (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM); int load_executed = condition_true (dsc->u.block.cond, status), i; unsigned int mask = dsc->u.block.regmask, write_reg = ARM_PC_REGNUM; unsigned int regs_loaded = bitcount (mask); @@ -6185,7 +6175,7 @@ cleanup_block_load_pc (struct gdbarch *gdbarch, if (read_reg != write_reg) { - ULONGEST rval = displaced_read_reg (regs, from, read_reg); + ULONGEST rval = displaced_read_reg (regs, dsc, read_reg); displaced_write_reg (regs, dsc, write_reg, rval, LOAD_WRITE_PC); if (debug_displaced) fprintf_unfiltered (gdb_stdlog, _("displaced: LDM: move " @@ -6247,7 +6237,6 @@ copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, int before = bit (insn, 24); int writeback = bit (insn, 21); int rn = bits (insn, 16, 19); - CORE_ADDR from = dsc->insn_addr; /* Block transfers which don't mention PC can be run directly out-of-line. */ @@ -6265,7 +6254,7 @@ copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, fprintf_unfiltered (gdb_stdlog, "displaced: copying block transfer insn " "%.8lx\n", (unsigned long) insn); - dsc->u.block.xfer_addr = displaced_read_reg (regs, from, rn); + dsc->u.block.xfer_addr = displaced_read_reg (regs, dsc, rn); dsc->u.block.rn = rn; dsc->u.block.load = load; @@ -6301,7 +6290,7 @@ copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, unsigned int to = 0, from = 0, i, new_rn; for (i = 0; i < num_in_list; i++) - dsc->tmp[i] = displaced_read_reg (regs, from, i); + dsc->tmp[i] = displaced_read_reg (regs, dsc, i); /* Writeback makes things complicated. We need to avoid clobbering the base register with one of the registers in our modified @@ -6358,8 +6347,7 @@ static void cleanup_svc (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - CORE_ADDR from = dsc->insn_addr; - CORE_ADDR resume_addr = from + 4; + CORE_ADDR resume_addr = dsc->insn_addr + 4; if (debug_displaced) fprintf_unfiltered (gdb_stdlog, "displaced: cleanup for svc, resume at " @@ -6372,8 +6360,6 @@ static int copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to, struct regcache *regs, struct displaced_step_closure *dsc) { - CORE_ADDR from = dsc->insn_addr; - /* Allow OS-specific code to override SVC handling. */ if (dsc->u.svc.copy_svc_os) return dsc->u.svc.copy_svc_os (gdbarch, insn, to, regs, dsc); diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h index 362be2e..ebd5e6e 100644 --- a/gdb/arm-tdep.h +++ b/gdb/arm-tdep.h @@ -302,7 +302,8 @@ extern void arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct displaced_step_closure *dsc); extern ULONGEST - displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno); + displaced_read_reg (struct regcache *regs, struct displaced_step_closure *dsc, + int regno); extern void displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, int regno, ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch, arm] Use cached dsc->is_thumb instead of re-computing 2011-03-07 9:02 ` Yao Qi @ 2011-03-07 15:50 ` Ulrich Weigand 2011-03-07 15:55 ` Yao Qi 0 siblings, 1 reply; 7+ messages in thread From: Ulrich Weigand @ 2011-03-07 15:50 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches Yao Qi wrote: > gdb/ > * arm-tdep.c (displaced_read_reg): Add `dsc' parameter, remove `from' > parameter. Use cached result instead of calling displaced_in_arm_mode > again. > (branch_write_pc, alu_write_pc, load_write_pc): Add `dsc' parameter. > (displaced_write_reg, copy_preload, copy_preload_reg): Callers update. > (cleanup_copro_load_store, copy_copro_load_store): Likewise. > (cleanup_branch, copy_bx_blx_reg, copy_alu_imm): Likewise. > (cleanup_alu_reg, copy_alu_reg, cleanup_alu_shifted_reg): Likewise. > (copy_alu_shifted_reg, cleanup_load, cleanup_store): Likewise. > (copy_extra_ld_st, copy_ldr_str_ldrb_strb): Likewise. > (cleanup_block_load_all, cleanup_block_store_pc): Likewise. > (cleanup_block_load_pc, copy_block_xfer): Likewise. > * arm-linux-tdep.c (arm_linux_copy_svc): Callers update. > (arm_catch_kernel_helper_return): Likewise. > * gdb/arm-tdep.h : Update function declarations. There's a now-unused local variable "from" in arm_linux_copy_svc (you removed those nearly everywhere, but apparently missed this one), and the recently- added prototype declaration for displaced_read_reg is now unneeded again. If you could remove those two as well, the patch is OK. Thanks, Ulrich -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch, arm] Use cached dsc->is_thumb instead of re-computing 2011-03-07 15:50 ` Ulrich Weigand @ 2011-03-07 15:55 ` Yao Qi 2011-03-07 16:22 ` Ulrich Weigand 0 siblings, 1 reply; 7+ messages in thread From: Yao Qi @ 2011-03-07 15:55 UTC (permalink / raw) To: Ulrich Weigand; +Cc: gdb-patches [-- Attachment #1: Type: text/plain, Size: 389 bytes --] On 03/07/2011 10:46 PM, Ulrich Weigand wrote: > There's a now-unused local variable "from" in arm_linux_copy_svc (you removed > those nearly everywhere, but apparently missed this one), and the recently- Done. > added prototype declaration for displaced_read_reg is now unneeded again. > I guess you mean "displaced_in_arm_mode" here. Removed its declaration. -- Yao (é½å°§) [-- Attachment #2: arm-displaced-read-refactor-0307.patch --] [-- Type: text/x-patch, Size: 22959 bytes --] gdb/ * arm-tdep.c: Remove prototype declaration displaced_in_arm_mode. (displaced_read_reg): Add `dsc' parameter, remove `from' parameter. Use cached result instead of calling displaced_in_arm_mode again. (branch_write_pc, alu_write_pc, load_write_pc): Add `dsc' parameter. (displaced_write_reg, copy_preload, copy_preload_reg): Callers update. (cleanup_copro_load_store, copy_copro_load_store): Likewise. (cleanup_branch, copy_bx_blx_reg, copy_alu_imm): Likewise. (cleanup_alu_reg, copy_alu_reg, cleanup_alu_shifted_reg): Likewise. (copy_alu_shifted_reg, cleanup_load, cleanup_store): Likewise. (copy_extra_ld_st, copy_ldr_str_ldrb_strb): Likewise. (cleanup_block_load_all, cleanup_block_store_pc): Likewise. (cleanup_block_load_pc, copy_block_xfer): Likewise. * arm-linux-tdep.c (arm_linux_copy_svc): Callers update. (arm_catch_kernel_helper_return): Likewise. * gdb/arm-tdep.h : Update function declarations. diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c index f60ecc3..2f3109c 100644 --- a/gdb/arm-linux-tdep.c +++ b/gdb/arm-linux-tdep.c @@ -801,11 +801,10 @@ static int arm_linux_copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to, struct regcache *regs, struct displaced_step_closure *dsc) { - CORE_ADDR from = dsc->insn_addr; CORE_ADDR return_to = 0; struct frame_info *frame; - unsigned int svc_number = displaced_read_reg (regs, from, 7); + unsigned int svc_number = displaced_read_reg (regs, dsc, 7); int is_sigreturn = 0; if (debug_displaced) @@ -918,7 +917,7 @@ arm_catch_kernel_helper_return (struct gdbarch *gdbarch, CORE_ADDR from, Insn: ldr pc, [r14, #4] Cleanup: r14 <- tmp[0], pc <- tmp[0]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, ARM_LR_REGNUM); + dsc->tmp[0] = displaced_read_reg (regs, dsc, ARM_LR_REGNUM); displaced_write_reg (regs, dsc, ARM_LR_REGNUM, (ULONGEST) to + 4, CANNOT_WRITE_PC); write_memory_unsigned_integer (to + 8, 4, byte_order, from); diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 2cf2eec..7796176 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -5111,16 +5111,16 @@ arm_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr) /* NOP instruction (mov r0, r0). */ #define ARM_NOP 0xe1a00000 -static int displaced_in_arm_mode (struct regcache *regs); - /* Helper for register reads for displaced stepping. In particular, this returns the PC as it would be seen by the instruction at its original location. */ ULONGEST -displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno) +displaced_read_reg (struct regcache *regs, struct displaced_step_closure *dsc, + int regno) { ULONGEST ret; + CORE_ADDR from = dsc->insn_addr; if (regno == ARM_PC_REGNUM) { @@ -5130,7 +5130,7 @@ displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno) - When executing a Thumb instruction, PC reads as the address of the current instruction plus 4. */ - if (displaced_in_arm_mode (regs)) + if (!dsc->is_thumb) from += 8; else from += 4; @@ -5164,9 +5164,10 @@ displaced_in_arm_mode (struct regcache *regs) /* Write to the PC as from a branch instruction. */ static void -branch_write_pc (struct regcache *regs, ULONGEST val) +branch_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { - if (displaced_in_arm_mode (regs)) + if (!dsc->is_thumb) /* Note: If bits 0/1 are set, this branch would be unpredictable for architecture versions < 6. */ regcache_cooked_write_unsigned (regs, ARM_PC_REGNUM, @@ -5209,23 +5210,25 @@ bx_write_pc (struct regcache *regs, ULONGEST val) /* Write to the PC as if from a load instruction. */ static void -load_write_pc (struct regcache *regs, ULONGEST val) +load_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { if (DISPLACED_STEPPING_ARCH_VERSION >= 5) bx_write_pc (regs, val); else - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); } /* Write to the PC as if from an ALU instruction. */ static void -alu_write_pc (struct regcache *regs, ULONGEST val) +alu_write_pc (struct regcache *regs, struct displaced_step_closure *dsc, + ULONGEST val) { - if (DISPLACED_STEPPING_ARCH_VERSION >= 7 && displaced_in_arm_mode (regs)) + if (DISPLACED_STEPPING_ARCH_VERSION >= 7 && !dsc->is_thumb) bx_write_pc (regs, val); else - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); } /* Helper for writing to registers for displaced stepping. Writing to the PC @@ -5244,7 +5247,7 @@ displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, switch (write_pc) { case BRANCH_WRITE_PC: - branch_write_pc (regs, val); + branch_write_pc (regs, dsc, val); break; case BX_WRITE_PC: @@ -5252,11 +5255,11 @@ displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, break; case LOAD_WRITE_PC: - load_write_pc (regs, val); + load_write_pc (regs, dsc, val); break; case ALU_WRITE_PC: - alu_write_pc (regs, val); + alu_write_pc (regs, dsc, val); break; case CANNOT_WRITE_PC: @@ -5346,7 +5349,6 @@ copy_preload (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, { unsigned int rn = bits (insn, 16, 19); ULONGEST rn_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000f0000ul)) return copy_unmodified (gdbarch, insn, "preload", dsc); @@ -5361,8 +5363,8 @@ copy_preload (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, -> {pli/pld} [r0, #+/-imm]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - rn_val = displaced_read_reg (regs, from, rn); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + rn_val = displaced_read_reg (regs, dsc, rn); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); dsc->u.preload.immed = 1; @@ -5384,7 +5386,6 @@ copy_preload_reg (struct gdbarch *gdbarch, uint32_t insn, unsigned int rn = bits (insn, 16, 19); unsigned int rm = bits (insn, 0, 3); ULONGEST rn_val, rm_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000f000ful)) return copy_unmodified (gdbarch, insn, "preload reg", dsc); @@ -5399,10 +5400,10 @@ copy_preload_reg (struct gdbarch *gdbarch, uint32_t insn, -> {pli/pld} [r0, r1 {, shift}]. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, 1); + rn_val = displaced_read_reg (regs, dsc, rn); + rm_val = displaced_read_reg (regs, dsc, rm); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rm_val, CANNOT_WRITE_PC); @@ -5422,7 +5423,7 @@ cleanup_copro_load_store (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rn_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rn_val = displaced_read_reg (regs, dsc, 0); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); @@ -5437,7 +5438,6 @@ copy_copro_load_store (struct gdbarch *gdbarch, uint32_t insn, { unsigned int rn = bits (insn, 16, 19); ULONGEST rn_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000f0000ul)) return copy_unmodified (gdbarch, insn, "copro load/store", dsc); @@ -5454,8 +5454,8 @@ copy_copro_load_store (struct gdbarch *gdbarch, uint32_t insn, ldc/ldc2 are handled identically. */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - rn_val = displaced_read_reg (regs, from, rn); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + rn_val = displaced_read_reg (regs, dsc, rn); displaced_write_reg (regs, dsc, 0, rn_val, CANNOT_WRITE_PC); dsc->u.ldst.writeback = bit (insn, 25); @@ -5475,8 +5475,7 @@ static void cleanup_branch (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM); int branch_taken = condition_true (dsc->u.branch.cond, status); enum pc_write_style write_pc = dsc->u.branch.exchange ? BX_WRITE_PC : BRANCH_WRITE_PC; @@ -5486,7 +5485,7 @@ cleanup_branch (struct gdbarch *gdbarch, struct regcache *regs, if (dsc->u.branch.link) { - ULONGEST pc = displaced_read_reg (regs, from, ARM_PC_REGNUM); + ULONGEST pc = displaced_read_reg (regs, dsc, ARM_PC_REGNUM); displaced_write_reg (regs, dsc, ARM_LR_REGNUM, pc - 4, CANNOT_WRITE_PC); } @@ -5551,7 +5550,6 @@ copy_bx_blx_reg (struct gdbarch *gdbarch, uint32_t insn, BLX: x12xxx3x. */ int link = bit (insn, 5); unsigned int rm = bits (insn, 0, 3); - CORE_ADDR from = dsc->insn_addr; if (debug_displaced) fprintf_unfiltered (gdb_stdlog, "displaced: copying %s register insn " @@ -5566,7 +5564,7 @@ copy_bx_blx_reg (struct gdbarch *gdbarch, uint32_t insn, Don't set r14 in cleanup for BX. */ - dsc->u.branch.dest = displaced_read_reg (regs, from, rm); + dsc->u.branch.dest = displaced_read_reg (regs, dsc, rm); dsc->u.branch.cond = cond; dsc->u.branch.link = link; @@ -5585,7 +5583,7 @@ static void cleanup_alu_imm (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rd_val = displaced_read_reg (regs, dsc, 0); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, dsc->tmp[1], CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, dsc->rd, rd_val, ALU_WRITE_PC); @@ -5600,7 +5598,6 @@ copy_alu_imm (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, unsigned int op = bits (insn, 21, 24); int is_mov = (op == 0xd); ULONGEST rd_val, rn_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000ff000ul)) return copy_unmodified (gdbarch, insn, "ALU immediate", dsc); @@ -5622,10 +5619,10 @@ copy_alu_imm (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, Cleanup: rd <- r0; r0 <- tmp1; r1 <- tmp2 */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, rn); - rd_val = displaced_read_reg (regs, from, rd); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, 1); + rn_val = displaced_read_reg (regs, dsc, rn); + rd_val = displaced_read_reg (regs, dsc, rd); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); dsc->rd = rd; @@ -5649,7 +5646,7 @@ cleanup_alu_reg (struct gdbarch *gdbarch, ULONGEST rd_val; int i; - rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + rd_val = displaced_read_reg (regs, dsc, 0); for (i = 0; i < 3; i++) displaced_write_reg (regs, dsc, i, dsc->tmp[i], CANNOT_WRITE_PC); @@ -5667,7 +5664,6 @@ copy_alu_reg (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, unsigned int op = bits (insn, 21, 24); int is_mov = (op == 0xd); ULONGEST rd_val, rn_val, rm_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000ff00ful)) return copy_unmodified (gdbarch, insn, "ALU reg", dsc); @@ -5688,12 +5684,12 @@ copy_alu_reg (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, Cleanup: rd <- r0; r0, r1, r2 <- tmp1, tmp2, tmp3 */ - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); - rd_val = displaced_read_reg (regs, from, rd); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, 1); + dsc->tmp[2] = displaced_read_reg (regs, dsc, 2); + rd_val = displaced_read_reg (regs, dsc, rd); + rn_val = displaced_read_reg (regs, dsc, rn); + rm_val = displaced_read_reg (regs, dsc, rm); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rm_val, CANNOT_WRITE_PC); @@ -5716,7 +5712,7 @@ cleanup_alu_shifted_reg (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST rd_val = displaced_read_reg (regs, dsc->insn_addr, 0); + ULONGEST rd_val = displaced_read_reg (regs, dsc, 0); int i; for (i = 0; i < 4; i++) @@ -5737,7 +5733,6 @@ copy_alu_shifted_reg (struct gdbarch *gdbarch, uint32_t insn, unsigned int op = bits (insn, 21, 24); int is_mov = (op == 0xd), i; ULONGEST rd_val, rn_val, rm_val, rs_val; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000fff0ful)) return copy_unmodified (gdbarch, insn, "ALU shifted reg", dsc); @@ -5762,12 +5757,12 @@ copy_alu_shifted_reg (struct gdbarch *gdbarch, uint32_t insn, */ for (i = 0; i < 4; i++) - dsc->tmp[i] = displaced_read_reg (regs, from, i); + dsc->tmp[i] = displaced_read_reg (regs, dsc, i); - rd_val = displaced_read_reg (regs, from, rd); - rn_val = displaced_read_reg (regs, from, rn); - rm_val = displaced_read_reg (regs, from, rm); - rs_val = displaced_read_reg (regs, from, rs); + rd_val = displaced_read_reg (regs, dsc, rd); + rn_val = displaced_read_reg (regs, dsc, rn); + rm_val = displaced_read_reg (regs, dsc, rm); + rs_val = displaced_read_reg (regs, dsc, rs); displaced_write_reg (regs, dsc, 0, rd_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 1, rn_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rm_val, CANNOT_WRITE_PC); @@ -5791,12 +5786,11 @@ cleanup_load (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { ULONGEST rt_val, rt_val2 = 0, rn_val; - CORE_ADDR from = dsc->insn_addr; - rt_val = displaced_read_reg (regs, from, 0); + rt_val = displaced_read_reg (regs, dsc, 0); if (dsc->u.ldst.xfersize == 8) - rt_val2 = displaced_read_reg (regs, from, 1); - rn_val = displaced_read_reg (regs, from, 2); + rt_val2 = displaced_read_reg (regs, dsc, 1); + rn_val = displaced_read_reg (regs, dsc, 2); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); if (dsc->u.ldst.xfersize > 4) @@ -5820,8 +5814,7 @@ static void cleanup_store (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - CORE_ADDR from = dsc->insn_addr; - ULONGEST rn_val = displaced_read_reg (regs, from, 2); + ULONGEST rn_val = displaced_read_reg (regs, dsc, 2); displaced_write_reg (regs, dsc, 0, dsc->tmp[0], CANNOT_WRITE_PC); if (dsc->u.ldst.xfersize > 4) @@ -5854,7 +5847,6 @@ copy_extra_ld_st (struct gdbarch *gdbarch, uint32_t insn, int unpriveleged, int immed = (op1 & 0x4) != 0; int opcode; ULONGEST rt_val, rt_val2 = 0, rn_val, rm_val = 0; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000ff00ful)) return copy_unmodified (gdbarch, insn, "extra load/store", dsc); @@ -5870,18 +5862,18 @@ copy_extra_ld_st (struct gdbarch *gdbarch, uint32_t insn, int unpriveleged, internal_error (__FILE__, __LINE__, _("copy_extra_ld_st: instruction decode error")); - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[1] = displaced_read_reg (regs, from, 1); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[1] = displaced_read_reg (regs, dsc, 1); + dsc->tmp[2] = displaced_read_reg (regs, dsc, 2); if (!immed) - dsc->tmp[3] = displaced_read_reg (regs, from, 3); + dsc->tmp[3] = displaced_read_reg (regs, dsc, 3); - rt_val = displaced_read_reg (regs, from, rt); + rt_val = displaced_read_reg (regs, dsc, rt); if (bytesize[opcode] == 8) - rt_val2 = displaced_read_reg (regs, from, rt + 1); - rn_val = displaced_read_reg (regs, from, rn); + rt_val2 = displaced_read_reg (regs, dsc, rt + 1); + rn_val = displaced_read_reg (regs, dsc, rn); if (!immed) - rm_val = displaced_read_reg (regs, from, rm); + rm_val = displaced_read_reg (regs, dsc, rm); displaced_write_reg (regs, dsc, 0, rt_val, CANNOT_WRITE_PC); if (bytesize[opcode] == 8) @@ -5926,7 +5918,6 @@ copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn, unsigned int rn = bits (insn, 16, 19); unsigned int rm = bits (insn, 0, 3); /* Only valid if !immed. */ ULONGEST rt_val, rn_val, rm_val = 0; - CORE_ADDR from = dsc->insn_addr; if (!insn_references_pc (insn, 0x000ff00ful)) return copy_unmodified (gdbarch, insn, "load/store", dsc); @@ -5937,17 +5928,17 @@ copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn, : (byte ? "strb" : "str"), usermode ? "t" : "", (unsigned long) insn); - dsc->tmp[0] = displaced_read_reg (regs, from, 0); - dsc->tmp[2] = displaced_read_reg (regs, from, 2); + dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); + dsc->tmp[2] = displaced_read_reg (regs, dsc, 2); if (!immed) - dsc->tmp[3] = displaced_read_reg (regs, from, 3); + dsc->tmp[3] = displaced_read_reg (regs, dsc, 3); if (!load) - dsc->tmp[4] = displaced_read_reg (regs, from, 4); + dsc->tmp[4] = displaced_read_reg (regs, dsc, 4); - rt_val = displaced_read_reg (regs, from, rt); - rn_val = displaced_read_reg (regs, from, rn); + rt_val = displaced_read_reg (regs, dsc, rt); + rn_val = displaced_read_reg (regs, dsc, rn); if (!immed) - rm_val = displaced_read_reg (regs, from, rm); + rm_val = displaced_read_reg (regs, dsc, rm); displaced_write_reg (regs, dsc, 0, rt_val, CANNOT_WRITE_PC); displaced_write_reg (regs, dsc, 2, rn_val, CANNOT_WRITE_PC); @@ -6047,7 +6038,6 @@ static void cleanup_block_load_all (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST from = dsc->insn_addr; int inc = dsc->u.block.increment; int bump_before = dsc->u.block.before ? (inc ? 4 : -4) : 0; int bump_after = dsc->u.block.before ? 0 : (inc ? 4 : -4); @@ -6056,7 +6046,7 @@ cleanup_block_load_all (struct gdbarch *gdbarch, struct regcache *regs, CORE_ADDR xfer_addr = dsc->u.block.xfer_addr; int exception_return = dsc->u.block.load && dsc->u.block.user && (regmask & 0x8000) != 0; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM); int do_transfer = condition_true (dsc->u.block.cond, status); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); @@ -6109,8 +6099,7 @@ static void cleanup_block_store_pc (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM); int store_executed = condition_true (dsc->u.block.cond, status); CORE_ADDR pc_stored_at, transferred_regs = bitcount (dsc->u.block.regmask); CORE_ADDR stm_insn_addr; @@ -6161,8 +6150,7 @@ cleanup_block_load_pc (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - ULONGEST from = dsc->insn_addr; - uint32_t status = displaced_read_reg (regs, from, ARM_PS_REGNUM); + uint32_t status = displaced_read_reg (regs, dsc, ARM_PS_REGNUM); int load_executed = condition_true (dsc->u.block.cond, status), i; unsigned int mask = dsc->u.block.regmask, write_reg = ARM_PC_REGNUM; unsigned int regs_loaded = bitcount (mask); @@ -6185,7 +6173,7 @@ cleanup_block_load_pc (struct gdbarch *gdbarch, if (read_reg != write_reg) { - ULONGEST rval = displaced_read_reg (regs, from, read_reg); + ULONGEST rval = displaced_read_reg (regs, dsc, read_reg); displaced_write_reg (regs, dsc, write_reg, rval, LOAD_WRITE_PC); if (debug_displaced) fprintf_unfiltered (gdb_stdlog, _("displaced: LDM: move " @@ -6247,7 +6235,6 @@ copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, int before = bit (insn, 24); int writeback = bit (insn, 21); int rn = bits (insn, 16, 19); - CORE_ADDR from = dsc->insn_addr; /* Block transfers which don't mention PC can be run directly out-of-line. */ @@ -6265,7 +6252,7 @@ copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, fprintf_unfiltered (gdb_stdlog, "displaced: copying block transfer insn " "%.8lx\n", (unsigned long) insn); - dsc->u.block.xfer_addr = displaced_read_reg (regs, from, rn); + dsc->u.block.xfer_addr = displaced_read_reg (regs, dsc, rn); dsc->u.block.rn = rn; dsc->u.block.load = load; @@ -6301,7 +6288,7 @@ copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, unsigned int to = 0, from = 0, i, new_rn; for (i = 0; i < num_in_list; i++) - dsc->tmp[i] = displaced_read_reg (regs, from, i); + dsc->tmp[i] = displaced_read_reg (regs, dsc, i); /* Writeback makes things complicated. We need to avoid clobbering the base register with one of the registers in our modified @@ -6358,8 +6345,7 @@ static void cleanup_svc (struct gdbarch *gdbarch, struct regcache *regs, struct displaced_step_closure *dsc) { - CORE_ADDR from = dsc->insn_addr; - CORE_ADDR resume_addr = from + 4; + CORE_ADDR resume_addr = dsc->insn_addr + 4; if (debug_displaced) fprintf_unfiltered (gdb_stdlog, "displaced: cleanup for svc, resume at " @@ -6372,8 +6358,6 @@ static int copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to, struct regcache *regs, struct displaced_step_closure *dsc) { - CORE_ADDR from = dsc->insn_addr; - /* Allow OS-specific code to override SVC handling. */ if (dsc->u.svc.copy_svc_os) return dsc->u.svc.copy_svc_os (gdbarch, insn, to, regs, dsc); diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h index 362be2e..ebd5e6e 100644 --- a/gdb/arm-tdep.h +++ b/gdb/arm-tdep.h @@ -302,7 +302,8 @@ extern void arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct displaced_step_closure *dsc); extern ULONGEST - displaced_read_reg (struct regcache *regs, CORE_ADDR from, int regno); + displaced_read_reg (struct regcache *regs, struct displaced_step_closure *dsc, + int regno); extern void displaced_write_reg (struct regcache *regs, struct displaced_step_closure *dsc, int regno, ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch, arm] Use cached dsc->is_thumb instead of re-computing 2011-03-07 15:55 ` Yao Qi @ 2011-03-07 16:22 ` Ulrich Weigand 2011-03-08 4:33 ` Yao Qi 0 siblings, 1 reply; 7+ messages in thread From: Ulrich Weigand @ 2011-03-07 16:22 UTC (permalink / raw) To: Yao Qi; +Cc: gdb-patches Yao Qi wrote: > > added prototype declaration for displaced_read_reg is now unneeded again. > > I guess you mean "displaced_in_arm_mode" here. Removed its declaration. Yes, sorry, that's what I meant. > * arm-tdep.c: Remove prototype declaration displaced_in_arm_mode. > (displaced_read_reg): Add `dsc' parameter, remove `from' parameter. > Use cached result instead of calling displaced_in_arm_mode again. > (branch_write_pc, alu_write_pc, load_write_pc): Add `dsc' parameter. > (displaced_write_reg, copy_preload, copy_preload_reg): Callers update. > (cleanup_copro_load_store, copy_copro_load_store): Likewise. > (cleanup_branch, copy_bx_blx_reg, copy_alu_imm): Likewise. > (cleanup_alu_reg, copy_alu_reg, cleanup_alu_shifted_reg): Likewise. > (copy_alu_shifted_reg, cleanup_load, cleanup_store): Likewise. > (copy_extra_ld_st, copy_ldr_str_ldrb_strb): Likewise. > (cleanup_block_load_all, cleanup_block_store_pc): Likewise. > (cleanup_block_load_pc, copy_block_xfer): Likewise. > * arm-linux-tdep.c (arm_linux_copy_svc): Callers update. > (arm_catch_kernel_helper_return): Likewise. > * gdb/arm-tdep.h : Update function declarations. This is OK. Thanks, Ulrich -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch, arm] Use cached dsc->is_thumb instead of re-computing 2011-03-07 16:22 ` Ulrich Weigand @ 2011-03-08 4:33 ` Yao Qi 0 siblings, 0 replies; 7+ messages in thread From: Yao Qi @ 2011-03-08 4:33 UTC (permalink / raw) To: gdb-patches On 03/08/2011 12:04 AM, Ulrich Weigand wrote: > >> * arm-tdep.c: Remove prototype declaration displaced_in_arm_mode. >> (displaced_read_reg): Add `dsc' parameter, remove `from' parameter. >> Use cached result instead of calling displaced_in_arm_mode again. >> (branch_write_pc, alu_write_pc, load_write_pc): Add `dsc' parameter. >> (displaced_write_reg, copy_preload, copy_preload_reg): Callers update. >> (cleanup_copro_load_store, copy_copro_load_store): Likewise. >> (cleanup_branch, copy_bx_blx_reg, copy_alu_imm): Likewise. >> (cleanup_alu_reg, copy_alu_reg, cleanup_alu_shifted_reg): Likewise. >> (copy_alu_shifted_reg, cleanup_load, cleanup_store): Likewise. >> (copy_extra_ld_st, copy_ldr_str_ldrb_strb): Likewise. >> (cleanup_block_load_all, cleanup_block_store_pc): Likewise. >> (cleanup_block_load_pc, copy_block_xfer): Likewise. >> * arm-linux-tdep.c (arm_linux_copy_svc): Callers update. >> (arm_catch_kernel_helper_return): Likewise. >> * gdb/arm-tdep.h : Update function declarations. > > This is OK. Thanks. Applied. http://sourceware.org/ml/gdb-cvs/2011-03/msg00111.html -- Yao (é½å°§) ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-03-08 1:11 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-03-04 13:30 [patch, arm] Use cached dsc->is_thumb instead of re-computing Yao Qi 2011-03-04 14:08 ` Ulrich Weigand 2011-03-07 9:02 ` Yao Qi 2011-03-07 15:50 ` Ulrich Weigand 2011-03-07 15:55 ` Yao Qi 2011-03-07 16:22 ` Ulrich Weigand 2011-03-08 4:33 ` Yao Qi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox