From patchwork Fri Jun 8 12:39:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 27715 Received: (qmail 96626 invoked by alias); 8 Jun 2018 12:53:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 96608 invoked by uid 89); 8 Jun 2018 12:53:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Jun 2018 12:53:48 +0000 Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 14E74AEB3; Fri, 8 Jun 2018 12:40:30 +0000 (UTC) From: Petr Tesarik To: gdb-patches@sourceware.org Cc: Simon Marchi , John Baldwin , Petr Tesarik , Jeff Mahoney Subject: [PATCH 2/4] Make add-symbol-file's address argument optional Date: Fri, 8 Jun 2018 14:39:58 +0200 Message-Id: <20180608124000.10668-3-ptesarik@suse.cz> In-Reply-To: <20180608124000.10668-1-ptesarik@suse.cz> References: <20180608124000.10668-1-ptesarik@suse.cz> X-IsSubscribed: yes From: Petr Tesarik 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-08 Petr Tesarik * symfile.c (add_symbol_file_command): Do not require the second argument. If omitted, load sections at the addresses specified in the file. gdb/doc/ChangeLog: 2018-06-08 Petr Tesarik * gdb.texinfo (Files): The address argument for "add-symbol-file" is no longer mandatory. gdb/testsuite/ChangeLog: 2018-06-08 Petr Tesarik * gdb.base/relocate.exp: Test add-symbol-file behavior when the address argument is omitted. --- gdb/ChangeLog | 2 ++ gdb/doc/ChangeLog | 2 ++ gdb/doc/gdb.texinfo | 13 ++++++++----- gdb/symfile.c | 23 +++++++++++------------ gdb/testsuite/ChangeLog | 2 ++ gdb/testsuite/gdb.base/relocate.exp | 15 +++++++++++++++ 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 27c6ed0a7c..e6e763b506 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -3,6 +3,8 @@ * symfile.c (symbol_file_command, symbol_file_add_main_1) (_initialize_symfile): Add option "-o" to symbol-file to add an offset to each section of the symbol file. + (add_symbol_file_command): Do not require the second argument. If + omitted, load sections at the addresses specified in the file. 2018-06-07 Pedro Alves diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 319d06a25f..7ddf5b0e9d 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,6 +1,8 @@ 2018-06-08 Petr Tesarik * gdb.texinfo (Files): Document "symbol-file -o offset". + (Files): The address argument for "add-symbol-file" is no longer + mandatory. 2018-06-05 Tom Tromey diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 9d1c29612b..b83ce052e7 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18917,18 +18917,21 @@ 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{[} @var{address} @r{]} +@itemx add-symbol-file @var{filename} @r{[} @var{address} @r{]} @r{[} -readnow @r{|} -readnever @r{]} +@itemx add-symbol-file @var{filename} @r{[} @var{address} @r{]} -s @var{section} @var{address} @dots{} 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 +address at which the file has been loaded. +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. +If @var{address} is omitted, @value{GDBN} will use the section +addresses found in @var{filename}. You can use @samp{-s} to +override this default and load a section at a different address. 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 diff --git a/gdb/symfile.c b/gdb/symfile.c index 09344f83d2..d319bb0564 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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_opts) + std::vector::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.size () == 0) + 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.size () == 0) + printf_unfiltered ("\n"); if (from_tty && (!query ("%s", ""))) error (_("Not confirmed.")); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index a9e0ec09ff..ffd97e66b9 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,6 +1,8 @@ 2018-06-08 Petr Tesarik * gdb.base/relocate.exp: Add test for "symbol-file -o ". + Test add-symbol-file behavior when the address argument is + omitted. 2018-06-05 Tom Tromey diff --git a/gdb/testsuite/gdb.base/relocate.exp b/gdb/testsuite/gdb.base/relocate.exp index 77f6a88159..a3af8cea61 100644 --- a/gdb/testsuite/gdb.base/relocate.exp +++ b/gdb/testsuite/gdb.base/relocate.exp @@ -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 equivallent 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\"" \