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. */
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 (size_t i = 0; i < len; i++)
+ {
+ if (i == 0)
+ ret += string_printf ("%02x", buf[i]);
+ else
+ ret += string_printf (" %02x", buf[i]);
+ }
- for (i = 0; i < len; i++)
- fprintf_unfiltered (file, "%02x ", buf[i]);
- fputs_unfiltered ("\n", file);
+ return ret;
}
/* Prepare to single-step, using displaced stepping.
/* 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);
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;
}
_("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);
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;
}
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
}
else if (prepared > 0)
{
- struct displaced_step_inferior_state *displaced;
-
/* Update pc to reflect the new address from which we will
execute instructions due to displaced stepping. */
pc = regcache_read_pc (get_thread_regcache (tp));
- displaced = get_displaced_stepping_state (tp->inf);
- step = gdbarch_displaced_step_hw_singlestep
- (gdbarch, displaced->step_closure.get ());
+ step = gdbarch_displaced_step_hw_singlestep (gdbarch);
}
}
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)
the main console. */
scoped_restore save_ui = make_scoped_restore (¤t_ui, main_ui);
+ /* Temporarily disable pagination. Otherwise, the user would be
+ given an option to press 'q' to quit, which would cause an early
+ exit and could leave GDB in a half-baked state. */
+ scoped_restore save_pagination
+ = make_scoped_restore (&pagination_enabled, false);
+
/* End up with readline processing input, if necessary. */
{
SCOPE_EXIT { reinstall_readline_callback_handler_cleanup (); };
/* 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);
}
enum stop_stack_kind stop_stack_dummy = STOP_NONE;
int stopped_by_random_signal = 0;
- /* ID if the selected frame when the inferior function call was made. */
+ /* ID and level of the selected frame when the inferior function
+ call was made. */
struct frame_id selected_frame_id {};
+ int selected_frame_level = -1;
};
/* Save all of the information associated with the inferior<==>gdb
inf_status->stop_stack_dummy = stop_stack_dummy;
inf_status->stopped_by_random_signal = stopped_by_random_signal;
- inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
+ save_selected_frame (&inf_status->selected_frame_id,
+ &inf_status->selected_frame_level);
return inf_status;
}
-static void
-restore_selected_frame (const frame_id &fid)
-{
- frame_info *frame = frame_find_by_id (fid);
-
- /* If inf_status->selected_frame_id is NULL, there was no previously
- selected frame. */
- if (frame == NULL)
- {
- warning (_("Unable to restore previously selected frame."));
- return;
- }
-
- select_frame (frame);
-}
-
/* Restore inferior session state to INF_STATUS. */
void
if (target_has_stack ())
{
- /* The point of the try/catch is that if the stack is clobbered,
- walking the stack might encounter a garbage pointer and
- error() trying to dereference it. */
- try
- {
- restore_selected_frame (inf_status->selected_frame_id);
- }
- catch (const gdb_exception_error &ex)
- {
- exception_fprintf (gdb_stderr, ex,
- "Unable to restore previously selected frame:\n");
- /* Error in restoring the selected frame. Select the
- innermost frame. */
- select_frame (get_current_frame ());
- }
+ restore_selected_frame (inf_status->selected_frame_id,
+ inf_status->selected_frame_level);
}
delete inf_status;