aboutsummaryrefslogtreecommitdiff
path: root/gdb/target.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2009-06-03 18:50:36 +0000
committerPedro Alves <palves@redhat.com>2009-06-03 18:50:36 +0000
commit07b82ea5f9396811815e8085a4cce5ca03f50fb5 (patch)
tree528772b8131a21e8de911a9e68a4c78a780c8dd3 /gdb/target.c
parent4fa62494657f9b422edd7049c7207bd6c6849c3f (diff)
downloadgdb-07b82ea5f9396811815e8085a4cce5ca03f50fb5.zip
gdb-07b82ea5f9396811815e8085a4cce5ca03f50fb5.tar.gz
gdb-07b82ea5f9396811815e8085a4cce5ca03f50fb5.tar.bz2
* target.c: Include "exec.h".
(update_current_target): Don't inherit to_sections or to_sections_end. (target_get_section_table): New. (target_section_by_addr): Fetch the section table from the passed in target. (memory_xfer_partial): Handle unmapped overlay sections before anything else. Get the overlay mapped address here. Adjust to use section_table_xfer_memory_partial. (get_target_memory): Request a TARGET_OBJECT_RAW_MEMORY object instead of TARGET_OBJECT_MEMORY. (target_resize_to_sections): Delete. (remove_target_sections): Adjust to remove target sections from `current_target_sections', and use resize_section_table. * target.h (struct target_ops) <to_sections, to_sections_end>: Remove fields. <to_get_section_table>: New method. (xfer_memory, print_section_info): Delete declarations. (struct target_section_table): New type. (target_get_section_table): Declare. (target_resize_to_sections): Delete declaration. (remove_target_sections): Delete declaration. * bfd-target.c (target_bfd_xfer_partial): Get the section table from to_data. (target_bfd_get_section_table): New. (target_bfd_xclose): Adjust. (target_bfd_reopen): Store the section table in the to_data field. * corelow.c (core_data): New. (core_close): Adjust to release core_data and its sections. (core_open): Allocate core_data, and build its target sections table. (deprecated_core_resize_section_table): New. (core_files_info): Pass core_data to print_section_info. (core_xfer_partial): Adjust to use section_table_xfer_memory_partial for TARGET_OBJECT_MEMORY xfers. (init_core_ops): Do not install a deprecated_xfer_memory callback anymore. * solib.c (update_solib_list): Add the shared library sections to the current target sections table. * exec.c (current_target_sections_1): New global. (current_target_sections): New global. (exec_close_1): New function, refactored from exec_close. Remove the exec_bfd's sections from the current target sections table. Adjust to not use to_sections. (exec_close): Remove all target sections. Call exec_close_1. (exec_file_clear): Use exec_close_1 instead of unpushing the target. (exec_file_attach): Likewise. Adjust to not use to_sections. Add exec_bfd's sections to the current target sections table. Don't push the exec_ops target here. (resize_section_table): New. (add_target_sections): New. (remove_target_sections): Moved here. (section_table_xfer_memory): Adjust to implement the xfer_partial interface, and rename to... (section_table_xfer_memory_partial): ... this, replacing the current function of that same name. (exec_get_section_table): New. (exec_xfer_partial): New. (xfer_memory): Delete. (print_section_info): Replace the target_ops parameter by a target_section_table parameter. (exec_files_info, set_section_command, exec_set_section_address): Adjust to use the current sections table. (init_exec_ops): Do not register a deprecated_xfer_memory callback. Register to_xfer_partial and to_get_section_table callbacks. * infrun.c (handle_inferior_event): Update comments around solib_add. * rs6000-nat.c (xcoff_relocate_core): Adjust to use deprecated_core_resize_section_table. * exec.h (resize_section_table): Declare. (section_table_xfer_memory_partial): Add const char * argument. (remove_target_sections): Declare here. (add_target_sections): Declare. (print_section_info): Declare here. * gdbcore.h (deprecated_core_resize_section_table): Declare.
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. */