diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2020-10-30 15:10:08 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2020-10-30 15:10:58 -0400 |
commit | 136821d9f6fdb7f457500d154166a1b4b41a0d1b (patch) | |
tree | 8204382983b0abf241cd990e5731ae9ac3225e83 /gdb | |
parent | aa2045e7fa41ea80a876421bca89443f7a2df92f (diff) | |
download | gdb-136821d9f6fdb7f457500d154166a1b4b41a0d1b.zip gdb-136821d9f6fdb7f457500d154166a1b4b41a0d1b.tar.gz gdb-136821d9f6fdb7f457500d154166a1b4b41a0d1b.tar.bz2 |
gdb: introduce displaced_debug_printf
Move all debug prints of the "displaced" category to use a new
displaced_debug_printf macro, like what was done for infrun and others
earlier.
The debug output for one displaced step one amd64 looks like:
[displaced] displaced_step_prepare_throw: stepping process 3367044 now
[displaced] displaced_step_prepare_throw: saved 0x555555555042: 1e fa 31 ed 49 89 d1 5e 48 89 e2 48 83 e4 f0 50
[displaced] amd64_displaced_step_copy_insn: copy 0x555555555131->0x555555555042: b8 00 00 00 00 5d c3 0f 1f 84 00 00 00 00 00 f3
[displaced] displaced_step_prepare_throw: displaced pc to 0x555555555042
[displaced] resume_1: run 0x555555555042: b8 00 00 00
[displaced] displaced_step_restore: restored process 3367044 0x555555555042
[displaced] amd64_displaced_step_fixup: fixup (0x555555555131, 0x555555555042), insn = 0xb8 0x00 ...
[displaced] amd64_displaced_step_fixup: relocated %rip from 0x555555555047 to 0x555555555136
On test case needed to be updated because it relied on the specific
formatting of the message.
gdb/ChangeLog:
* infrun.h (displaced_debug_printf): New macro. Replace
displaced debug prints throughout to use it.
(displaced_debug_printf_1): New declaration.
(displaced_step_dump_bytes): Return string, remove ui_file
parameter, update all callers.
* infrun.c (displaced_debug_printf_1): New function.
(displaced_step_dump_bytes): Return string, remove ui_file
parameter
gdb/testsuite/ChangeLog:
* gdb.arch/amd64-disp-step-avx.exp: Update displaced step debug
expected output.
Change-Id: Ie78837f56431f6f98378790ba1e6051337bf6533
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 11 | ||||
-rw-r--r-- | gdb/aarch64-tdep.c | 45 | ||||
-rw-r--r-- | gdb/amd64-tdep.c | 75 | ||||
-rw-r--r-- | gdb/arm-linux-tdep.c | 44 | ||||
-rw-r--r-- | gdb/arm-tdep.c | 339 | ||||
-rw-r--r-- | gdb/i386-tdep.c | 62 | ||||
-rw-r--r-- | gdb/infrun.c | 97 | ||||
-rw-r--r-- | gdb/infrun.h | 18 | ||||
-rw-r--r-- | gdb/rs6000-tdep.c | 41 | ||||
-rw-r--r-- | gdb/s390-tdep.c | 32 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp | 2 |
12 files changed, 311 insertions, 460 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 185d4a3..dce2e11 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2020-10-30 Simon Marchi <simon.marchi@efficios.com> + + * infrun.h (displaced_debug_printf): New macro. Replace + displaced debug prints throughout to use it. + (displaced_debug_printf_1): New declaration. + (displaced_step_dump_bytes): Return string, remove ui_file + parameter, update all callers. + * infrun.c (displaced_debug_printf_1): New function. + (displaced_step_dump_bytes): Return string, remove ui_file + parameter + 2020-10-30 Simon Marchi <simon.marchi@polymtl.ca> * rs6000-tdep.c (rs6000_dwarf2_reg_to_regnum): Return -1 for diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 639fe59..4c1d545 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -3177,12 +3177,10 @@ aarch64_displaced_step_copy_insn (struct gdbarch *gdbarch, relocated instruction(s) there. */ for (i = 0; i < dsd.insn_count; i++) { - if (debug_displaced) - { - debug_printf ("displaced: writing insn "); - debug_printf ("%.8x", dsd.insn_buf[i]); - debug_printf (" at %s\n", paddress (gdbarch, to + i * 4)); - } + displaced_debug_printf ("writing insn %.8x at %s", + dsd.insn_buf[i], + paddress (gdbarch, to + i * 4)); + write_memory_unsigned_integer (to + i * 4, 4, byte_order_for_code, (ULONGEST) dsd.insn_buf[i]); } @@ -3210,15 +3208,13 @@ aarch64_displaced_step_fixup (struct gdbarch *gdbarch, regcache_cooked_read_unsigned (regs, AARCH64_PC_REGNUM, &pc); - if (debug_displaced) - debug_printf ("Displaced: PC after stepping: %s (was %s).\n", - paddress (gdbarch, pc), paddress (gdbarch, to)); + displaced_debug_printf ("PC after stepping: %s (was %s).", + paddress (gdbarch, pc), paddress (gdbarch, to)); if (dsc->cond) { - if (debug_displaced) - debug_printf ("Displaced: [Conditional] pc_adjust before: %d\n", - dsc->pc_adjust); + displaced_debug_printf ("[Conditional] pc_adjust before: %d", + dsc->pc_adjust); if (pc - to == 8) { @@ -3232,16 +3228,13 @@ aarch64_displaced_step_fixup (struct gdbarch *gdbarch, else gdb_assert_not_reached ("Unexpected PC value after displaced stepping"); - if (debug_displaced) - debug_printf ("Displaced: [Conditional] pc_adjust after: %d\n", - dsc->pc_adjust); + displaced_debug_printf ("[Conditional] pc_adjust after: %d", + dsc->pc_adjust); } - if (debug_displaced) - debug_printf ("Displaced: %s PC by %d\n", - dsc->pc_adjust? "adjusting" : "not adjusting", - dsc->pc_adjust); - + displaced_debug_printf ("%s PC by %d", + dsc->pc_adjust ? "adjusting" : "not adjusting", + dsc->pc_adjust); if (dsc->pc_adjust != 0) { @@ -3251,17 +3244,13 @@ aarch64_displaced_step_fixup (struct gdbarch *gdbarch, took place. */ if ((pc - to) == 0) { - if (debug_displaced) - debug_printf ("Displaced: PC did not move. Discarding PC " - "adjustment.\n"); + displaced_debug_printf ("PC did not move. Discarding PC adjustment."); dsc->pc_adjust = 0; } - if (debug_displaced) - { - debug_printf ("Displaced: fixup: set PC to %s:%d\n", - paddress (gdbarch, from), dsc->pc_adjust); - } + displaced_debug_printf ("fixup: set PC to %s:%d", + paddress (gdbarch, from), dsc->pc_adjust); + regcache_cooked_write_unsigned (regs, AARCH64_PC_REGNUM, from + dsc->pc_adjust); } diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c index e801f83..57d57be 100644 --- a/gdb/amd64-tdep.c +++ b/gdb/amd64-tdep.c @@ -1438,11 +1438,10 @@ fixup_riprel (struct gdbarch *gdbarch, amd64_displaced_step_closure *dsc, regcache_cooked_write_unsigned (regs, tmp_regno, rip_base); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: %%rip-relative addressing used.\n" - "displaced: using temp reg %d, old value %s, new value %s\n", - dsc->tmp_regno, paddress (gdbarch, dsc->tmp_save), - paddress (gdbarch, rip_base)); + displaced_debug_printf ("%%rip-relative addressing used."); + displaced_debug_printf ("using temp reg %d, old value %s, new value %s", + dsc->tmp_regno, paddress (gdbarch, dsc->tmp_save), + paddress (gdbarch, rip_base)); } static void @@ -1504,12 +1503,9 @@ amd64_displaced_step_copy_insn (struct gdbarch *gdbarch, write_memory (to, buf, len); - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ", - paddress (gdbarch, from), paddress (gdbarch, to)); - displaced_step_dump_bytes (gdb_stdlog, buf, len); - } + displaced_debug_printf ("copy %s->%s: %s", + paddress (gdbarch, from), paddress (gdbarch, to), + displaced_step_dump_bytes (buf, len).c_str ()); /* This is a work around for a problem with g++ 4.8. */ return displaced_step_closure_up (dsc.release ()); @@ -1685,20 +1681,16 @@ amd64_displaced_step_fixup (struct gdbarch *gdbarch, gdb_byte *insn = dsc->insn_buf.data (); const struct amd64_insn *insn_details = &dsc->insn_details; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: fixup (%s, %s), " - "insn = 0x%02x 0x%02x ...\n", - paddress (gdbarch, from), paddress (gdbarch, to), - insn[0], insn[1]); + displaced_debug_printf ("fixup (%s, %s), insn = 0x%02x 0x%02x ...", + paddress (gdbarch, from), paddress (gdbarch, to), + insn[0], insn[1]); /* If we used a tmp reg, restore it. */ if (dsc->tmp_used) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: restoring reg %d to %s\n", - dsc->tmp_regno, paddress (gdbarch, dsc->tmp_save)); + displaced_debug_printf ("restoring reg %d to %s", + dsc->tmp_regno, paddress (gdbarch, dsc->tmp_save)); regcache_cooked_write_unsigned (regs, dsc->tmp_regno, dsc->tmp_save); } @@ -1743,12 +1735,7 @@ amd64_displaced_step_fixup (struct gdbarch *gdbarch, Presumably this is a kernel bug. Fixup ensures its a nop, we add one to the length for it. */ && orig_rip != to + insn_len + 1) - { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: syscall changed %%rip; " - "not relocating\n"); - } + displaced_debug_printf ("syscall changed %%rip; not relocating"); else { ULONGEST rip = orig_rip - insn_offset; @@ -1759,12 +1746,9 @@ amd64_displaced_step_fixup (struct gdbarch *gdbarch, regcache_cooked_write_unsigned (regs, AMD64_RIP_REGNUM, rip); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: " - "relocated %%rip from %s to %s\n", - paddress (gdbarch, orig_rip), - paddress (gdbarch, rip)); + displaced_debug_printf ("relocated %%rip from %s to %s", + paddress (gdbarch, orig_rip), + paddress (gdbarch, rip)); } } @@ -1787,12 +1771,9 @@ amd64_displaced_step_fixup (struct gdbarch *gdbarch, retaddr = (retaddr - insn_offset) & 0xffffffffffffffffULL; write_memory_unsigned_integer (rsp, retaddr_len, byte_order, retaddr); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: relocated return addr at %s " - "to %s\n", - paddress (gdbarch, rsp), - paddress (gdbarch, retaddr)); + displaced_debug_printf ("relocated return addr at %s to %s", + paddress (gdbarch, rsp), + paddress (gdbarch, retaddr)); } } @@ -1910,12 +1891,9 @@ amd64_relocate_instruction (struct gdbarch *gdbarch, newrel = (oldloc - *to) + rel32; store_signed_integer (insn + 1, 4, byte_order, newrel); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "Adjusted insn rel32=%s at %s to" - " rel32=%s at %s\n", - hex_string (rel32), paddress (gdbarch, oldloc), - hex_string (newrel), paddress (gdbarch, *to)); + displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s", + hex_string (rel32), paddress (gdbarch, oldloc), + hex_string (newrel), paddress (gdbarch, *to)); /* Write the adjusted jump into its displaced location. */ append_insns (to, 5, insn); @@ -1939,12 +1917,9 @@ amd64_relocate_instruction (struct gdbarch *gdbarch, rel32 = extract_signed_integer (insn + offset, 4, byte_order); newrel = (oldloc - *to) + rel32; store_signed_integer (insn + offset, 4, byte_order, newrel); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "Adjusted insn rel32=%s at %s to" - " rel32=%s at %s\n", - hex_string (rel32), paddress (gdbarch, oldloc), - hex_string (newrel), paddress (gdbarch, *to)); + displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s", + hex_string (rel32), paddress (gdbarch, oldloc), + hex_string (newrel), paddress (gdbarch, *to)); } /* Write the adjusted instruction into its displaced location. */ diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c index f60cb51..0435263 100644 --- a/gdb/arm-linux-tdep.c +++ b/gdb/arm-linux-tdep.c @@ -957,15 +957,11 @@ arm_linux_cleanup_svc (struct gdbarch *gdbarch, && apparent_pc < (dsc->scratch_base + ARM_DISPLACED_MODIFIED_INSNS * 4 + 4)); - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, "displaced: PC is apparently %.8lx after " - "SVC step ", (unsigned long) apparent_pc); - if (within_scratch) - fprintf_unfiltered (gdb_stdlog, "(within scratch space)\n"); - else - fprintf_unfiltered (gdb_stdlog, "(outside scratch space)\n"); - } + displaced_debug_printf ("PC is apparently %.8lx after SVC step %s", + (unsigned long) apparent_pc, + (within_scratch + ? "(within scratch space)" + : "(outside scratch space)")); if (within_scratch) displaced_write_reg (regs, dsc, ARM_PC_REGNUM, @@ -991,16 +987,12 @@ arm_linux_copy_svc (struct gdbarch *gdbarch, struct regcache *regs, { struct symtab_and_line sal; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: found " - "sigreturn/rt_sigreturn SVC call. PC in " - "frame = %lx\n", - (unsigned long) get_frame_pc (frame)); + displaced_debug_printf ("found sigreturn/rt_sigreturn SVC call. " + "PC in frame = %lx", + (unsigned long) get_frame_pc (frame)); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: unwind pc = %lx. " - "Setting momentary breakpoint.\n", - (unsigned long) return_to); + displaced_debug_printf ("unwind pc = %lx. Setting momentary breakpoint.", + (unsigned long) return_to); gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL); @@ -1025,13 +1017,12 @@ arm_linux_copy_svc (struct gdbarch *gdbarch, struct regcache *regs, breakpoint set above. */ insert_breakpoints (); } - else if (debug_displaced) - fprintf_unfiltered (gdb_stderr, "displaced: couldn't find previous " - "frame to set momentary breakpoint for " - "sigreturn/rt_sigreturn\n"); + else + displaced_debug_printf ("couldn't find previous frame to set momentary " + "breakpoint for sigreturn/rt_sigreturn"); } - else if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: found SVC call\n"); + else + displaced_debug_printf ("found SVC call"); /* Preparation: If we detect sigreturn, set momentary breakpoint at resume location, else nothing. @@ -1115,9 +1106,8 @@ arm_linux_displaced_step_copy_insn (struct gdbarch *gdbarch, stop at the return location. */ if (from > 0xffff0000) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: detected kernel helper " - "at %.8lx\n", (unsigned long) from); + displaced_debug_printf ("detected kernel helper at %.8lx", + (unsigned long) from); arm_catch_kernel_helper_return (gdbarch, from, to, regs, dsc.get ()); } diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index c007a38..10e26bc 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -418,11 +418,9 @@ arm_pc_is_thumb (struct gdbarch *gdbarch, CORE_ADDR memaddr) should be determined by instruction on the original address. */ if (dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: check mode of %.8lx instead of %.8lx\n", - (unsigned long) dsc->insn_addr, - (unsigned long) memaddr); + displaced_debug_printf ("check mode of %.8lx instead of %.8lx", + (unsigned long) dsc->insn_addr, + (unsigned long) memaddr); memaddr = dsc->insn_addr; } @@ -4457,17 +4455,17 @@ displaced_read_reg (struct regcache *regs, arm_displaced_step_closure *dsc, else from += 4; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: read pc value %.8lx\n", - (unsigned long) from); + displaced_debug_printf ("read pc value %.8lx", + (unsigned long) from); return (ULONGEST) from; } else { regcache_cooked_read_unsigned (regs, regno, &ret); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: read r%d value %.8lx\n", - regno, (unsigned long) ret); + + displaced_debug_printf ("read r%d value %.8lx", + regno, (unsigned long) ret); + return ret; } } @@ -4563,9 +4561,8 @@ displaced_write_reg (struct regcache *regs, arm_displaced_step_closure *dsc, { if (regno == ARM_PC_REGNUM) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: writing pc %.8lx\n", - (unsigned long) val); + displaced_debug_printf ("writing pc %.8lx", (unsigned long) val); + switch (write_pc) { case BRANCH_WRITE_PC: @@ -4598,9 +4595,8 @@ displaced_write_reg (struct regcache *regs, arm_displaced_step_closure *dsc, } else { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: writing r%d value %.8lx\n", - regno, (unsigned long) val); + displaced_debug_printf ("writing r%d value %.8lx", + regno, (unsigned long) val); regcache_cooked_write_unsigned (regs, regno, val); } } @@ -4644,10 +4640,8 @@ static int arm_copy_unmodified (struct gdbarch *gdbarch, uint32_t insn, const char *iname, arm_displaced_step_closure *dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.8lx, " - "opcode/class '%s' unmodified\n", (unsigned long) insn, - iname); + displaced_debug_printf ("copying insn %.8lx, opcode/class '%s' unmodified", + (unsigned long) insn, iname); dsc->modinsn[0] = insn; @@ -4659,10 +4653,8 @@ thumb_copy_unmodified_32bit (struct gdbarch *gdbarch, uint16_t insn1, uint16_t insn2, const char *iname, arm_displaced_step_closure *dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.4x %.4x, " - "opcode/class '%s' unmodified\n", insn1, insn2, - iname); + displaced_debug_printf ("copying insn %.4x %.4x, opcode/class '%s' " + "unmodified", insn1, insn2, iname); dsc->modinsn[0] = insn1; dsc->modinsn[1] = insn2; @@ -4678,10 +4670,8 @@ thumb_copy_unmodified_16bit (struct gdbarch *gdbarch, uint16_t insn, const char *iname, arm_displaced_step_closure *dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.4x, " - "opcode/class '%s' unmodified\n", insn, - iname); + displaced_debug_printf ("copying insn %.4x, opcode/class '%s' unmodified", + insn, iname); dsc->modinsn[0] = insn; @@ -4727,9 +4717,7 @@ arm_copy_preload (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, if (!insn_references_pc (insn, 0x000f0000ul)) return arm_copy_unmodified (gdbarch, insn, "preload", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying preload insn %.8lx\n", - (unsigned long) insn); + displaced_debug_printf ("copying preload insn %.8lx", (unsigned long) insn); dsc->modinsn[0] = insn & 0xfff0ffff; @@ -4752,11 +4740,9 @@ thumb2_copy_preload (struct gdbarch *gdbarch, uint16_t insn1, uint16_t insn2, /* PC is only allowed to use in PLI (immediate,literal) Encoding T3, and PLD (literal) Encoding T1. */ - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying pld/pli pc (0x%x) %c imm12 %.4x\n", - (unsigned int) dsc->insn_addr, u_bit ? '+' : '-', - imm12); + displaced_debug_printf ("copying pld/pli pc (0x%x) %c imm12 %.4x", + (unsigned int) dsc->insn_addr, u_bit ? '+' : '-', + imm12); if (!u_bit) imm12 = -1 * imm12; @@ -4824,9 +4810,8 @@ arm_copy_preload_reg (struct gdbarch *gdbarch, uint32_t insn, if (!insn_references_pc (insn, 0x000f000ful)) return arm_copy_unmodified (gdbarch, insn, "preload reg", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying preload insn %.8lx\n", - (unsigned long) insn); + displaced_debug_printf ("copying preload insn %.8lx", + (unsigned long) insn); dsc->modinsn[0] = (insn & 0xfff0fff0) | 0x1; @@ -4886,9 +4871,8 @@ arm_copy_copro_load_store (struct gdbarch *gdbarch, uint32_t insn, if (!insn_references_pc (insn, 0x000f0000ul)) return arm_copy_unmodified (gdbarch, insn, "copro load/store", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying coprocessor " - "load/store insn %.8lx\n", (unsigned long) insn); + displaced_debug_printf ("copying coprocessor load/store insn %.8lx", + (unsigned long) insn); dsc->modinsn[0] = insn & 0xfff0ffff; @@ -4908,9 +4892,8 @@ thumb2_copy_copro_load_store (struct gdbarch *gdbarch, uint16_t insn1, return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2, "copro load/store", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying coprocessor " - "load/store insn %.4x%.4x\n", insn1, insn2); + displaced_debug_printf ("copying coprocessor load/store insn %.4x%.4x", + insn1, insn2); dsc->modinsn[0] = insn1 & 0xfff0; dsc->modinsn[1] = insn2; @@ -4995,10 +4978,9 @@ arm_copy_b_bl_blx (struct gdbarch *gdbarch, uint32_t insn, int link = exchange || bit (insn, 24); long offset; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying %s immediate insn " - "%.8lx\n", (exchange) ? "blx" : (link) ? "bl" : "b", - (unsigned long) insn); + displaced_debug_printf ("copying %s immediate insn %.8lx", + (exchange) ? "blx" : (link) ? "bl" : "b", + (unsigned long) insn); if (exchange) /* For BLX, set bit 0 of the destination. The cleanup_branch function will then arrange the switch into Thumb mode. */ @@ -5058,11 +5040,9 @@ thumb2_copy_b_bl_blx (struct gdbarch *gdbarch, uint16_t insn1, (bits (insn2, 1, 10) << 2) : (bits (insn2, 0, 10) << 1); } - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying %s insn " - "%.4x %.4x with offset %.8lx\n", - link ? (exchange) ? "blx" : "bl" : "b", - insn1, insn2, offset); + displaced_debug_printf ("copying %s insn %.4x %.4x with offset %.8lx", + link ? (exchange) ? "blx" : "bl" : "b", + insn1, insn2, offset); dsc->modinsn[0] = THUMB_NOP; @@ -5092,10 +5072,8 @@ thumb_copy_b (struct gdbarch *gdbarch, uint16_t insn, cond = INST_AL; } - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying b immediate insn %.4x " - "with offset %d\n", insn, offset); + displaced_debug_printf ("copying b immediate insn %.4x with offset %d", + insn, offset); dsc->u.branch.cond = cond; dsc->u.branch.link = 0; @@ -5144,9 +5122,7 @@ arm_copy_bx_blx_reg (struct gdbarch *gdbarch, uint32_t insn, int link = bit (insn, 5); unsigned int rm = bits (insn, 0, 3); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.8lx", - (unsigned long) insn); + displaced_debug_printf ("copying insn %.8lx", (unsigned long) insn); dsc->modinsn[0] = ARM_NOP; @@ -5162,9 +5138,7 @@ thumb_copy_bx_blx_reg (struct gdbarch *gdbarch, uint16_t insn, int link = bit (insn, 7); unsigned int rm = bits (insn, 3, 6); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying insn %.4x", - (unsigned short) insn); + displaced_debug_printf ("copying insn %.4x", (unsigned short) insn); dsc->modinsn[0] = THUMB_NOP; @@ -5199,10 +5173,9 @@ arm_copy_alu_imm (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, if (!insn_references_pc (insn, 0x000ff000ul)) return arm_copy_unmodified (gdbarch, insn, "ALU immediate", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying immediate %s insn " - "%.8lx\n", is_mov ? "move" : "ALU", - (unsigned long) insn); + displaced_debug_printf ("copying immediate %s insn %.8lx", + is_mov ? "move" : "ALU", + (unsigned long) insn); /* Instruction is of form: @@ -5253,9 +5226,7 @@ thumb2_copy_alu_imm (struct gdbarch *gdbarch, uint16_t insn1, if (rm != ARM_PC_REGNUM && rd != ARM_PC_REGNUM) return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2, "ALU imm", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying reg %s insn %.4x%.4x\n", - "ALU", insn1, insn2); + displaced_debug_printf ("copying reg %s insn %.4x%.4x", "ALU", insn1, insn2); /* Instruction is of form: @@ -5346,9 +5317,8 @@ arm_copy_alu_reg (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, if (!insn_references_pc (insn, 0x000ff00ful)) return arm_copy_unmodified (gdbarch, insn, "ALU reg", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying reg %s insn %.8lx\n", - is_mov ? "move" : "ALU", (unsigned long) insn); + displaced_debug_printf ("copying reg %s insn %.8lx", + is_mov ? "move" : "ALU", (unsigned long) insn); if (is_mov) dsc->modinsn[0] = (insn & 0xfff00ff0) | 0x2; @@ -5373,9 +5343,7 @@ thumb_copy_alu_reg (struct gdbarch *gdbarch, uint16_t insn, if (rd != ARM_PC_REGNUM && rm != ARM_PC_REGNUM) return thumb_copy_unmodified_16bit (gdbarch, insn, "ALU reg", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying ALU reg insn %.4x\n", - (unsigned short) insn); + displaced_debug_printf ("copying ALU reg insn %.4x", (unsigned short) insn); dsc->modinsn[0] = ((insn & 0xff00) | 0x10); @@ -5450,10 +5418,9 @@ arm_copy_alu_shifted_reg (struct gdbarch *gdbarch, uint32_t insn, if (!insn_references_pc (insn, 0x000fff0ful)) return arm_copy_unmodified (gdbarch, insn, "ALU shifted reg", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying shifted reg %s insn " - "%.8lx\n", is_mov ? "move" : "ALU", - (unsigned long) insn); + displaced_debug_printf ("copying shifted reg %s insn %.8lx", + is_mov ? "move" : "ALU", + (unsigned long) insn); rn = bits (insn, 16, 19); rm = bits (insn, 0, 3); @@ -5542,10 +5509,9 @@ arm_copy_extra_ld_st (struct gdbarch *gdbarch, uint32_t insn, int unprivileged, if (!insn_references_pc (insn, 0x000ff00ful)) return arm_copy_unmodified (gdbarch, insn, "extra load/store", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying %sextra load/store " - "insn %.8lx\n", unprivileged ? "unprivileged " : "", - (unsigned long) insn); + displaced_debug_printf ("copying %sextra load/store insn %.8lx", + unprivileged ? "unprivileged " : "", + (unsigned long) insn); opcode = ((op2 << 2) | (op1 & 0x1) | ((op1 & 0x4) >> 1)) - 4; @@ -5663,11 +5629,9 @@ thumb2_copy_load_literal (struct gdbarch *gdbarch, uint16_t insn1, int imm12 = bits (insn2, 0, 11); ULONGEST pc_val; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying ldr pc (0x%x) R%d %c imm12 %.4x\n", - (unsigned int) dsc->insn_addr, rt, u_bit ? '+' : '-', - imm12); + displaced_debug_printf ("copying ldr pc (0x%x) R%d %c imm12 %.4x", + (unsigned int) dsc->insn_addr, rt, u_bit ? '+' : '-', + imm12); if (!u_bit) imm12 = -1 * imm12; @@ -5725,10 +5689,8 @@ thumb2_copy_load_reg_imm (struct gdbarch *gdbarch, uint16_t insn1, return thumb_copy_unmodified_32bit (gdbarch, insn1, insn2, "load", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying ldr r%d [r%d] insn %.4x%.4x\n", - rt, rn, insn1, insn2); + displaced_debug_printf ("copying ldr r%d [r%d] insn %.4x%.4x", + rt, rn, insn1, insn2); install_load_store (gdbarch, regs, dsc, 1, immed, writeback, 4, 0, rt, rm, rn); @@ -5773,13 +5735,12 @@ arm_copy_ldr_str_ldrb_strb (struct gdbarch *gdbarch, uint32_t insn, if (!insn_references_pc (insn, 0x000ff00ful)) return arm_copy_unmodified (gdbarch, insn, "load/store", dsc); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying %s%s r%d [r%d] insn %.8lx\n", - load ? (size == 1 ? "ldrb" : "ldr") - : (size == 1 ? "strb" : "str"), usermode ? "t" : "", - rt, rn, - (unsigned long) insn); + displaced_debug_printf ("copying %s%s r%d [r%d] insn %.8lx", + load ? (size == 1 ? "ldrb" : "ldr") + : (size == 1 ? "strb" : "str"), + usermode ? "t" : "", + rt, rn, + (unsigned long) insn); install_load_store (gdbarch, regs, dsc, load, immed, writeback, size, usermode, rt, rm, rn); @@ -5870,11 +5831,10 @@ cleanup_block_load_all (struct gdbarch *gdbarch, struct regcache *regs, /* We don't handle any stores here for now. */ gdb_assert (dsc->u.block.load != 0); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: emulating block transfer: " - "%s %s %s\n", dsc->u.block.load ? "ldm" : "stm", - dsc->u.block.increment ? "inc" : "dec", - dsc->u.block.before ? "before" : "after"); + displaced_debug_printf ("emulating block transfer: %s %s %s", + dsc->u.block.load ? "ldm" : "stm", + dsc->u.block.increment ? "inc" : "dec", + dsc->u.block.before ? "before" : "after"); while (regmask) { @@ -5940,9 +5900,8 @@ cleanup_block_store_pc (struct gdbarch *gdbarch, struct regcache *regs, stm_insn_addr = dsc->scratch_base; offset = pc_val - stm_insn_addr; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: detected PC offset %.8lx for " - "STM instruction\n", offset); + displaced_debug_printf ("detected PC offset %.8lx for STM instruction", + offset); /* Rewrite the stored PC to the proper value for the non-displaced original instruction. */ @@ -5985,15 +5944,12 @@ cleanup_block_load_pc (struct gdbarch *gdbarch, { 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 " - "loaded register r%d to r%d\n"), read_reg, - write_reg); + displaced_debug_printf ("LDM: move loaded register r%d to r%d", + read_reg, write_reg); } - else if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, _("displaced: LDM: register " - "r%d already in the right place\n"), - write_reg); + else + displaced_debug_printf ("LDM: register r%d already in the right " + "place", write_reg); clobbered &= ~(1 << write_reg); @@ -6010,9 +5966,8 @@ cleanup_block_load_pc (struct gdbarch *gdbarch, { displaced_write_reg (regs, dsc, write_reg, dsc->tmp[write_reg], CANNOT_WRITE_PC); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, _("displaced: LDM: restored " - "clobbered register r%d\n"), write_reg); + displaced_debug_printf ("LDM: restored clobbered register r%d", + write_reg); clobbered &= ~(1 << write_reg); } } @@ -6059,9 +6014,8 @@ arm_copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, return arm_copy_unmodified (gdbarch, insn, "unpredictable ldm/stm", dsc); } - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying block transfer insn " - "%.8lx\n", (unsigned long) insn); + displaced_debug_printf ("copying block transfer insn %.8lx", + (unsigned long) insn); dsc->u.block.xfer_addr = displaced_read_reg (regs, dsc, rn); dsc->u.block.rn = rn; @@ -6122,11 +6076,10 @@ arm_copy_block_xfer (struct gdbarch *gdbarch, uint32_t insn, new_regmask = (1 << num_in_list) - 1; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, _("displaced: LDM r%d%s, " - "{..., pc}: original reg list %.4x, modified " - "list %.4x\n"), rn, writeback ? "!" : "", - (int) insn & 0xffff, new_regmask); + displaced_debug_printf ("LDM r%d%s, {..., pc}: original reg list " + "%.4x, modified list %.4x", + rn, writeback ? "!" : "", + (int) insn & 0xffff, new_regmask); dsc->modinsn[0] = (insn & ~0xffff) | (new_regmask & 0xffff); @@ -6171,9 +6124,8 @@ thumb2_copy_block_xfer (struct gdbarch *gdbarch, uint16_t insn1, uint16_t insn2, "unpredictable ldm/stm", dsc); } - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying block transfer insn " - "%.4x%.4x\n", insn1, insn2); + displaced_debug_printf ("copying block transfer insn %.4x%.4x", + insn1, insn2); /* Clear bit 13, since it should be always zero. */ dsc->u.block.regmask = (insn2 & 0xdfff); @@ -6208,11 +6160,10 @@ thumb2_copy_block_xfer (struct gdbarch *gdbarch, uint16_t insn1, uint16_t insn2, new_regmask = (1 << num_in_list) - 1; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, _("displaced: LDM r%d%s, " - "{..., pc}: original reg list %.4x, modified " - "list %.4x\n"), rn, writeback ? "!" : "", - (int) dsc->u.block.regmask, new_regmask); + displaced_debug_printf ("LDM r%d%s, {..., pc}: original reg list " + "%.4x, modified list %.4x", + rn, writeback ? "!" : "", + (int) dsc->u.block.regmask, new_regmask); dsc->modinsn[0] = insn1; dsc->modinsn[1] = (new_regmask & 0xffff); @@ -6302,9 +6253,8 @@ cleanup_svc (struct gdbarch *gdbarch, struct regcache *regs, { CORE_ADDR resume_addr = dsc->insn_addr + dsc->insn_size; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: cleanup for svc, resume at " - "%.8lx\n", (unsigned long) resume_addr); + displaced_debug_printf ("cleanup for svc, resume at %.8lx", + (unsigned long) resume_addr); displaced_write_reg (regs, dsc, ARM_PC_REGNUM, resume_addr, BRANCH_WRITE_PC); } @@ -6339,9 +6289,8 @@ arm_copy_svc (struct gdbarch *gdbarch, uint32_t insn, struct regcache *regs, arm_displaced_step_closure *dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying svc insn %.8lx\n", - (unsigned long) insn); + displaced_debug_printf ("copying svc insn %.8lx", + (unsigned long) insn); dsc->modinsn[0] = insn; @@ -6353,9 +6302,7 @@ thumb_copy_svc (struct gdbarch *gdbarch, uint16_t insn, struct regcache *regs, arm_displaced_step_closure *dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying svc insn %.4x\n", - insn); + displaced_debug_printf ("copying svc insn %.4x", insn); dsc->modinsn[0] = insn; @@ -6368,10 +6315,8 @@ static int arm_copy_undef (struct gdbarch *gdbarch, uint32_t insn, arm_displaced_step_closure *dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying undefined insn %.8lx\n", - (unsigned long) insn); + displaced_debug_printf ("copying undefined insn %.8lx", + (unsigned long) insn); dsc->modinsn[0] = insn; @@ -6383,10 +6328,8 @@ thumb_32bit_copy_undef (struct gdbarch *gdbarch, uint16_t insn1, uint16_t insn2, arm_displaced_step_closure *dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying undefined insn " - "%.4x %.4x\n", (unsigned short) insn1, - (unsigned short) insn2); + displaced_debug_printf ("copying undefined insn %.4x %.4x", + (unsigned short) insn1, (unsigned short) insn2); dsc->modinsn[0] = insn1; dsc->modinsn[1] = insn2; @@ -6401,9 +6344,8 @@ static int arm_copy_unpred (struct gdbarch *gdbarch, uint32_t insn, arm_displaced_step_closure *dsc) { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying unpredictable insn " - "%.8lx\n", (unsigned long) insn); + displaced_debug_printf ("copying unpredictable insn %.8lx", + (unsigned long) insn); dsc->modinsn[0] = insn; @@ -6975,10 +6917,8 @@ thumb_decode_pc_relative_16bit (struct gdbarch *gdbarch, uint16_t insn, unsigned int rd = bits (insn, 8, 10); unsigned int imm8 = bits (insn, 0, 7); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying thumb adr r%d, #%d insn %.4x\n", - rd, imm8, insn); + displaced_debug_printf ("copying thumb adr r%d, #%d insn %.4x", + rd, imm8, insn); return thumb_copy_pc_relative_16bit (gdbarch, regs, dsc, rd, imm8); } @@ -6996,10 +6936,8 @@ thumb_copy_pc_relative_32bit (struct gdbarch *gdbarch, uint16_t insn1, unsigned int imm_3_8 = insn2 & 0x70ff; unsigned int imm_i = insn1 & 0x0400; /* Clear all bits except bit 10. */ - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying thumb adr r%d, #%d:%d insn %.4x%.4x\n", - rd, imm_i, imm_3_8, insn1, insn2); + displaced_debug_printf ("copying thumb adr r%d, #%d:%d insn %.4x%.4x", + rd, imm_i, imm_3_8, insn1, insn2); if (bit (insn1, 7)) /* Encoding T2 */ { @@ -7038,10 +6976,7 @@ thumb_copy_16bit_ldr_literal (struct gdbarch *gdbarch, uint16_t insn1, Insn: LDR R0, [R2, R3]; Cleanup: R2 <- tmp2, R3 <- tmp3, Rd <- R0, R0 <- tmp0 */ - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying thumb ldr r%d [pc #%d]\n" - , rt, imm8); + displaced_debug_printf ("copying thumb ldr r%d [pc #%d]", rt, imm8); dsc->tmp[0] = displaced_read_reg (regs, dsc, 0); dsc->tmp[2] = displaced_read_reg (regs, dsc, 2); @@ -7096,10 +7031,9 @@ thumb_copy_cbnz_cbz (struct gdbarch *gdbarch, uint16_t insn1, dsc->u.branch.link = 0; dsc->u.branch.exchange = 0; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copying %s [r%d = 0x%x]" - " insn %.4x to %.8lx\n", non_zero ? "cbnz" : "cbz", - rn, rn_val, insn1, dsc->u.branch.dest); + displaced_debug_printf ("copying %s [r%d = 0x%x] insn %.4x to %.8lx", + non_zero ? "cbnz" : "cbz", + rn, rn_val, insn1, dsc->u.branch.dest); dsc->modinsn[0] = THUMB_NOP; @@ -7136,11 +7070,10 @@ thumb2_copy_table_branch (struct gdbarch *gdbarch, uint16_t insn1, halfwords = extract_unsigned_integer (buf, 1, byte_order); } - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: %s base 0x%x offset 0x%x" - " offset 0x%x\n", is_tbh ? "tbh" : "tbb", - (unsigned int) rn_val, (unsigned int) rm_val, - (unsigned int) halfwords); + displaced_debug_printf ("%s base 0x%x offset 0x%x offset 0x%x", + is_tbh ? "tbh" : "tbb", + (unsigned int) rn_val, (unsigned int) rm_val, + (unsigned int) halfwords); dsc->u.branch.cond = INST_AL; dsc->u.branch.link = 0; @@ -7197,10 +7130,8 @@ thumb_copy_pop_pc_16bit (struct gdbarch *gdbarch, uint16_t insn1, Cleanup: Set registers in original reglist from r0 - rN. Restore r0 - rN from tmp[] properly. */ - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: copying thumb pop {%.8x, pc} insn %.4x\n", - dsc->u.block.regmask, insn1); + displaced_debug_printf ("copying thumb pop {%.8x, pc} insn %.4x", + dsc->u.block.regmask, insn1); if (dsc->u.block.regmask == 0xff) { @@ -7224,11 +7155,9 @@ thumb_copy_pop_pc_16bit (struct gdbarch *gdbarch, uint16_t insn1, new_regmask = (1 << (num_in_list + 1)) - 1; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, _("displaced: POP " - "{..., pc}: original reg list %.4x," - " modified list %.4x\n"), - (int) dsc->u.block.regmask, new_regmask); + displaced_debug_printf ("POP {..., pc}: original reg list %.4x, " + "modified list %.4x", + (int) dsc->u.block.regmask, new_regmask); dsc->u.block.regmask |= 0x8000; dsc->u.block.writeback = 0; @@ -7562,9 +7491,8 @@ thumb_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from, uint16_t insn1 = read_memory_unsigned_integer (from, 2, byte_order_for_code); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: process thumb insn %.4x " - "at %.8lx\n", insn1, (unsigned long) from); + displaced_debug_printf ("process thumb insn %.4x at %.8lx", + insn1, (unsigned long) from); dsc->is_thumb = 1; dsc->insn_size = thumb_insn_size (insn1); @@ -7601,10 +7529,8 @@ arm_process_displaced_insn (struct gdbarch *gdbarch, CORE_ADDR from, dsc->is_thumb = 0; dsc->insn_size = 4; insn = read_memory_unsigned_integer (from, 4, byte_order_for_code); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: stepping insn %.8lx " - "at %.8lx\n", (unsigned long) insn, - (unsigned long) from); + displaced_debug_printf ("stepping insn %.8lx at %.8lx", + (unsigned long) insn, (unsigned long) from); if ((insn & 0xf0000000) == 0xf0000000) err = arm_decode_unconditional (gdbarch, insn, regs, dsc); @@ -7652,20 +7578,14 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from, /* Poke modified instruction(s). */ for (i = 0; i < dsc->numinsns; i++) { - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, "displaced: writing insn "); - if (size == 4) - fprintf_unfiltered (gdb_stdlog, "%.8lx", - dsc->modinsn[i]); - else if (size == 2) - fprintf_unfiltered (gdb_stdlog, "%.4x", - (unsigned short)dsc->modinsn[i]); - - fprintf_unfiltered (gdb_stdlog, " at %.8lx\n", - (unsigned long) to + offset); + if (size == 4) + displaced_debug_printf ("writing insn %.8lx at %.8lx", + dsc->modinsn[i], (unsigned long) to + offset); + else if (size == 2) + displaced_debug_printf ("writing insn %.4x at %.8lx", + (unsigned short) dsc->modinsn[i], + (unsigned long) to + offset); - } write_memory_unsigned_integer (to + offset, size, byte_order_for_code, dsc->modinsn[i]); @@ -7687,9 +7607,8 @@ arm_displaced_init_closure (struct gdbarch *gdbarch, CORE_ADDR from, /* Put breakpoint afterwards. */ write_memory (to + offset, bkp_insn, len); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ", - paddress (gdbarch, from), paddress (gdbarch, to)); + displaced_debug_printf ("copy %s->%s", paddress (gdbarch, from), + paddress (gdbarch, to)); } /* Entry point for cleaning things up after a displaced instruction has been diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index b485f0b..e680e98 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -825,12 +825,9 @@ i386_displaced_step_copy_insn (struct gdbarch *gdbarch, write_memory (to, buf, len); - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ", - paddress (gdbarch, from), paddress (gdbarch, to)); - displaced_step_dump_bytes (gdb_stdlog, buf, len); - } + displaced_debug_printf ("%s->%s: %s", + paddress (gdbarch, from), paddress (gdbarch, to), + displaced_step_dump_bytes (buf, len).c_str ()); /* This is a work around for a problem with g++ 4.8. */ return displaced_step_closure_up (closure.release ()); @@ -859,12 +856,9 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch, /* The start of the insn, needed in case we see some prefixes. */ gdb_byte *insn_start = insn; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: fixup (%s, %s), " - "insn = 0x%02x 0x%02x ...\n", - paddress (gdbarch, from), paddress (gdbarch, to), - insn[0], insn[1]); + displaced_debug_printf ("fixup (%s, %s), insn = 0x%02x 0x%02x ...", + paddress (gdbarch, from), paddress (gdbarch, to), + insn[0], insn[1]); /* The list of issues to contend with here is taken from resume_execution in arch/i386/kernel/kprobes.c, Linux 2.6.20. @@ -918,13 +912,8 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch, Presumably this is a kernel bug. i386_displaced_step_copy_insn ensures its a nop, we add one to the length for it. */ - && orig_eip != to + (insn - insn_start) + insn_len + 1) - { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: syscall changed %%eip; " - "not relocating\n"); - } + && orig_eip != to + (insn - insn_start) + insn_len + 1) + displaced_debug_printf ("syscall changed %%eip; not relocating"); else { ULONGEST eip = (orig_eip - insn_offset) & 0xffffffffUL; @@ -935,12 +924,9 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch, regcache_cooked_write_unsigned (regs, I386_EIP_REGNUM, eip); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: " - "relocated %%eip from %s to %s\n", - paddress (gdbarch, orig_eip), - paddress (gdbarch, eip)); + displaced_debug_printf ("relocated %%eip from %s to %s", + paddress (gdbarch, orig_eip), + paddress (gdbarch, eip)); } } @@ -963,11 +949,9 @@ i386_displaced_step_fixup (struct gdbarch *gdbarch, retaddr = (retaddr - insn_offset) & 0xffffffffUL; write_memory_unsigned_integer (esp, retaddr_len, byte_order, retaddr); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: relocated return addr at %s to %s\n", - paddress (gdbarch, esp), - paddress (gdbarch, retaddr)); + displaced_debug_printf ("relocated return addr at %s to %s", + paddress (gdbarch, esp), + paddress (gdbarch, retaddr)); } } @@ -1019,12 +1003,9 @@ i386_relocate_instruction (struct gdbarch *gdbarch, newrel = (oldloc - *to) + rel32; store_signed_integer (insn + 1, 4, byte_order, newrel); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "Adjusted insn rel32=%s at %s to" - " rel32=%s at %s\n", - hex_string (rel32), paddress (gdbarch, oldloc), - hex_string (newrel), paddress (gdbarch, *to)); + displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s", + hex_string (rel32), paddress (gdbarch, oldloc), + hex_string (newrel), paddress (gdbarch, *to)); /* Write the adjusted jump into its displaced location. */ append_insns (to, 5, insn); @@ -1044,12 +1025,9 @@ i386_relocate_instruction (struct gdbarch *gdbarch, rel32 = extract_signed_integer (insn + offset, 4, byte_order); newrel = (oldloc - *to) + rel32; store_signed_integer (insn + offset, 4, byte_order, newrel); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "Adjusted insn rel32=%s at %s to" - " rel32=%s at %s\n", - hex_string (rel32), paddress (gdbarch, oldloc), - hex_string (newrel), paddress (gdbarch, *to)); + displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s", + hex_string (rel32), paddress (gdbarch, oldloc), + hex_string (newrel), paddress (gdbarch, *to)); } /* Write the adjusted instructions into their displaced diff --git a/gdb/infrun.c b/gdb/infrun.c index 19031a0..de2437f 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -179,6 +179,16 @@ show_debug_infrun (struct ui_file *file, int from_tty, fprintf_filtered (file, _("Inferior debugging is %s.\n"), value); } +/* See infrun.h. */ + +void +displaced_debug_printf_1 (const char *func_name, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + debug_prefixed_vprintf ("displaced", func_name, fmt, ap); + va_end (ap); +} /* Support for disabling address space randomization. */ @@ -1629,17 +1639,22 @@ displaced_step_reset (displaced_step_inferior_state *displaced) using displaced_step_reset_cleanup = FORWARD_SCOPE_EXIT (displaced_step_reset); -/* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ -void -displaced_step_dump_bytes (struct ui_file *file, - const gdb_byte *buf, - size_t len) +/* See infrun.h. */ + +std::string +displaced_step_dump_bytes (const gdb_byte *buf, size_t len) { - int i; + std::string ret; - for (i = 0; i < len; i++) - fprintf_unfiltered (file, "%02x ", buf[i]); - fputs_unfiltered ("\n", file); + for (size_t i = 0; i < len; i++) + { + if (i == 0) + ret += string_printf ("%02x", buf[i]); + else + ret += string_printf (" %02x", buf[i]); + } + + return ret; } /* Prepare to single-step, using displaced stepping. @@ -1692,21 +1707,15 @@ displaced_step_prepare_throw (thread_info *tp) /* Already waiting for a displaced step to finish. Defer this request and place in queue. */ - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: deferring step of %s\n", - target_pid_to_str (tp->ptid).c_str ()); + displaced_debug_printf ("deferring step of %s", + target_pid_to_str (tp->ptid).c_str ()); thread_step_over_chain_enqueue (tp); return 0; } else - { - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: stepping %s now\n", + displaced_debug_printf ("stepping %s now", target_pid_to_str (tp->ptid).c_str ()); - } displaced_step_reset (displaced); @@ -1730,12 +1739,8 @@ displaced_step_prepare_throw (thread_info *tp) in the scratch pad range (after initial startup) anyway, but the former is unacceptable. Simply punt and fallback to stepping over this breakpoint in-line. */ - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, - "displaced: breakpoint set in scratch pad. " - "Stepping over breakpoint in-line instead.\n"); - } + displaced_debug_printf ("breakpoint set in scratch pad. " + "Stepping over breakpoint in-line instead."); return -1; } @@ -1748,14 +1753,11 @@ displaced_step_prepare_throw (thread_info *tp) _("Error accessing memory address %s (%s) for " "displaced-stepping scratch space."), paddress (gdbarch, copy), safe_strerror (status)); - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ", - paddress (gdbarch, copy)); - displaced_step_dump_bytes (gdb_stdlog, - displaced->step_saved_copy.data (), - len); - }; + + displaced_debug_printf ("saved %s: %s", + paddress (gdbarch, copy), + displaced_step_dump_bytes + (displaced->step_saved_copy.data (), len).c_str ()); displaced->step_closure = gdbarch_displaced_step_copy_insn (gdbarch, original, copy, regcache); @@ -1783,9 +1785,7 @@ displaced_step_prepare_throw (thread_info *tp) cleanup.release (); } - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n", - paddress (gdbarch, copy)); + displaced_debug_printf ("displaced pc to %s", paddress (gdbarch, copy)); return 1; } @@ -1850,11 +1850,11 @@ displaced_step_restore (struct displaced_step_inferior_state *displaced, write_memory_ptid (ptid, displaced->step_copy, displaced->step_saved_copy.data (), len); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n", - target_pid_to_str (ptid).c_str (), - paddress (displaced->step_gdbarch, - displaced->step_copy)); + + displaced_debug_printf ("restored %s %s", + target_pid_to_str (ptid).c_str (), + paddress (displaced->step_gdbarch, + displaced->step_copy)); } /* If we displaced stepped an instruction successfully, adjust @@ -2593,10 +2593,11 @@ resume_1 (enum gdb_signal sig) CORE_ADDR actual_pc = regcache_read_pc (resume_regcache); gdb_byte buf[4]; - fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", - paddress (resume_gdbarch, actual_pc)); read_memory (actual_pc, buf, sizeof (buf)); - displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); + displaced_debug_printf ("run %s: %s", + paddress (resume_gdbarch, actual_pc), + displaced_step_dump_bytes + (buf, sizeof (buf)).c_str ()); } if (tp->control.may_range_step) @@ -5354,12 +5355,10 @@ handle_inferior_event (struct execution_control_state *ecs) /* Read PC value of parent process. */ parent_pc = regcache_read_pc (regcache); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: write child pc from %s to %s\n", - paddress (gdbarch, - regcache_read_pc (child_regcache)), - paddress (gdbarch, parent_pc)); + displaced_debug_printf ("write child pc from %s to %s", + paddress (gdbarch, + regcache_read_pc (child_regcache)), + paddress (gdbarch, parent_pc)); regcache_write_pc (child_regcache, parent_pc); } diff --git a/gdb/infrun.h b/gdb/infrun.h index d0dca67..4fc1bf9 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -47,6 +47,19 @@ void ATTRIBUTE_PRINTF (2, 3) infrun_debug_printf_1 /* True if we are debugging displaced stepping. */ extern bool debug_displaced; +/* Print a "displaced" debug statement. Should be used through + displaced_debug_printf. */ +void ATTRIBUTE_PRINTF (2, 3) displaced_debug_printf_1 + (const char *func_name, const char *fmt, ...); + +#define displaced_debug_printf(fmt, ...) \ + do \ + { \ + if (debug_displaced) \ + displaced_debug_printf_1 (__func__, fmt, ##__VA_ARGS__); \ + } \ + while (0) + /* Nonzero if we want to give control to the user when we're notified of shared library events by the dynamic linker. */ extern int stop_on_solib_events; @@ -229,9 +242,8 @@ extern void update_signals_program_target (void); $_exitsignal. */ extern void clear_exit_convenience_vars (void); -/* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ -extern void displaced_step_dump_bytes (struct ui_file *file, - const gdb_byte *buf, size_t len); +/* Dump LEN bytes at BUF in hex to a string and return it. */ +extern std::string displaced_step_dump_bytes (const gdb_byte *buf, size_t len); extern struct displaced_step_closure *get_displaced_step_closure_by_addr (CORE_ADDR addr); diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index 4b8c3ed..2d0efaf 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -874,25 +874,17 @@ ppc_displaced_step_copy_insn (struct gdbarch *gdbarch, /* Assume all atomic sequences start with a Load and Reserve instruction. */ if (IS_LOAD_AND_RESERVE_INSN (insn)) { - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, - "displaced: can't displaced step " - "atomic sequence at %s\n", + displaced_debug_printf ("can't displaced step atomic sequence at %s", paddress (gdbarch, from)); - } return NULL; } write_memory (to, buf, len); - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ", - paddress (gdbarch, from), paddress (gdbarch, to)); - displaced_step_dump_bytes (gdb_stdlog, buf, len); - } + displaced_debug_printf ("copy %s->%s: %s", + paddress (gdbarch, from), paddress (gdbarch, to), + displaced_step_dump_bytes (buf, len).c_str ());; /* This is a work around for a problem with g++ 4.8. */ return displaced_step_closure_up (closure.release ()); @@ -917,11 +909,8 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch, opcode = insn & BRANCH_MASK; - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: (ppc) fixup (%s, %s)\n", - paddress (gdbarch, from), paddress (gdbarch, to)); - + displaced_debug_printf ("(ppc) fixup (%s, %s)", + paddress (gdbarch, from), paddress (gdbarch, to)); /* Handle PC-relative branch instructions. */ if (opcode == B_INSN || opcode == BC_INSN || opcode == BXL_INSN) @@ -942,13 +931,11 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch, if (!(insn & 0x2)) { /* PC-relative addressing is being used in the branch. */ - if (debug_displaced) - fprintf_unfiltered - (gdb_stdlog, - "displaced: (ppc) branch instruction: %s\n" - "displaced: (ppc) adjusted PC from %s to %s\n", - paddress (gdbarch, insn), paddress (gdbarch, current_pc), - paddress (gdbarch, from + offset)); + displaced_debug_printf ("(ppc) branch instruction: %s", + paddress (gdbarch, insn)); + displaced_debug_printf ("(ppc) adjusted PC from %s to %s", + paddress (gdbarch, current_pc), + paddress (gdbarch, from + offset)); regcache_cooked_write_unsigned (regs, gdbarch_pc_regnum (gdbarch), @@ -975,10 +962,8 @@ ppc_displaced_step_fixup (struct gdbarch *gdbarch, regcache_cooked_write_unsigned (regs, gdbarch_tdep (gdbarch)->ppc_lr_regnum, from + PPC_INSN_SIZE); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: (ppc) adjusted LR to %s\n", - paddress (gdbarch, from + PPC_INSN_SIZE)); + displaced_debug_printf ("(ppc) adjusted LR to %s", + paddress (gdbarch, from + PPC_INSN_SIZE)); } } diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index d3b96eb..ce01345 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -454,13 +454,8 @@ s390_displaced_step_copy_insn (struct gdbarch *gdbarch, { /* Let the core fall back to stepping over the breakpoint in-line. */ - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, - "displaced: can't displaced step " - "RIL instruction: offset %s out of range\n", - plongest (offset)); - } + displaced_debug_printf ("can't displaced step RIL instruction: offset " + "%s out of range", plongest (offset)); return NULL; } @@ -470,12 +465,9 @@ s390_displaced_step_copy_insn (struct gdbarch *gdbarch, write_memory (to, buf, len); - if (debug_displaced) - { - fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ", - paddress (gdbarch, from), paddress (gdbarch, to)); - displaced_step_dump_bytes (gdb_stdlog, buf, len); - } + displaced_debug_printf ("copy %s->%s: %s", + paddress (gdbarch, from), paddress (gdbarch, to), + displaced_step_dump_bytes (buf, len).c_str ()); /* This is a work around for a problem with g++ 4.8. */ return displaced_step_closure_up (closure.release ()); @@ -511,11 +503,9 @@ s390_displaced_step_fixup (struct gdbarch *gdbarch, amode &= 0x80000000; } - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: (s390) fixup (%s, %s) pc %s len %d amode 0x%x\n", - paddress (gdbarch, from), paddress (gdbarch, to), - paddress (gdbarch, pc), insnlen, (int) amode); + displaced_debug_printf ("(s390) fixup (%s, %s) pc %s len %d amode 0x%x", + paddress (gdbarch, from), paddress (gdbarch, to), + paddress (gdbarch, pc), insnlen, (int) amode); /* Handle absolute branch and save instructions. */ int op_basr_p = is_rr (insn, op_basr, &r1, &r2); @@ -578,10 +568,8 @@ s390_displaced_step_fixup (struct gdbarch *gdbarch, else regcache_write_pc (regs, pc - to + from); - if (debug_displaced) - fprintf_unfiltered (gdb_stdlog, - "displaced: (s390) pc is now %s\n", - paddress (gdbarch, regcache_read_pc (regs))); + displaced_debug_printf ("(s390) pc is now %s", + paddress (gdbarch, regcache_read_pc (regs))); } /* Implement displaced_step_hw_singlestep gdbarch method. */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6c28c59..3ed7d4f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-10-30 Simon Marchi <simon.marchi@efficios.com> + + * gdb.arch/amd64-disp-step-avx.exp: Update displaced step debug + expected output. + 2020-10-30 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.base/paginate-after-ctrl-c-running.exp: Update with no pagination diff --git a/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp index ab83fe6..5dd827a 100644 --- a/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp +++ b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp @@ -97,7 +97,7 @@ proc disp_step_func { func } { gdb_test_no_output "set debug displaced on" gdb_test "continue" \ - "Continuing.*displaced: displaced pc to.*Breakpoint.*, ${test_end_label} ().*" \ + "Continuing.*displaced pc to.*Breakpoint.*, ${test_end_label} ().*" \ "continue to ${test_end_label}" gdb_test_no_output "set debug displaced off" |