Bug 31971 - Loading a saved record file asserts if we try to execute the inferior
Summary: Loading a saved record file asserts if we try to execute the inferior
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: record (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 15.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-11 17:29 UTC by Guinevere Larsen
Modified: 2024-07-15 16:25 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guinevere Larsen 2024-07-11 17:29:52 UTC
This is a regression from GDB 9

Since GDB started supporting multi-targets, we need to provide a PID to execute the inferior. The record subsystem was updated to save the ptid of the recorded inferior and use it, but resuming from a recording never got this update. This means that a fresh GDB session loading a precsave file would never populate the ptid field, and GDB asserts like so:

../../gdb/inferior.c:293: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

Our testsuite never picked this up because if you load the precsave in a session that has already set the recorded ptid, things just work, and none of the precsave tests try a clean_restart to exercise a fresh session.

I'm opening this bug so we can backport the solution (once accepted) for a GDB 15.2 release
Comment 1 Sourceware Commits 2024-07-15 14:31:48 UTC
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=25c228409597bcb7114a9a839ac08db0ba995418

commit 25c228409597bcb7114a9a839ac08db0ba995418
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Mon Jul 15 16:29:36 2024 +0200

    Fix loading a saved recording
    
    Currently you get this assertion failure if you try to execute the
    inferior after loading a saved recording, when no recording was done
    earlier in the same gdb session:
    ```
    $ gdb -q c -ex "record restore test.rec"
    Reading symbols from c...
    [New LWP 26428]
    Core was generated by `/tmp/c'.
    Restored records from core file /tmp/test.rec.
    (gdb) c
    Continuing.
    ../../gdb/inferior.c:293: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    ```
    
    The change in step-precsave.exp triggers this bug, since now the
    recording is loaded in a new gdb session, where
    record_full_resume_ptid was never set.
    
    The fix is to simply set record_full_resume_ptid when resuming a loaded
    recording.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31971
    Approved-By: Guinevere Larsen <blarsen@redhat.com>
Comment 2 Hannes Domani 2024-07-15 14:35:01 UTC
Fixed.
Comment 3 Sourceware Commits 2024-07-15 16:25:16 UTC
The gdb-15-branch branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e7c91a1ff9e0f87f79f630296219765a6ab1f3e3

commit e7c91a1ff9e0f87f79f630296219765a6ab1f3e3
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Mon Jul 15 16:29:36 2024 +0200

    Fix loading a saved recording
    
    Currently you get this assertion failure if you try to execute the
    inferior after loading a saved recording, when no recording was done
    earlier in the same gdb session:
    ```
    $ gdb -q c -ex "record restore test.rec"
    Reading symbols from c...
    [New LWP 26428]
    Core was generated by `/tmp/c'.
    Restored records from core file /tmp/test.rec.
    (gdb) c
    Continuing.
    ../../gdb/inferior.c:293: internal-error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    ```
    
    The change in step-precsave.exp triggers this bug, since now the
    recording is loaded in a new gdb session, where
    record_full_resume_ptid was never set.
    
    The fix is to simply set record_full_resume_ptid when resuming a loaded
    recording.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31971
    Approved-By: Guinevere Larsen <blarsen@redhat.com>