aboutsummaryrefslogtreecommitdiff
path: root/gdb/symfile.c
diff options
context:
space:
mode:
authorPetr Tesarik <ptesarik@suse.cz>2018-06-28 08:33:17 +0200
committerPetr Tesarik <ptesarik@suse.cz>2018-06-28 08:35:34 +0200
commit291f9a9643f87fa4eb6a7c280eaa3877c11e3a1f (patch)
tree4318a3a5a93f7f82ada7a658b214783a334098fe /gdb/symfile.c
parentd81a3eaff36b41ed67758a119a6864b50f60a60d (diff)
downloadgdb-291f9a9643f87fa4eb6a7c280eaa3877c11e3a1f.zip
gdb-291f9a9643f87fa4eb6a7c280eaa3877c11e3a1f.tar.gz
gdb-291f9a9643f87fa4eb6a7c280eaa3877c11e3a1f.tar.bz2
Add an optional offset option to the "add-symbol-file" command
If all sections of a symbol file are loaded with a fixed offset, it is easier to specify that offset than listing all sections explicitly. There is also a similar option for "symbol-file". gdb/ChangeLog: 2018-06-28 Petr Tesarik <ptesarik@suse.cz> * symfile.c (add_symbol_file_command, _initialize_symfile): Add option "-o" to add-symbol-file-load to add an offset to each section's load address. * symfile.c (set_objfile_default_section_offset): New function. gdb/doc/ChangeLog: 2018-06-28 Petr Tesarik <ptesarik@suse.cz> * gdb.texinfo (Files): Document "add-symbol-file -o offset". gdb/testsuite/ChangeLog: 2018-06-28 Petr Tesarik <ptesarik@suse.cz> * gdb.base/relocate.exp: Add test for "add-symbol-file -o ".
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r--gdb/symfile.c83
1 files changed, 80 insertions, 3 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index b592be7..48eca5c 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2078,6 +2078,61 @@ print_transfer_performance (struct ui_file *stream,
uiout->text (".\n");
}
+/* Add an OFFSET to the start address of each section in OBJF, except
+ sections that were specified in ADDRS. */
+
+static void
+set_objfile_default_section_offset (struct objfile *objf,
+ const section_addr_info &addrs,
+ CORE_ADDR offset)
+{
+ /* Add OFFSET to all sections by default. */
+ std::vector<struct section_offsets> offsets (objf->num_sections,
+ { offset });
+
+ /* Create sorted lists of all sections in ADDRS as well as all
+ sections in OBJF. */
+
+ std::vector<const struct other_sections *> addrs_sorted
+ = addrs_section_sort (addrs);
+
+ section_addr_info objf_addrs
+ = build_section_addr_info_from_objfile (objf);
+ std::vector<const struct other_sections *> objf_addrs_sorted
+ = addrs_section_sort (objf_addrs);
+
+ /* Walk the BFD section list, and if a matching section is found in
+ ADDRS_SORTED_LIST, set its offset to zero to keep its address
+ unchanged.
+
+ Note that both lists may contain multiple sections with the same
+ name, and then the sections from ADDRS are matched in BFD order
+ (thanks to sectindex). */
+
+ std::vector<const struct other_sections *>::iterator addrs_sorted_iter
+ = addrs_sorted.begin ();
+ for (const struct other_sections *objf_sect : objf_addrs_sorted)
+ {
+ const char *objf_name = addr_section_name (objf_sect->name.c_str ());
+ int cmp = -1;
+
+ while (cmp < 0 && addrs_sorted_iter != addrs_sorted.end ())
+ {
+ const struct other_sections *sect = *addrs_sorted_iter;
+ const char *sect_name = addr_section_name (sect->name.c_str ());
+ cmp = strcmp (sect_name, objf_name);
+ if (cmp <= 0)
+ ++addrs_sorted_iter;
+ }
+
+ if (cmp == 0)
+ offsets[objf_sect->sectindex].offsets[0] = 0;
+ }
+
+ /* Apply the new section offsets. */
+ objfile_relocate (objf, offsets.data ());
+}
+
/* This function allows the addition of incrementally linked object files.
It does not modify any state in the target, only in the debugger. */
/* Note: ezannoni 2000-04-13 This function/command used to have a
@@ -2109,6 +2164,7 @@ add_symbol_file_command (const char *args, int from_tty)
std::vector<sect_opt> sect_opts = { { ".text", NULL } };
bool stop_processing_options = false;
+ CORE_ADDR offset = 0;
dont_repeat ();
@@ -2116,6 +2172,7 @@ add_symbol_file_command (const char *args, int from_tty)
error (_("add-symbol-file takes a file name and an address"));
bool seen_addr = false;
+ bool seen_offset = false;
gdb_argv argv (args);
for (arg = argv[0], argcnt = 0; arg != NULL; arg = argv[++argcnt])
@@ -2153,6 +2210,15 @@ add_symbol_file_command (const char *args, int from_tty)
sect_opts.push_back (sect);
argcnt += 2;
}
+ else if (strcmp (arg, "-o") == 0)
+ {
+ arg = argv[++argcnt];
+ if (arg == NULL)
+ error (_("Missing argument to -o"));
+
+ offset = parse_and_eval_address (arg);
+ seen_offset = true;
+ }
else if (strcmp (arg, "--") == 0)
stop_processing_options = true;
else
@@ -2202,7 +2268,13 @@ add_symbol_file_command (const char *args, int from_tty)
At this point, we don't know what file type this is,
so we can't determine what section names are valid. */
}
- if (section_addrs.empty ())
+ if (seen_offset)
+ printf_unfiltered (_("%s offset by %s\n"),
+ (section_addrs.empty ()
+ ? _(" with all sections")
+ : _("with other sections")),
+ paddress (gdbarch, offset));
+ else if (section_addrs.empty ())
printf_unfiltered ("\n");
if (from_tty && (!query ("%s", "")))
@@ -2211,6 +2283,9 @@ add_symbol_file_command (const char *args, int from_tty)
objf = symbol_file_add (filename.get (), add_flags, &section_addrs,
flags);
+ if (seen_offset)
+ set_objfile_default_section_offset (objf, section_addrs, offset);
+
add_target_sections_of_objfile (objf);
/* Getting new symbols may change our opinion about what is
@@ -3799,12 +3874,14 @@ to execute.\n" READNOW_READNEVER_HELP), &cmdlist);
c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, _("\
Load symbols from FILE, assuming FILE has been dynamically loaded.\n\
-Usage: add-symbol-file FILE [-readnow | -readnever] [ADDR] \
+Usage: add-symbol-file FILE [-readnow | -readnever] [-o OFF] [ADDR] \
[-s SECT-NAME SECT-ADDR]...\n\
ADDR is the starting address of the file's text.\n\
Each '-s' argument provides a section name and address, and\n\
should be specified if the data and bss segments are not contiguous\n\
-with the text. SECT-NAME is a section name to be loaded at SECT-ADDR.\n"
+with the text. SECT-NAME is a section name to be loaded at SECT-ADDR.\n\
+OFF is an optional offset which is added to the default load addresses\n\
+of all sections for which no other address was specified.\n"
READNOW_READNEVER_HELP),
&cmdlist);
set_cmd_completer (c, filename_completer);