gdb, infcmd: support jump command in multi-inferior case

Fixes the issue where jump failed if multiple inferiors run the same
source.

See the below example

    $ gdb -q ./simple
    Reading symbols from ./simple...
    (gdb) break 2
    Breakpoint 1 at 0x114e: file simple.c, line 2.
    (gdb) run
    Starting program: /temp/simple

    Breakpoint 1, main () at simple.c:2
    2         int a = 42;
    (gdb) add-inferior
    [New inferior 2]
    Added inferior 2 on connection 1 (native)
    (gdb) inferior 2
    [Switching to inferior 2 [<null>] (<noexec>)]
    (gdb) info inferiors
      Num  Description       Connection           Executable
      1    process 6250      1 (native)           /temp/simple
    * 2    <null>            1 (native)
    (gdb) file ./simple
    Reading symbols from ./simple...
    (gdb) run
    Starting program: /temp/simple

    Thread 2.1 "simple" hit Breakpoint 1, main () at simple.c:2
    2         int a = 42;
    (gdb) info inferiors
      Num  Description       Connection           Executable
      1    process 6250      1 (native)           /temp/simple
    * 2    process 6705      1 (native)           /temp/simple
    (gdb) jump 3
    Unreasonable jump request
    (gdb)

In this example, jump fails because the debugger finds two different
locations, one for each inferior.

Solution is to limit the search to the current program space.

This is done by having the jump_command function use
decode_line_with_current_source rather than
decode_line_with_last_displayed, which makes sense,
the *_current_source function always looks up a location based on the
current thread's location -- if a user is asking the current thread to
jump, then surely their destination should be relative to where the
current thread is located.

Then, inside decode_line_with_current_source, the call to
decode_line_1 is updated to pass through the current program_space,
which will limit the returned locations to those in the current
program space.

Approved-By: Andrew Burgess <aburgess@redhat.com>
This commit is contained in:
Puputti, Matti
2023-07-26 12:29:15 +00:00
committed by Andrew Burgess
parent ba22cd5e88
commit da1f552dc7
3 changed files with 97 additions and 87 deletions

View File

@ -1068,7 +1068,7 @@ jump_command (const char *arg, int from_tty)
error_no_arg (_("starting address"));
std::vector<symtab_and_line> sals
= decode_line_with_last_displayed (arg, DECODE_LINE_FUNFIRSTLINE);
= decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE);
if (sals.size () != 1)
{
/* If multiple sal-objects were found, try dropping those that aren't