* target.h (struct target_ops): Make to_has_all_memory,

to_has_memory, to_has_stack, to_has_registers and to_has_execution
	methods instead of variables.
	(target_has_all_memory_1, target_has_memory_1, target_has_stack_1)
	(target_has_registers_1, target_has_execution_1): Declare
	functions.
	(target_has_all_memory): Rewrite to call target_has_all_memory_1.
	(target_has_memory): Rewrite to call target_has_memory_1.
	(target_has_stack): Rewrite to call target_has_all_stack_1.
	(target_has_registers): Rewrite to call target_has_registers_1.
	(target_has_execution): Rewrite to call target_has_execution_1.
	(default_child_has_all_memory, default_child_has_memory)
	(default_child_has_stack, default_child_has_registers)
	(default_child_has_execution): Declare.
	(target_mark_running, target_mark_exited): Delete declarations.
	* target.c (default_child_has_all_memory,
	default_child_has_memory, default_child_has_stack,
	default_child_has_registers, default_child_has_execution): New.
	(target_has_all_memory_1, target_has_memory_1, target_has_stack_1,
	target_has_registers_1, target_has_execution_1): New.
	(add_target): Default the to_has_all_memory, to_has_all_memory,
	to_has_memory, to_has_stack, to_has_registers and to_has_execution
	callbacks to return 0.
	(update_current_target): Do not inherit to_has_all_memory,
	to_has_memory, to_has_stack, to_has_registers or to_has_execution.
	(target_mark_running, target_mark_exited): Delete.
	(memory_xfer_partial): Adjust.
	(target_read_memory, target_write_memory, target_search_memory):
	Dispatch to the the top-most target, not the flattened
	current_target.
	(target_info): Adjust.
	(init_dummy_target): Install return_zero as callback for
	to_has_all_memory, to_has_memory, to_has_stack, to_has_registers,
	to_has_execution.
	(set_maintenance_target_async_permitted): Use have_live_inferiors
	instead of target_has_execution.
	* target-memory.c (target_write_memory_blocks): Dispatch memory
	writes to the the top-most target, not the flattened
	current_target.

	* breakpoint.c (insert_breakpoints): Don't check for
	target_has_execution here.
	(update_global_location_list): Check if there are live inferiors
	to debug instead of target_has_execution.
	* infcmd.c (kill_command, detach_command): Check if there are
	inferiors instead of target_has_execution.
	* inferior.h (have_live_inferiors): Declare.
	* inferior.c (have_live_inferiors): New.
	* infrun.c (normal_stop): Don't check for target_has_execution to
	finish the thread states.
	* thread.c (is_thread_state, is_stopped, is_exited, is_running)
	(any_running, is_executing): Remove checks for
	target_has_execution.
	* top.c (kill_or_detach): Don't try to kill core inferiors.
	(quit_target): Don't check for target_has_execution.

	* corelow.c (core_has_memory, core_has_stack, core_has_registers):
	New.
	(init_core_ops): Install core_has_memory, core_has_stack and
	core_has_registers.
	* exec.c (exec_has_memory): New.
	(init_exec_ops): Install exec_has_memory.
	* remote.c (remote_add_inferior): Don't call target_mark_running.
	(remote_start_remote): Don't call target_mark_exited or call
	target_mark_running.
	(remote_open_1): Use have_inferiors instead of
	target_has_execution.  Don't use target_mark_exited.
	(init_remote_ops): Install deafult_child_has_all_memory,
	default_child_has_memory, default_child_has_stack,
	default_child_has_registers, default_child_has_execution.
	* bsd-kvm.c (bsd_kvm_return_one): New.
	(bsd_kvm_add_target): Register bsd_kvm_return_one as
	to_has_memory, to_has_stack and to_has_registers callbacks.
	* remote-m32r-sdi.c (m32r_return_one): New.
	(init_m32r_ops): Register it.
	* inf-child.c (inf_child_target): Adjust to register
	default_child_has_all_memory, default_child_has_memory,
	default_child_has_stack, default_child_has_registers,
	default_child_has_execution callbacks.
	* gnu-nat.c (init_gnu_ops): Likewise.
	* go32-nat.c (init_go32_ops): Likewise.
	* hpux-thread.c (init_hpux_thread_ops): Likewise.
	* monitor.c (init_base_monitor_ops): Likewise.
	* nto-procfs.c (init_procfs_ops): Likewise.
	* remote-mips.c (_initialize_remote_mips): Likewise.
	* windows-nat.c (init_windows_ops): Likewise.
	* remote-sim.c (gdbsim_create_inferior): Don't use
	target_mark_running or target_mark_exited.
	(gdbsim_mourn_inferior): Don't call target_mark_exited.
	(init_gdbsim_ops): Adjust to register
	default_child_has_all_memory, default_child_has_memory,
	default_child_has_stack, default_child_has_registers,
	default_child_has_execution callbacks.

	* linux-nat.c (linux_nat_xfer_partial): If reading memory, and
	there's no inferior selected, defer to a lower stratum.
This commit is contained in:
Pedro Alves 2009-06-07 16:46:48 +00:00
parent 68c9c31474
commit c35b149212
26 changed files with 432 additions and 241 deletions

View file

@ -213,6 +213,120 @@ target_command (char *arg, int from_tty)
gdb_stdout);
}
/* Default target_has_* methods for process_stratum targets. */
int
default_child_has_all_memory (struct target_ops *ops)
{
/* If no inferior selected, then we can't read memory here. */
if (ptid_equal (inferior_ptid, null_ptid))
return 0;
return 1;
}
int
default_child_has_memory (struct target_ops *ops)
{
/* If no inferior selected, then we can't read memory here. */
if (ptid_equal (inferior_ptid, null_ptid))
return 0;
return 1;
}
int
default_child_has_stack (struct target_ops *ops)
{
/* If no inferior selected, there's no stack. */
if (ptid_equal (inferior_ptid, null_ptid))
return 0;
return 1;
}
int
default_child_has_registers (struct target_ops *ops)
{
/* Can't read registers from no inferior. */
if (ptid_equal (inferior_ptid, null_ptid))
return 0;
return 1;
}
int
default_child_has_execution (struct target_ops *ops)
{
/* If there's no thread selected, then we can't make it run through
hoops. */
if (ptid_equal (inferior_ptid, null_ptid))
return 0;
return 1;
}
int
target_has_all_memory_1 (void)
{
struct target_ops *t;
for (t = current_target.beneath; t != NULL; t = t->beneath)
if (t->to_has_all_memory (t))
return 1;
return 0;
}
int
target_has_memory_1 (void)
{
struct target_ops *t;
for (t = current_target.beneath; t != NULL; t = t->beneath)
if (t->to_has_memory (t))
return 1;
return 0;
}
int
target_has_stack_1 (void)
{
struct target_ops *t;
for (t = current_target.beneath; t != NULL; t = t->beneath)
if (t->to_has_stack (t))
return 1;
return 0;
}
int
target_has_registers_1 (void)
{
struct target_ops *t;
for (t = current_target.beneath; t != NULL; t = t->beneath)
if (t->to_has_registers (t))
return 1;
return 0;
}
int
target_has_execution_1 (void)
{
struct target_ops *t;
for (t = current_target.beneath; t != NULL; t = t->beneath)
if (t->to_has_execution (t))
return 1;
return 0;
}
/* Add a possible target architecture to the list. */
void
@ -222,6 +336,21 @@ add_target (struct target_ops *t)
if (t->to_xfer_partial == NULL)
t->to_xfer_partial = default_xfer_partial;
if (t->to_has_all_memory == NULL)
t->to_has_all_memory = (int (*) (struct target_ops *)) return_zero;
if (t->to_has_memory == NULL)
t->to_has_memory = (int (*) (struct target_ops *)) return_zero;
if (t->to_has_stack == NULL)
t->to_has_stack = (int (*) (struct target_ops *)) return_zero;
if (t->to_has_registers == NULL)
t->to_has_registers = (int (*) (struct target_ops *)) return_zero;
if (t->to_has_execution == NULL)
t->to_has_execution = (int (*) (struct target_ops *)) return_zero;
if (!target_structs)
{
target_struct_allocsize = DEFAULT_ALLOCSIZE;
@ -486,11 +615,11 @@ update_current_target (void)
INHERIT (to_pid_to_exec_file, t);
INHERIT (to_log_command, t);
INHERIT (to_stratum, t);
INHERIT (to_has_all_memory, t);
INHERIT (to_has_memory, t);
INHERIT (to_has_stack, t);
INHERIT (to_has_registers, t);
INHERIT (to_has_execution, t);
/* Do not inherit to_has_all_memory */
/* Do not inherit to_has_memory */
/* Do not inherit to_has_stack */
/* Do not inherit to_has_registers */
/* Do not inherit to_has_execution */
INHERIT (to_has_thread_control, t);
INHERIT (to_can_async_p, t);
INHERIT (to_is_async_p, t);
@ -658,56 +787,6 @@ update_current_target (void)
setup_target_debug ();
}
/* Mark OPS as a running target. This reverses the effect
of target_mark_exited. */
void
target_mark_running (struct target_ops *ops)
{
struct target_ops *t;
for (t = target_stack; t != NULL; t = t->beneath)
if (t == ops)
break;
if (t == NULL)
internal_error (__FILE__, __LINE__,
"Attempted to mark unpushed target \"%s\" as running",
ops->to_shortname);
ops->to_has_execution = 1;
ops->to_has_all_memory = 1;
ops->to_has_memory = 1;
ops->to_has_stack = 1;
ops->to_has_registers = 1;
update_current_target ();
}
/* Mark OPS as a non-running target. This reverses the effect
of target_mark_running. */
void
target_mark_exited (struct target_ops *ops)
{
struct target_ops *t;
for (t = target_stack; t != NULL; t = t->beneath)
if (t == ops)
break;
if (t == NULL)
internal_error (__FILE__, __LINE__,
"Attempted to mark unpushed target \"%s\" as running",
ops->to_shortname);
ops->to_has_execution = 0;
ops->to_has_all_memory = 0;
ops->to_has_memory = 0;
ops->to_has_stack = 0;
ops->to_has_registers = 0;
update_current_target ();
}
/* Push a new target type into the stack of the existing target accessors,
possibly superseding some of the existing accessors.
@ -1176,7 +1255,7 @@ memory_xfer_partial (struct target_ops *ops, void *readbuf, const void *writebuf
/* We want to continue past core files to executables, but not
past a running target's memory. */
if (ops->to_has_all_memory)
if (ops->to_has_all_memory (ops))
break;
ops = ops->beneath;
@ -1293,7 +1372,10 @@ target_xfer_partial (struct target_ops *ops,
int
target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
{
if (target_read (&current_target, TARGET_OBJECT_MEMORY, NULL,
/* Dispatch to the topmost target, not the flattened current_target.
Memory accesses check target->to_has_(all_)memory, and the
flattened target doesn't inherit those. */
if (target_read (current_target.beneath, TARGET_OBJECT_MEMORY, NULL,
myaddr, memaddr, len) == len)
return 0;
else
@ -1303,7 +1385,10 @@ target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
int
target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
{
if (target_write (&current_target, TARGET_OBJECT_MEMORY, NULL,
/* Dispatch to the topmost target, not the flattened current_target.
Memory accesses check target->to_has_(all_)memory, and the
flattened target doesn't inherit those. */
if (target_write (current_target.beneath, TARGET_OBJECT_MEMORY, NULL,
myaddr, memaddr, len) == len)
return 0;
else
@ -1756,7 +1841,7 @@ target_info (char *args, int from_tty)
for (t = target_stack; t != NULL; t = t->beneath)
{
if (!t->to_has_memory)
if (!(*t->to_has_memory) (t))
continue;
if ((int) (t->to_stratum) <= (int) dummy_stratum)
@ -1765,7 +1850,7 @@ target_info (char *args, int from_tty)
printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
printf_unfiltered ("%s:\n", t->to_longname);
(t->to_files_info) (t);
has_all_mem = t->to_has_all_memory;
has_all_mem = (*t->to_has_all_memory) (t);
}
}
@ -2169,7 +2254,7 @@ target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
{
/* If a special version of to_search_memory isn't available, use the
simple version. */
found = simple_search_memory (&current_target,
found = simple_search_memory (current_target.beneath,
start_addr, search_space_len,
pattern, pattern_len, found_addrp);
}
@ -2541,6 +2626,11 @@ init_dummy_target (void)
dummy_target.to_find_memory_regions = dummy_find_memory_regions;
dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
dummy_target.to_xfer_partial = default_xfer_partial;
dummy_target.to_has_all_memory = (int (*) (struct target_ops *)) return_zero;
dummy_target.to_has_memory = (int (*) (struct target_ops *)) return_zero;
dummy_target.to_has_stack = (int (*) (struct target_ops *)) return_zero;
dummy_target.to_has_registers = (int (*) (struct target_ops *)) return_zero;
dummy_target.to_has_execution = (int (*) (struct target_ops *)) return_zero;
dummy_target.to_magic = OPS_MAGIC;
}
@ -3264,7 +3354,7 @@ static void
set_maintenance_target_async_permitted (char *args, int from_tty,
struct cmd_list_element *c)
{
if (target_has_execution)
if (have_live_inferiors ())
{
target_async_permitted_1 = target_async_permitted;
error (_("Cannot change this setting while the inferior is running."));