aboutsummaryrefslogtreecommitdiff
path: root/gdb/target.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/target.c')
-rw-r--r--gdb/target.c163
1 files changed, 57 insertions, 106 deletions
diff --git a/gdb/target.c b/gdb/target.c
index 6a180f3..8de1be8 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -41,6 +41,7 @@
#include "target-descriptions.h"
#include "gdbthread.h"
#include "solib.h"
+#include "exec.h"
static void target_info (char *, int);
@@ -491,8 +492,6 @@ update_current_target (void)
INHERIT (to_has_registers, t);
INHERIT (to_has_execution, t);
INHERIT (to_has_thread_control, t);
- INHERIT (to_sections, t);
- INHERIT (to_sections_end, t);
INHERIT (to_can_async_p, t);
INHERIT (to_is_async_p, t);
INHERIT (to_async, t);
@@ -1016,14 +1015,33 @@ done:
return nbytes_read;
}
+struct target_section_table *
+target_get_section_table (struct target_ops *target)
+{
+ struct target_ops *t;
+
+ if (targetdebug)
+ fprintf_unfiltered (gdb_stdlog, "target_get_section_table ()\n");
+
+ for (t = target; t != NULL; t = t->beneath)
+ if (t->to_get_section_table != NULL)
+ return (*t->to_get_section_table) (t);
+
+ return NULL;
+}
+
/* Find a section containing ADDR. */
+
struct target_section *
target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
{
+ struct target_section_table *table = target_get_section_table (target);
struct target_section *secp;
- for (secp = target->to_sections;
- secp < target->to_sections_end;
- secp++)
+
+ if (table == NULL)
+ return NULL;
+
+ for (secp = table->sections; secp < table->sections_end; secp++)
{
if (addr >= secp->addr && addr < secp->endaddr)
return secp;
@@ -1046,24 +1064,43 @@ memory_xfer_partial (struct target_ops *ops, void *readbuf, const void *writebuf
if (len == 0)
return 0;
- /* Try the executable file, if "trust-readonly-sections" is set. */
+ /* For accesses to unmapped overlay sections, read directly from
+ files. Must do this first, as MEMADDR may need adjustment. */
+ if (readbuf != NULL && overlay_debugging)
+ {
+ struct obj_section *section = find_pc_overlay (memaddr);
+ if (pc_in_unmapped_range (memaddr, section))
+ {
+ struct target_section_table *table
+ = target_get_section_table (ops);
+ const char *section_name = section->the_bfd_section->name;
+ memaddr = overlay_mapped_address (memaddr, section);
+ return section_table_xfer_memory_partial (readbuf, writebuf,
+ memaddr, len,
+ table->sections,
+ table->sections_end,
+ section_name);
+ }
+ }
+
+ /* Try the executable files, if "trust-readonly-sections" is set. */
if (readbuf != NULL && trust_readonly)
{
struct target_section *secp;
+ struct target_section_table *table;
secp = target_section_by_addr (ops, memaddr);
if (secp != NULL
&& (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
& SEC_READONLY))
- return xfer_memory (memaddr, readbuf, len, 0, NULL, ops);
- }
-
- /* Likewise for accesses to unmapped overlay sections. */
- if (readbuf != NULL && overlay_debugging)
- {
- struct obj_section *section = find_pc_overlay (memaddr);
- if (pc_in_unmapped_range (memaddr, section))
- return xfer_memory (memaddr, readbuf, len, 0, NULL, ops);
+ {
+ table = target_get_section_table (ops);
+ return section_table_xfer_memory_partial (readbuf, writebuf,
+ memaddr, len,
+ table->sections,
+ table->sections_end,
+ NULL);
+ }
}
/* Try GDB's internal data cache. */
@@ -1688,7 +1725,11 @@ void
get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf,
LONGEST len)
{
- if (target_read (ops, TARGET_OBJECT_MEMORY, NULL, buf, addr, len)
+ /* This method is used to read from an alternate, non-current
+ target. This read must bypass the overlay support (as symbols
+ don't match this target), and GDB's internal cache (wrong cache
+ for this target). */
+ if (target_read (ops, TARGET_OBJECT_RAW_MEMORY, NULL, buf, addr, len)
!= len)
memory_error (EIO, addr);
}
@@ -2338,96 +2379,6 @@ return_minus_one (void)
return -1;
}
-/*
- * Resize the to_sections pointer. Also make sure that anyone that
- * was holding on to an old value of it gets updated.
- * Returns the old size.
- */
-
-int
-target_resize_to_sections (struct target_ops *target, int num_added)
-{
- struct target_ops **t;
- struct target_section *old_value;
- int old_count;
-
- old_value = target->to_sections;
-
- if (target->to_sections)
- {
- old_count = target->to_sections_end - target->to_sections;
- target->to_sections = (struct target_section *)
- xrealloc ((char *) target->to_sections,
- (sizeof (struct target_section)) * (num_added + old_count));
- }
- else
- {
- old_count = 0;
- target->to_sections = (struct target_section *)
- xmalloc ((sizeof (struct target_section)) * num_added);
- }
- target->to_sections_end = target->to_sections + (num_added + old_count);
-
- /* Check to see if anyone else was pointing to this structure.
- If old_value was null, then no one was. */
-
- if (old_value)
- {
- for (t = target_structs; t < target_structs + target_struct_size;
- ++t)
- {
- if ((*t)->to_sections == old_value)
- {
- (*t)->to_sections = target->to_sections;
- (*t)->to_sections_end = target->to_sections_end;
- }
- }
- /* There is a flattened view of the target stack in current_target,
- so its to_sections pointer might also need updating. */
- if (current_target.to_sections == old_value)
- {
- current_target.to_sections = target->to_sections;
- current_target.to_sections_end = target->to_sections_end;
- }
- }
-
- return old_count;
-
-}
-
-/* Remove all target sections taken from ABFD.
-
- Scan the current target stack for targets whose section tables
- refer to sections from BFD, and remove those sections. We use this
- when we notice that the inferior has unloaded a shared object, for
- example. */
-void
-remove_target_sections (bfd *abfd)
-{
- struct target_ops **t;
-
- for (t = target_structs; t < target_structs + target_struct_size; t++)
- {
- struct target_section *src, *dest;
-
- dest = (*t)->to_sections;
- for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
- if (src->bfd != abfd)
- {
- /* Keep this section. */
- if (dest < src) *dest = *src;
- dest++;
- }
-
- /* If we've dropped any sections, resize the section table. */
- if (dest < src)
- target_resize_to_sections (*t, dest - src);
- }
-}
-
-
-
-
/* Find a single runnable target in the stack and return it. If for
some reason there is more than one, return NULL. */