[PATCH v4 1/1] gdb, infcmd: Support jump command with same line in multiple symtabs

Eli Zaretskii eliz@gnu.org
Wed May 10 12:15:14 GMT 2023


> Cc: aburgess@redhat.com
> Date: Wed, 10 May 2023 13:12:30 +0200
> From: Matti Puputti via Gdb-patches <gdb-patches@sourceware.org>
> 
> If a header file defining a static function is included in multiple source
> files, each calling the function, and GDB is asked to jump to a line inside
> that function, there would be multiple locations matching the target.  The
> solution in this commit is to select the location in the current symtab.
> ---
>  gdb/doc/gdb.texinfo                           |  5 +-
>  gdb/infcmd.c                                  | 13 ++++-
>  .../gdb.base/jump_multiple_objfiles-foo.c     | 24 +++++++++
>  .../gdb.base/jump_multiple_objfiles.c         | 30 +++++++++++
>  .../gdb.base/jump_multiple_objfiles.exp       | 54 +++++++++++++++++++
>  .../gdb.base/jump_multiple_objfiles.h         | 30 +++++++++++
>  6 files changed, 153 insertions(+), 3 deletions(-)
>  create mode 100755 gdb/testsuite/gdb.base/jump_multiple_objfiles-foo.c
>  create mode 100755 gdb/testsuite/gdb.base/jump_multiple_objfiles.c
>  create mode 100755 gdb/testsuite/gdb.base/jump_multiple_objfiles.exp
>  create mode 100755 gdb/testsuite/gdb.base/jump_multiple_objfiles.h
> 
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 4ae84ec5a63..921cff16597 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -20586,8 +20586,9 @@ an address of your own choosing, with the following commands:
>  Resume execution at the address of the code location that results from
>  resolving @var{locspec}.
>  @xref{Location Specifications}, for a description of the different
> -forms of @var{locspec}.  If @var{locspec} resolves to more than one
> -address, the command aborts before jumping.
> +forms of @var{locspec}.  If @var{locspec} resolves to more than one address,
> +those outside the current compilation unit are ignored.  If still not a
> +unique address found, the command aborts before jumping.

Thanks.  The last sentence reads awkwardly in English, so I suggest to
rephrase:

  If considering just the addresses in the current compilation unit
  still doesn't yield a unique address, the command aborts before
  jumping.

> --- a/gdb/infcmd.c
> +++ b/gdb/infcmd.c
> @@ -1070,7 +1070,18 @@ jump_command (const char *arg, int from_tty)
>    std::vector<symtab_and_line> sals
>      = decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
>    if (sals.size () != 1)
> -    error (_("Unreasonable jump request"));
> +    {
> +      /* If multiple sal-objects were found, try dropping those that aren't
> +	 from the current symtab.  */
> +      struct symtab_and_line cursal = get_current_source_symtab_and_line ();
> +      sals.erase (std::remove_if (sals.begin (), sals.end (),
> +		  [&] (const symtab_and_line &sal)
> +		    {
> +		      return sal.symtab != cursal.symtab;
> +		    }), sals.end ());
> +      if (sals.size () != 1)
> +	error (_("Unreasonable jump request"));

I wonder whether, while we are at that, we could make this error
message less vague.  How about

  Jump request is ambiguous: does not resolve to a single address

Reviewed-By: Eli Zaretskii <eliz@gnu.org>


More information about the Gdb-patches mailing list