]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: use archive name in warning when appropriate
authorAndrew Burgess <aburgess@redhat.com>
Sat, 23 Sep 2023 13:29:40 +0000 (14:29 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 5 Oct 2023 11:21:45 +0000 (12:21 +0100)
While working on some other patch I noticed that in reread_symbols
there is a diagnostic message that can be printed, and in some cases
we might use the wrong filename in the message.

The code in question is checking to see if an objfile has changed on
disk, we do this by stat-ing the on disk file and checking the mtime.
If this file has been removed from disk then we print a message that
the file has been removed, however, if the objfile is within an
archive then we stat the archive itself, but then warn that the
component within the archive has disappeared.  I think it makes more
sense to say that the archive has disappeared.

The last related commit is this one:

  commit 02aeec7bde8ec8a04d14a5637e75f1c6ab899e23
  Date:   Tue Apr 27 21:01:30 2010 +0000

      Check library name rather than member name when rereading symbols.

Though this just makes the code to stat the archive unconditional, the
code in question existed before this commit.

However, the above commit doesn't include any tests, and seems to
indicate that the problem being addressed was seen on Darwin.  I'm not
sure how to setup a test where GDB is using an objfile from within an
archive, and so there's no tests for this commit...

... but if someone can let me know how I can setup a suitable test,
please let me know and I'll try to get something working.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/symfile.c

index 0338825d3fbcd3c777d1725bd1d722ab90a983c8..ff8a3fd0bc55a5ab21026c084ad86d0639b47a69 100644 (file)
@@ -2479,18 +2479,19 @@ reread_symbols (int from_tty)
         `ar', often called a `static library' on most systems, though
         a `shared library' on AIX is also an archive), then you should
         stat on the archive name, not member name.  */
-      int res;
-      struct stat new_statbuf;
+      const char *filename;
       if (objfile->obfd->my_archive)
-       res = stat (bfd_get_filename (objfile->obfd->my_archive), &new_statbuf);
+       filename = bfd_get_filename (objfile->obfd->my_archive);
       else
-       res = stat (objfile_name (objfile), &new_statbuf);
+       filename = objfile_name (objfile);
+
+      struct stat new_statbuf;
+      int res = stat (filename, &new_statbuf);
       if (res != 0)
        {
          /* FIXME, should use print_sys_errmsg but it's not filtered.  */
          gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"),
-                     styled_string (file_name_style.style (),
-                                    objfile_name (objfile)));
+                     styled_string (file_name_style.style (), filename));
          continue;
        }
       time_t new_modtime = new_statbuf.st_mtime;