From 48e9cc84058771da089a2e8e652f70ac20a8fac0 Mon Sep 17 00:00:00 2001 From: Philippe Waroquiers Date: Sat, 23 May 2020 14:54:31 +0200 Subject: Ensure 'exec-file has changed' check has priority over 'exec-file-mismatch' check Following the implementation of exec-file-mismatch based on build-id, an attach to a process that runs a modified exec-file was triggering the exec-file-mismatch handling, giving a warning such as: warning: Mismatch between current exec-file /bd/home/philippe/gdb/git/build_termours/gdb/testsuite/outputs/gdb.base/attach/attach and automatically determined exec-file /bd/home/philippe/gdb/git/build_termours/gdb/testsuite/outputs/gdb.base/attach/attach exec-file-mismatch handling is currently "ask" as the build-ids differ when an exec-file is recompiled. This patch ensures that the exec-file-mismatch check is done with an up to date build-id. With this, exec-file-mismatch check will only trigger when the PID file really differs from the (build-id refreshed) current exec-file. Note that the additional check does not (yet) reload the symbols if the exec-file is changed: this reload will happen later if needed. gdb/ChangeLog 2020-06-21 Philippe Waroquiers * exec.c (validate_exec_file): Ensure the build-id is up to date by calling reopen_exec_file (that checks file timestamp to decide to re-read the file). gdb/testsuite/ChangeLog 2020-06-21 Philippe Waroquiers * gdb.base/attach.exp: Test priority of 'exec-file' changed over 'exec-file-mismatch'. * gdb.base/attach.c: Mark should_exit volatile. * gdb.base/attach2.c: Likewise. Add a comment explaining why the sleep cannot be big. * gdb.base/attach3.c: New file. --- gdb/exec.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gdb/exec.c') diff --git a/gdb/exec.c b/gdb/exec.c index ee13c5e..fa770c6 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -256,6 +256,14 @@ validate_exec_file (int from_tty) /* Try validating via build-id, if available. This is the most reliable check. */ + + /* In case current_exec_file was changed, reopen_exec_file ensures + an up to date build_id (will do nothing if the file timestamp + did not change). If exec file changed, reopen_exec_file has + allocated another file name, so get_exec_file again. */ + reopen_exec_file (); + current_exec_file = get_exec_file (0); + const bfd_build_id *exec_file_build_id = build_id_bfd_get (exec_bfd); if (exec_file_build_id != nullptr) { -- cgit v1.1