From: Simon Marchi <simon.marchi@polymtl.ca>
To: Petr Tesarik <ptesarik@suse.cz>
Cc: gdb-patches@sourceware.org, Jeff Mahoney <jeffm@suse.com>
Subject: Re: [PATCH v2 4/4] Add an optional offset option to the "add-symbol-file" command
Date: Tue, 26 Jun 2018 02:52:00 -0000 [thread overview]
Message-ID: <0061dc594fcb938994c15b6deb389618@polymtl.ca> (raw)
In-Reply-To: <20180611120835.27343-5-ptesarik@suse.cz>
On 2018-06-11 08:08, Petr Tesarik wrote:
> @@ -2195,7 +2206,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.size () == 0)
> + if (seen_offset)
> + printf_unfiltered (_("%s offset by %s\n"),
> + (section_addrs.size () == 0
> + ? _(" with all sections")
> + : _("with other sections")),
> + paddress (gdbarch, offset));
> + else if (section_addrs.size () == 0)
Nice little detail, the message that adapts to how the command was used.
You can use ".empty ()" instead of .size () == 0" (in the previous
patches too).
> printf_unfiltered ("\n");
>
> if (from_tty && (!query ("%s", "")))
> @@ -2204,6 +2221,42 @@ add_symbol_file_command (const char *args, int
> from_tty)
> objf = symbol_file_add (filename.get (), add_flags, §ion_addrs,
> flags);
>
> + if (seen_offset)
> + {
> + std::vector<struct section_offsets> new_offsets
> (objf->num_sections,
> + { offset });
> +
> + std::vector<const struct other_sections *> sect_addrs_sorted
> + = addrs_section_sort (section_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);
> +
> + std::vector<const struct other_sections *>::iterator
> sect_sorted_iter
> + = sect_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 && sect_sorted_iter != sect_addrs_sorted.end ())
> + {
> + const struct other_sections *sect = *sect_sorted_iter;
> + const char *sect_name = addr_section_name (sect->name.c_str
> ());
> + cmp = strcmp (sect_name, objf_name);
> + if (cmp <= 0)
> + ++sect_sorted_iter;
> + }
> +
> + if (cmp == 0)
> + new_offsets[objf_sect->sectindex].offsets[0] = 0;
> + }
> +
> + objfile_relocate (objf, new_offsets.data ());
> + }
> +
Could this new code be in a separate function? This one is starting to
get long.
Also, could you add a bit of comments to explain the intent of the code?
There is a lot of magic going on, it's a bit hard to read.
> diff --git a/gdb/testsuite/gdb.base/relocate.exp
> b/gdb/testsuite/gdb.base/relocate.exp
> index a3af8cea61..119495dd94 100644
> --- a/gdb/testsuite/gdb.base/relocate.exp
> +++ b/gdb/testsuite/gdb.base/relocate.exp
> @@ -235,6 +235,62 @@ set new_function_foo_addr [get_var_address
> function_foo]
> gdb_assert {${new_function_foo_addr} == ${function_foo_addr} +
> $offset} \
> "function foo is moved by offset"
>
> +# Load the object using add-symbol-file with an offset and check that
> +# all addresses are moved by that offset.
> +
> +set offset 0x10000
> +clean_restart
> +gdb_test "add-symbol-file -o $offset $binfile" \
> + "Reading symbols from ${binfile}\.\.\.done\." \
> + "add-symbol-file with offset" \
> + "add symbol table from file \".*${testfile}\\.o\" with all
> sections offset by $offset\[\r\n\]+\\(y or n\\) " \
> + "y"
> +
> +# Make sure the address of a static variable is moved by offset.
> +set new_static_foo_addr [get_var_address static_foo]
> +gdb_assert { ${new_static_foo_addr} == ${static_foo_addr} + $offset }
> \
> + "static variable foo is moved by offset"
> +
> +# Make sure the address of a global variable is moved by offset.
> +set new_global_foo_addr [get_var_address global_foo]
> +gdb_assert { ${new_global_foo_addr} == ${global_foo_addr} + $offset }
> \
> + "global variable foo is moved by offset"
> +
> +# Make sure the address of a function is moved by offset.
> +set new_function_foo_addr [get_var_address function_foo]
> +gdb_assert { ${new_function_foo_addr} == ${function_foo_addr} +
> $offset } \
> + "function foo is moved by offset"
> +
> +# Re-load the object giving an explicit address for .text
> +
> +set text [ format "0x%x" [expr ${function_foo_addr} + 0x20000] ]
> +clean_restart
> +gdb_test "add-symbol-file $binfile -o $offset $text" \
> + "Reading symbols from ${binfile}\.\.\.done\." \
> + "add-symbol-file with offset, text address given" \
> + "add symbol table from file \".*${testfile}\\.o\" at\[
> \t\r\n\]+\.text_addr = ${text}\[\r\n\]+with other sections offset by
> ${offset}\[\r\n\]+\\(y or n\\) " \
> + "y"
> +
> +# Make sure function has a different addresses now.
"has a different addresses" -> "has a different address", repeated a few
times.
Simon
next prev parent reply other threads:[~2018-06-26 2:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-11 12:08 [PATCH v2 0/4] Allow loading symbol files with an offset Petr Tesarik
2018-06-11 12:08 ` [PATCH v2 3/4] Make sure that sorting does not change section order Petr Tesarik
2018-06-26 2:37 ` Simon Marchi
2018-06-26 5:10 ` Petr Tesarik
2018-06-26 13:26 ` Simon Marchi
2018-06-11 12:08 ` [PATCH v2 1/4] Add an optional offset option to the "symbol-file" command Petr Tesarik
2018-06-11 15:23 ` Eli Zaretskii
2018-06-26 2:02 ` Simon Marchi
2018-06-11 12:08 ` [PATCH v2 2/4] Make add-symbol-file's address argument optional Petr Tesarik
2018-06-11 15:25 ` Eli Zaretskii
2018-06-11 16:50 ` Petr Tesarik
2018-06-11 17:25 ` Eli Zaretskii
2018-06-26 2:14 ` Simon Marchi
2018-06-11 12:23 ` [PATCH v2 4/4] Add an optional offset option to the "add-symbol-file" command Petr Tesarik
2018-06-26 2:52 ` Simon Marchi [this message]
2018-06-22 7:52 ` [PATCH v2 0/4] Allow loading symbol files with an offset Petr Tesarik
2018-06-26 2:58 ` Simon Marchi
2018-06-26 5:01 ` Petr Tesarik
2018-06-26 15:15 ` Simon Marchi
2018-06-26 15:23 ` Petr Tesarik
2018-06-27 12:14 ` [PATCH v3 " Petr Tesarik
2018-06-27 12:14 ` [PATCH v3 1/4] Add an optional offset option to the "symbol-file" command Petr Tesarik
2018-06-27 12:14 ` [PATCH v3 2/4] Make add-symbol-file's address argument optional Petr Tesarik
2018-06-27 12:14 ` [PATCH v3 3/4] Make sure that sorting does not change section order Petr Tesarik
2018-06-27 12:33 ` [PATCH v3 4/4] Add an optional offset option to the "add-symbol-file" command Petr Tesarik
2018-06-27 12:57 ` [PATCH v3 0/4] Allow loading symbol files with an offset Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0061dc594fcb938994c15b6deb389618@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=jeffm@suse.com \
--cc=ptesarik@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).