Make add-symbol-file's address argument optional
authorPetr Tesarik <ptesarik@suse.cz>
Thu, 28 Jun 2018 06:30:42 +0000 (08:30 +0200)
committerPetr Tesarik <ptesarik@suse.cz>
Thu, 28 Jun 2018 06:35:34 +0000 (08:35 +0200)
The (first) .text section must be always specified as the second
non-option argument.  The documentation states that GDB cannot
figure out this address by itself.  This is true if the object file
was indeed relocated, but it is also confusing, because all other
sections can be omitted and will use the address provided by BFD.

gdb/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

* symfile.c (add_symbol_file_command, _initialize_symfile): Do not
require the second argument.  If omitted, load sections at the
addresses specified in the file.

gdb/doc/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

* gdb.texinfo (Files): The address argument for "add-symbol-file"
is no longer mandatory.

gdb/testsuite/ChangeLog:
2018-06-28  Petr Tesarik  <ptesarik@suse.cz>

* gdb.base/relocate.exp: Test add-symbol-file behavior when the
address argument is omitted.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/symfile.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/relocate.exp

index 4bc320440737bcc131f3dfe26d71501c39517642..f17c1a105aee3da7357161bc34c42e5db1958cdc 100644 (file)
@@ -1,3 +1,9 @@
+2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
+
+       * symfile.c (add_symbol_file_command, _initialize_symfile): Do not
+       require the second argument.  If omitted, load sections at the
+       addresses specified in the file.
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
        * symfile.c (symbol_file_command, symbol_file_add_main_1)
index 101746567acefd344111713bb54fc0b498ff1524..54c0f1d19b199ad218d34302888106f9e62783af 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -6,6 +6,9 @@
 * The 'symbol-file' command now accepts an '-o' option to add a relative
   offset to all sections.
 
+* The 'add-symbol-file' command no longer requires the second argument
+  (address of the text section).
+
 * The endianness used with the 'set endian auto' mode in the absence of
   an executable selected for debugging is now the last endianness chosen
   either by one of the 'set endian big' and 'set endian little' commands
index f31287384c3a4e77cfa763805c937821991b2598..9fd3d3c3689061e51f163532360897f6e9d8a962 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
+
+       * gdb.texinfo (Files): The address argument for "add-symbol-file"
+       is no longer mandatory.
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
        * gdb.texinfo (Files): Document "symbol-file -o offset".
index 328256236e45cd28c49bc1708b02968775997540..64c511d1e6d2b93b526c1b9506ed4630bf05f61f 100644 (file)
@@ -18918,18 +18918,17 @@ the program is running.  To do this, use the @code{kill} command
 
 @kindex add-symbol-file
 @cindex dynamic linking
-@item add-symbol-file @var{filename} @var{address}
-@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{|} -readnever @r{]}
-@itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
+@item add-symbol-file @var{filename} @r{[} -readnow @r{|} -readnever @r{]} @r{[} @var{textaddress} @r{]} @r{[} -s @var{section} @var{address} @dots{} @r{]}
 The @code{add-symbol-file} command reads additional symbol table
 information from the file @var{filename}.  You would use this command
 when @var{filename} has been dynamically loaded (by some other means)
-into the program that is running.  The @var{address} should give the memory
-address at which the file has been loaded; @value{GDBN} cannot figure
-this out for itself.  You can additionally specify an arbitrary number
-of @samp{-s @var{section} @var{address}} pairs, to give an explicit
-section name and base address for that section.  You can specify any
-@var{address} as an expression.
+into the program that is running.  The @var{textaddress} parameter gives
+the memory address at which the file's text section has been loaded.
+You can additionally specify the base address of other sections using
+an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
+If a section is omitted, @value{GDBN} will use its default addresses
+as found in @var{filename}.  Any @var{address} or @var{textaddress}
+can be given as an expression.
 
 The symbol table of the file @var{filename} is added to the symbol table
 originally read with the @code{symbol-file} command.  You can use the
index 461f60d0748cb2783f33dae740547c0f47a42f86..2a41fce64fdfb380cdba9f389f88a14fb7f8ef1e 100644 (file)
@@ -2161,29 +2161,26 @@ add_symbol_file_command (const char *args, int from_tty)
 
   validate_readnow_readnever (flags);
 
-  /* This command takes at least two arguments.  The first one is a
-     filename, and the second is the address where this file has been
-     loaded.  Abort now if this address hasn't been provided by the
-     user.  */
-  if (!seen_addr)
-    error (_("The address where %s has been loaded is missing"),
-          filename.get ());
-
   /* Print the prompt for the query below.  And save the arguments into
      a sect_addr_info structure to be passed around to other
      functions.  We have to split this up into separate print
      statements because hex_string returns a local static
      string.  */
 
-  printf_unfiltered (_("add symbol table from file \"%s\" at\n"),
+  printf_unfiltered (_("add symbol table from file \"%s\""),
                     filename.get ());
   section_addr_info section_addrs;
-  for (sect_opt &sect : sect_opts)
+  std::vector<sect_opt>::const_iterator it = sect_opts.begin ();
+  if (!seen_addr)
+    ++it;
+  for (; it != sect_opts.end (); ++it)
     {
       CORE_ADDR addr;
-      const char *val = sect.value;
-      const char *sec = sect.name;
+      const char *val = it->value;
+      const char *sec = it->name;
 
+      if (section_addrs.empty ())
+       printf_unfiltered (_(" at\n"));
       addr = parse_and_eval_address (val);
 
       /* Here we store the section offsets in the order they were
@@ -2198,6 +2195,8 @@ 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 ())
+    printf_unfiltered ("\n");
 
   if (from_tty && (!query ("%s", "")))
     error (_("Not confirmed."));
@@ -3793,8 +3792,8 @@ 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 ADDR [-readnow | -readnever | \
--s SECT-NAME SECT-ADDR]...\n\
+Usage: add-symbol-file FILE [-readnow | -readnever] [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\
index cea52c78cafdecc107c0de39b22cb04ffe8281e0..e3c91415645ae38ed53599685371ac4c2279588a 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
+
+       * gdb.base/relocate.exp: Test add-symbol-file behavior when the
+       address argument is omitted.
+
 2018-06-28  Petr Tesarik  <ptesarik@suse.cz>
 
        * gdb.base/relocate.exp: Add test for "symbol-file -o ".
index 77f6a8815939e5be429208f67522d2ef1ad08af5..2b4c4a70446065505ba1fd5aef34b315202311f3 100644 (file)
@@ -73,6 +73,21 @@ gdb_test_multiple "add-symbol-file -s .text 0x200 $binfile 0x100" $test {
        gdb_test "n" "Not confirmed\." $test
     }
 }
+# Check that passing a single "-s .text" is equivalent to passing
+# the text address in a positional argument.
+set test "add-symbol-file -s .text, no address"
+gdb_test_multiple "add-symbol-file $binfile -s .text 0x100" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\\(y or n\\) " {
+       gdb_test "n" "Not confirmed\." $test
+    }
+}
+# Check section addresses can be omitted.
+set test "add-symbol-file no address"
+gdb_test_multiple "add-symbol-file $binfile" $test {
+    -re "add symbol table from file \"${binfile}\"\r\n\\(y or n\\) " {
+       gdb_test "n" "Not confirmed\." $test
+    }
+}
 # Test that passing "--" disables option processing.
 gdb_test "add-symbol-file -- $binfile 0x100 -s .bss 0x3" \
     "Unrecognized argument \"-s\"" \
This page took 0.060374 seconds and 4 git commands to generate.