Bug 26800 - [readnow] symtabs not expanded when re-reading
Summary: [readnow] symtabs not expanded when re-reading
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 12.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-28 12:19 UTC by Tom de Vries
Modified: 2021-12-07 06:53 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 Tom de Vries 2020-10-28 12:19:36 UTC
There's a group of FAILs with -readnow:
...
FAIL: gdb.ada/exec_changed.exp: start second
FAIL: gdb.ada/exec_changed.exp: start just first
FAIL: gdb.base/reread.exp: opts= "" "" : run to foo() second time
FAIL: gdb.base/reread.exp: opts= "" "" : second pass: run to foo() second time
FAIL: gdb.base/reread.exp: opts= "-fPIE" "ldflags=-pie" : run to foo() second time
FAIL: gdb.base/reread.exp: opts= "-fPIE" "ldflags=-pie" : second pass: run to foo() second time
...

This FAIL:
...
FAIL: gdb.base/reread.exp: opts= "" "" : run to foo() second time
...
can be reproduced a follows.

First, run the test-case.  Then rename the reread exec to the original name:
...
$ mv outputs/gdb.base/reread/reread outputs/gdb.base/reread/reread2
...
such that we have:
...
$ ls -1 outputs/gdb.base/reread/reread*
outputs/gdb.base/reread/reread1
outputs/gdb.base/reread/reread2
...

Then, do a run without -readnow for contrast:
...
$ gdb -batch \
    -ex "shell cp outputs/gdb.base/reread/reread1 reread" \
    -ex "file reread" \
    -ex "b foo" \
    -ex run \
    -ex "shell rm reread" \
    -ex "shell cp outputs/gdb.base/reread/reread2 reread" \
    -ex "shell sleep 1" \
    -ex run
Breakpoint 1 at 0x654: file /home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.base/reread1.c, line 14.

Breakpoint 1, foo () at /home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.base/reread1.c:14
14        x++;
`/home/vries/gdb_versions/devel/reread' has changed; re-reading symbols.

Breakpoint 1, foo () at /home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.base/reread2.c:9
9         x++;
...
Note that the second time we hit foo, it shows foo at reread2.c:9.

With -readnow however, the second time we hit foo, no file/lineno is shown:
...
Breakpoint 1 at 0x654: file /home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.base/reread1.c, line 14.

Breakpoint 1, foo () at /home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.base/reread1.c:14
14        x++;
`/home/vries/gdb_versions/devel/reread' has changed; re-reading symbols.

Breakpoint 1, 0x000055555555468e in foo ()
...
Comment 1 Tom de Vries 2020-10-28 12:21:06 UTC
Tentative patch (code copied from symbol_file_add_with_addrs):
...
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 3332e7f69f..2d00cab743 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2586,6 +2586,12 @@ reread_symbols (void)
 
          read_symbols (objfile, 0);
 
+         if ((objfile->flags & OBJF_READNOW))
+           {
+             if (objfile->sf)
+               objfile->sf->qf->expand_all_symtabs (objfile);
+           }
+
          if (!objfile_has_symbols (objfile))
            {
              wrap_here ("");
...
Comment 2 Tom Tromey 2020-11-01 17:44:58 UTC
We've see a number of bugs come about because reread_symbols
imperfectly duplicates the logic of symbol reading.
It would be more robust to just drop the objfile and reread it.
Comment 3 Tom de Vries 2021-10-11 14:56:42 UTC
Patch posted: https://sourceware.org/pipermail/gdb-patches/2021-October/182488.html