/* Select target systems and architectures at runtime for GDB.
- Copyright (C) 1990-2013 Free Software Foundation, Inc.
+ Copyright (C) 1990-2014 Free Software Foundation, Inc.
Contributed by Cygnus Support.
static int return_minus_one (void);
+static void *return_null (void);
+
void target_ignore (void);
static void target_command (char *, int);
static struct target_ops *find_default_run_target (char *);
-static LONGEST default_xfer_partial (struct target_ops *ops,
- enum target_object object,
- const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf,
- ULONGEST offset, LONGEST len);
+static target_xfer_partial_ftype default_xfer_partial;
-static LONGEST current_xfer_partial (struct target_ops *ops,
- enum target_object object,
- const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf,
- ULONGEST offset, LONGEST len);
+static target_xfer_partial_ftype current_xfer_partial;
static struct gdbarch *default_thread_architecture (struct target_ops *ops,
ptid_t ptid);
static void debug_to_open (char *, int);
-static void debug_to_prepare_to_store (struct regcache *);
+static void debug_to_prepare_to_store (struct target_ops *self,
+ struct regcache *);
static void debug_to_files_info (struct target_ops *);
(void (*) (int))
target_ignore);
de_fault (to_prepare_to_store,
- (void (*) (struct regcache *))
+ (void (*) (struct target_ops *, struct regcache *))
noprocess);
de_fault (deprecated_xfer_memory,
(int (*) (CORE_ADDR, gdb_byte *, int, int,
return_zero);
de_fault (to_extra_thread_info,
(char *(*) (struct thread_info *))
- return_zero);
+ return_null);
de_fault (to_thread_name,
(char *(*) (struct thread_info *))
- return_zero);
+ return_null);
de_fault (to_stop,
(void (*) (ptid_t))
target_ignore);
tcomplain);
de_fault (to_pid_to_exec_file,
(char *(*) (int))
- return_zero);
+ return_null);
de_fault (to_async,
(void (*) (void (*) (enum inferior_event_type, void*), void*))
tcomplain);
tcomplain);
de_fault (to_traceframe_info,
(struct traceframe_info * (*) (void))
- return_zero);
+ return_null);
de_fault (to_supports_evaluation_of_breakpoint_conditions,
(int (*) (void))
return_zero);
static LONGEST
target_read_live_memory (enum target_object object,
- ULONGEST memaddr, gdb_byte *myaddr, LONGEST len)
+ ULONGEST memaddr, gdb_byte *myaddr, ULONGEST len)
{
LONGEST ret;
struct cleanup *cleanup;
memory_xfer_live_readonly_partial (struct target_ops *ops,
enum target_object object,
gdb_byte *readbuf, ULONGEST memaddr,
- LONGEST len)
+ ULONGEST len)
{
struct target_section *secp;
struct target_section_table *table;
return 0;
}
+/* Read memory from more than one valid target. A core file, for
+ instance, could have some of memory but delegate other bits to
+ the target below it. So, we must manually try all targets. */
+
+static LONGEST
+raw_memory_xfer_partial (struct target_ops *ops, void *readbuf,
+ const void *writebuf, ULONGEST memaddr, LONGEST len)
+{
+ LONGEST res;
+
+ do
+ {
+ res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
+ readbuf, writebuf, memaddr, len);
+ if (res > 0)
+ break;
+
+ /* We want to continue past core files to executables, but not
+ past a running target's memory. */
+ if (ops->to_has_all_memory (ops))
+ break;
+
+ ops = ops->beneath;
+ }
+ while (ops != NULL);
+
+ return res;
+}
+
/* Perform a partial memory transfer.
For docs see target.h, to_xfer_partial. */
static LONGEST
memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
void *readbuf, const void *writebuf, ULONGEST memaddr,
- LONGEST len)
+ ULONGEST len)
{
LONGEST res;
int reg_len;
the collected memory range fails. */
&& get_traceframe_number () == -1
&& (region->attrib.cache
- || (stack_cache_enabled () && object == TARGET_OBJECT_STACK_MEMORY)))
+ || (stack_cache_enabled_p () && object == TARGET_OBJECT_STACK_MEMORY)
+ || (code_cache_enabled_p () && object == TARGET_OBJECT_CODE_MEMORY)))
{
DCACHE *dcache = target_dcache_get_or_init ();
to_xfer_partial is enough; if it doesn't recognize an object
it will call the to_xfer_partial of the next target down.
But for memory this won't do. Memory is the only target
- object which can be read from more than one valid target.
- A core file, for instance, could have some of memory but
- delegate other bits to the target below it. So, we must
- manually try all targets. */
-
- do
- {
- res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
- readbuf, writebuf, memaddr, reg_len);
- if (res > 0)
- break;
-
- /* We want to continue past core files to executables, but not
- past a running target's memory. */
- if (ops->to_has_all_memory (ops))
- break;
-
- ops = ops->beneath;
- }
- while (ops != NULL);
+ object which can be read from more than one valid target. */
+ res = raw_memory_xfer_partial (ops, readbuf, writebuf, memaddr, reg_len);
/* Make sure the cache gets updated no matter what - if we are writing
to the stack. Even if this write is not tagged as such, we still need
&& writebuf != NULL
&& target_dcache_init_p ()
&& !region->attrib.cache
- && stack_cache_enabled ()
- && object != TARGET_OBJECT_STACK_MEMORY)
+ && ((stack_cache_enabled_p () && object != TARGET_OBJECT_STACK_MEMORY)
+ || (code_cache_enabled_p () && object != TARGET_OBJECT_CODE_MEMORY)))
{
DCACHE *dcache = target_dcache_get ();
static LONGEST
memory_xfer_partial (struct target_ops *ops, enum target_object object,
void *readbuf, const void *writebuf, ULONGEST memaddr,
- LONGEST len)
+ ULONGEST len)
{
int res;
LONGEST
target_xfer_partial (struct target_ops *ops,
enum target_object object, const char *annex,
- void *readbuf, const void *writebuf,
- ULONGEST offset, LONGEST len)
+ gdb_byte *readbuf, const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len)
{
LONGEST retval;
/* If this is a memory transfer, let the memory-specific code
have a look at it instead. Memory transfers are more
complicated. */
- if (object == TARGET_OBJECT_MEMORY || object == TARGET_OBJECT_STACK_MEMORY)
+ if (object == TARGET_OBJECT_MEMORY || object == TARGET_OBJECT_STACK_MEMORY
+ || object == TARGET_OBJECT_CODE_MEMORY)
retval = memory_xfer_partial (ops, object, readbuf,
writebuf, offset, len);
- else
+ else if (object == TARGET_OBJECT_RAW_MEMORY)
{
- enum target_object raw_object = object;
-
- /* If this is a raw memory transfer, request the normal
- memory object from other layers. */
- if (raw_object == TARGET_OBJECT_RAW_MEMORY)
- raw_object = TARGET_OBJECT_MEMORY;
-
- retval = ops->to_xfer_partial (ops, raw_object, annex, readbuf,
- writebuf, offset, len);
+ /* Request the normal memory object from other layers. */
+ retval = raw_memory_xfer_partial (ops, readbuf, writebuf, offset, len);
}
+ else
+ retval = ops->to_xfer_partial (ops, object, annex, readbuf,
+ writebuf, offset, len);
if (targetdebug)
{
host_address_to_string (readbuf),
host_address_to_string (writebuf),
core_addr_to_string_nz (offset),
- plongest (len), plongest (retval));
+ pulongest (len), plongest (retval));
if (readbuf)
myaddr = readbuf;
return TARGET_XFER_E_IO;
}
+/* Like target_read_memory, but specify explicitly that this is a read
+ from the target's raw memory. That is, this read bypasses the
+ dcache, breakpoint shadowing, etc. */
+
+int
+target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
+{
+ /* See comment in target_read_memory about why the request starts at
+ current_target.beneath. */
+ if (target_read (current_target.beneath, TARGET_OBJECT_RAW_MEMORY, NULL,
+ myaddr, memaddr, len) == len)
+ return 0;
+ else
+ return TARGET_XFER_E_IO;
+}
+
/* Like target_read_memory, but specify explicitly that this is a read from
the target's stack. This may trigger different cache behavior. */
int
target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
{
- /* 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. */
-
+ /* See comment in target_read_memory about why the request starts at
+ current_target.beneath. */
if (target_read (current_target.beneath, TARGET_OBJECT_STACK_MEMORY, NULL,
myaddr, memaddr, len) == len)
return 0;
return TARGET_XFER_E_IO;
}
+/* Like target_read_memory, but specify explicitly that this is a read from
+ the target's code. This may trigger different cache behavior. */
+
+int
+target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
+{
+ /* See comment in target_read_memory about why the request starts at
+ current_target.beneath. */
+ if (target_read (current_target.beneath, TARGET_OBJECT_CODE_MEMORY, NULL,
+ myaddr, memaddr, len) == len)
+ return 0;
+ else
+ return TARGET_XFER_E_IO;
+}
+
/* Write LEN bytes from MYADDR to target memory at address MEMADDR.
Returns either 0 for success or a target_xfer_error value if any
error occurs. If an error occurs, no guarantee is made about how
int
target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
{
- /* 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. */
+ /* See comment in target_read_memory about why the request starts at
+ current_target.beneath. */
if (target_write (current_target.beneath, TARGET_OBJECT_MEMORY, NULL,
myaddr, memaddr, len) == len)
return 0;
int
target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
{
- /* 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. */
+ /* See comment in target_read_memory about why the request starts at
+ current_target.beneath. */
if (target_write (current_target.beneath, TARGET_OBJECT_RAW_MEMORY, NULL,
myaddr, memaddr, len) == len)
return 0;
static LONGEST
default_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
+ const gdb_byte *writebuf, ULONGEST offset, ULONGEST len)
{
if (object == TARGET_OBJECT_MEMORY
&& ops->deprecated_xfer_memory != NULL)
static LONGEST
current_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
- const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
+ const gdb_byte *writebuf, ULONGEST offset, ULONGEST len)
{
if (ops->beneath != NULL)
return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
return -1;
}
+static void *
+return_null (void)
+{
+ return 0;
+}
+
/*
* Find the next target down the stack from the specified target.
*/
}
static void
-debug_to_prepare_to_store (struct regcache *regcache)
+debug_to_prepare_to_store (struct target_ops *self, struct regcache *regcache)
{
- debug_target.to_prepare_to_store (regcache);
+ debug_target.to_prepare_to_store (&debug_target, regcache);
fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
}
+/* See target.h. */
+
+const struct frame_unwind *
+target_get_unwinder (void)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_get_unwinder != NULL)
+ return t->to_get_unwinder;
+
+ return NULL;
+}
+
+/* See target.h. */
+
+const struct frame_unwind *
+target_get_tailcall_unwinder (void)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_get_tailcall_unwinder != NULL)
+ return t->to_get_tailcall_unwinder;
+
+ return NULL;
+}
+
static int
deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len,
int write, struct mem_attrib *attrib,