Bug 26006 - rereading symbols fails
Summary: rereading symbols fails
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 10.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-18 03:22 UTC by Andy Owen
Modified: 2020-08-09 20:46 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-05-20 00:00:00


Attachments
gdb script which demonstrates the bug (103 bytes, text/plain)
2020-05-18 03:22 UTC, Andy Owen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Owen 2020-05-18 03:22:21 UTC
Created attachment 12552 [details]
gdb script which demonstrates the bug

I am running v9.1 on amd64 (I compiled it from source in ubuntu
20.20 using the packaged gcc v9.3.0).

This gdb script (also attached) demonstrates the problem:

shell echo "int main(void) { return 0;}" > test.c
shell gcc -g test.c
file a.out
run
shell sleep 1
shell touch a.out
run
quit

When I run this I get:

$ ./gdb -q -x gdb-bug.gdb
[Inferior 1 (process 257896) exited normally]
`/home/andy/gdb-test/bin/a.out' has changed; re-reading symbols.
warning: Probes-based dynamic linker interface failed.
Reverting to original interface.
[Inferior 1 (process 257902) exited normally]

If I change the "shell sleep 1" to "shell sleep 0" then it works as expected:
$ ./gdb -q -x ~/gdb-bug-sleep0.gdb
[Inferior 1 (process 257948) exited normally]
[Inferior 1 (process 257954) exited normally]


In the context of a non-trivial program, whenever I see the "warning:
Probes-based dynamic linker interface failed." message, this tends to mean
that my stack traces will be broken (filled with ???).
Comment 1 Simon Marchi 2020-05-20 01:57:57 UTC
Hi Andy, could you please try the following patch?

It fixes the problem you described for me.  It also fixes gdb.ada/exec_changed.exp, although I haven't run the full testsuite so I don't know if there are regressions.


From 966cd4f85551958bf01c6469db0663f07a0c2610 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@efficios.com>
Date: Tue, 19 May 2020 21:54:24 -0400
Subject: [PATCH] gdb: reset/recompute section offset in reread_symbols

---
 gdb/symfile.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index dd8192a67fbb..4d0a12e533fe 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2543,6 +2543,7 @@ reread_symbols (void)
 	     will need to be called (see discussion below).  */
 	  obstack_free (&objfile->objfile_obstack, 0);
 	  objfile->sections = NULL;
+	  objfile->section_offsets.clear ();
 	  objfile->compunit_symtabs = NULL;
 	  objfile->template_symbols = NULL;
 	  objfile->static_links.reset (nullptr);
@@ -2597,6 +2598,8 @@ reread_symbols (void)
 
 	  objfiles_changed ();
 
+	  objfile->sf->sym_offsets (objfile, {});
+
 	  read_symbols (objfile, 0);
 
 	  if (!objfile_has_symbols (objfile))
-- 
2.26.2
Comment 2 Andy Owen 2020-05-20 02:35:02 UTC
Yes, this fixes the issue at my end.

I will keep on using this version of gdb as my daily driver and let you know if I see anything bad.
Comment 3 Simon Marchi 2020-05-20 02:38:24 UTC
Thanks for testing!
Comment 4 Tom Tromey 2020-08-09 20:46:45 UTC
This patch went in, so I'm closing this.