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
This commit is contained in:
parent
aa2045e7fa
commit
136821d9f6
12 changed files with 312 additions and 461 deletions
99
gdb/infrun.c
99
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)
|
||||
{
|
||||
int i;
|
||||
/* See infrun.h. */
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
fprintf_unfiltered (file, "%02x ", buf[i]);
|
||||
fputs_unfiltered ("\n", file);
|
||||
std::string
|
||||
displaced_step_dump_bytes (const gdb_byte *buf, size_t len)
|
||||
{
|
||||
std::string ret;
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue