diff options
author | Philippe Waroquiers <philippe.waroquiers@skynet.be> | 2020-05-23 14:54:31 +0200 |
---|---|---|
committer | Philippe Waroquiers <philippe.waroquiers@skynet.be> | 2020-06-21 12:48:18 +0200 |
commit | 48e9cc84058771da089a2e8e652f70ac20a8fac0 (patch) | |
tree | ab910f5040d0a5df7b43afa317c31cc9f0bcd5b9 /gdb/testsuite/gdb.base/attach.exp | |
parent | 160f8a8f32f5566077e4a4b13943bc7c70bc5da2 (diff) | |
download | gdb-48e9cc84058771da089a2e8e652f70ac20a8fac0.zip gdb-48e9cc84058771da089a2e8e652f70ac20a8fac0.tar.gz gdb-48e9cc84058771da089a2e8e652f70ac20a8fac0.tar.bz2 |
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 <philippe.waroquiers@skynet.be>
* 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 <philippe.waroquiers@skynet.be>
* 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.
Diffstat (limited to 'gdb/testsuite/gdb.base/attach.exp')
-rw-r--r-- | gdb/testsuite/gdb.base/attach.exp | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp index 32f72e2..ab2d318 100644 --- a/gdb/testsuite/gdb.base/attach.exp +++ b/gdb/testsuite/gdb.base/attach.exp @@ -17,12 +17,13 @@ if {![can_spawn_for_attach]} { return 0 } -standard_testfile attach.c attach2.c +standard_testfile attach.c attach2.c attach3.c set binfile2 ${binfile}2 +set binfile3 ${binfile}3 set escapedbinfile [string_to_regexp $binfile] #execute_anywhere "rm -f ${binfile} ${binfile2}" -remote_exec build "rm -f ${binfile} ${binfile2}" +remote_exec build "rm -f ${binfile} ${binfile2} ${binfile3}" # For debugging this test # #log_user 1 @@ -41,6 +42,13 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {d return -1 } +# Build the third file, used to check attach when the exec-file has changed. + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile3}" "${binfile3}" executable {debug}] != "" } { + untested "failed to compile attach exec-file changed test" + return -1 +} + if [get_compiler_info] { return -1 } @@ -515,6 +523,7 @@ proc_with_prefix do_attach_exec_mismatch_handling_tests {} { global gdb_prompt global binfile global binfile2 + global binfile3 clean_restart $binfile @@ -577,10 +586,51 @@ proc_with_prefix do_attach_exec_mismatch_handling_tests {} { # Detach the process. gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach attach" + # Test that the 'exec-file' changed is checked before exec-file-mismatch. + set test "mismatch exec-file changed has priority" + gdb_test_no_output "set exec-file-mismatch ask" + gdb_test_multiple "attach $testpid" "$test attach1 again, initial exec-file" { + -re "Attaching to program.*exec-file-mismatch handling is currently \"ask\".*Load new symbol table from .*attach\".*\(y or n\)" { + gdb_test "y" "Reading symbols from .*attach.*" $gdb_test_name + } + } + + + gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach attach initial exec-file" + + # Change the exec-file and attach to a new process using the changed file. + remote_exec build "mv ${binfile} ${binfile}.initial" + remote_exec build "mv ${binfile3} ${binfile}" + # Ensure GDB detects ${binfile} has changed when checking timestamp. + sleep 1 + remote_exec build "touch ${binfile}" + set test_spawn_id3 [spawn_wait_for_attach $binfile] + set testpid3 [spawn_id_get_pid $test_spawn_id3] + + gdb_test "attach $testpid3" "Attaching to program.*attach' has changed; re-reading symbols.*" \ + "$test attach1 again, after changing exec-file" + gdb_test "detach" "Detaching from program: .* detached\\\]" "$test detach after attach changed exec-file" + + # Now, test the situation when current exec-file has changed + # and we attach to a pid using another file. + # Ensure GDB detects ${binfile} has changed when checking timestamp. + sleep 1 + remote_exec build "touch ${binfile}" + + gdb_test_multiple "attach $testpid2" "$test attach2" { + -re "Attaching to program.*exec-file-mismatch handling is currently \"ask\".*Load new symbol table from .*attach2\".*\(y or n\)" { + gdb_test "y" "Reading symbols from .*attach2.*" $gdb_test_name + } + } + + # Restore initial build situation. + remote_exec build "mv ${binfile} ${binfile3}" + remote_exec build "mv ${binfile}.initial ${binfile}" # Don't leave a process around kill_wait_spawned_process $test_spawn_id kill_wait_spawned_process $test_spawn_id2 + kill_wait_spawned_process $test_spawn_id3 } do_attach_tests |