From 480847e9e63fde4ce4884db1dcb503cc7a3bb849 Mon Sep 17 00:00:00 2001 From: Sergio Durigan Junior Date: Feb 11 2020 20:19:55 +0000 Subject: Fix 'Incorrect printing of source lines (colorized source lines not updated when source reloaded?)' (H. J. Lu, Sergio Durigan Junior, RHBZ 1784210). --- diff --git a/_gdb.spec.Patch.include b/_gdb.spec.Patch.include index 70557ca..9415b78 100644 --- a/_gdb.spec.Patch.include +++ b/_gdb.spec.Patch.include @@ -422,3 +422,12 @@ Patch103: gdb-rhbz1728147-gdb-segfaults-if-working-dir-was-deleted.patch # 1785768). Patch104: gdb-rhbz1785768-revert-basenames_may_differ.patch +# Fix "Incorrect printing of source lines (colorized source lines not +# updated when source reloaded?)" (H.J. Lu, RHBZ 1784210). +Patch105: gdb-rhbz1784210-clear-source-cache-reload-binary-1of2.patch + +# Fix "Incorrect printing of source lines (colorized source lines not +# updated when source reloaded?)" (Sergio Durigan Junior -- testcase, +# RHBZ 1784210). +Patch106: gdb-rhbz1784210-clear-source-cache-reload-binary-2of2.patch + diff --git a/_gdb.spec.patch.include b/_gdb.spec.patch.include index 2e5e265..1b966ef 100644 --- a/_gdb.spec.patch.include +++ b/_gdb.spec.patch.include @@ -102,3 +102,5 @@ %patch102 -p1 %patch103 -p1 %patch104 -p1 +%patch105 -p1 +%patch106 -p1 diff --git a/_patch_order b/_patch_order index 876761f..bad952f 100644 --- a/_patch_order +++ b/_patch_order @@ -102,3 +102,5 @@ gdb-rhbz1553104-s390x-arch12-test.patch gdb-rhbz1765117-fix-core-tui-run.patch gdb-rhbz1728147-gdb-segfaults-if-working-dir-was-deleted.patch gdb-rhbz1785768-revert-basenames_may_differ.patch +gdb-rhbz1784210-clear-source-cache-reload-binary-1of2.patch +gdb-rhbz1784210-clear-source-cache-reload-binary-2of2.patch diff --git a/gdb-rhbz1784210-clear-source-cache-reload-binary-1of2.patch b/gdb-rhbz1784210-clear-source-cache-reload-binary-1of2.patch new file mode 100644 index 0000000..6276b3e --- /dev/null +++ b/gdb-rhbz1784210-clear-source-cache-reload-binary-1of2.patch @@ -0,0 +1,29 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Sergio Durigan Junior +Date: Tue, 11 Feb 2020 15:15:44 -0500 +Subject: gdb-rhbz1784210-clear-source-cache-reload-binary-1of2.patch + +;; Fix "Incorrect printing of source lines (colorized source lines not +;; updated when source reloaded?)" (H.J. Lu, RHBZ 1784210). + +Call forget_cached_source_info to clear the stale source cache + +Clear the stale source cache when re-reading symbols. + + PR gdb/25126 + * symfile.c (reread_symbols): Call forget_cached_source_info to + clear the stale source cache. + +diff --git a/gdb/symfile.c b/gdb/symfile.c +--- a/gdb/symfile.c ++++ b/gdb/symfile.c +@@ -2528,6 +2528,9 @@ reread_symbols (void) + automatically recreated by sym_read. */ + free_objfile_separate_debug (objfile); + ++ /* Clear the stale source cache. */ ++ forget_cached_source_info (); ++ + /* Remove any references to this objfile in the global + value lists. */ + preserve_values (objfile); diff --git a/gdb-rhbz1784210-clear-source-cache-reload-binary-2of2.patch b/gdb-rhbz1784210-clear-source-cache-reload-binary-2of2.patch new file mode 100644 index 0000000..4b8f4b5 --- /dev/null +++ b/gdb-rhbz1784210-clear-source-cache-reload-binary-2of2.patch @@ -0,0 +1,186 @@ +From FEDORA_PATCHES Mon Sep 17 00:00:00 2001 +From: Sergio Durigan Junior +Date: Tue, 11 Feb 2020 15:17:59 -0500 +Subject: gdb-rhbz1784210-clear-source-cache-reload-binary-2of2.patch + +;; Fix "Incorrect printing of source lines (colorized source lines not +;; updated when source reloaded?)" (Sergio Durigan Junior -- testcase, +;; RHBZ 1784210). + +New testcase for PR tui/25126 (staled source cache) + +I'm dealing with a Fedora GDB bug that is related to PR tui/25126, and +I thought I'd write a specific testcase for it because I couldn't find +one. + +The idea is to get the simple reproducer from the bug and tweak the +testcase around it. This one was a bit hard because, since we need to +modify the source file and recompile it, it involved a bit of TCL-foo +to do things. Also for this reason, I'm only enabling the test for +native boards. + +I tested this with an upstream GDB and made sure everything is +passing. I also tested with a faulty GDB and made sure the test +failed. + +gdb/testsuite/ChangeLog: +2020-02-11 Sergio Durigan Junior + + PR tui/25126 + https://bugzilla.redhat.com/show_bug.cgi?id=1784210 + * gdb.base/cached-source-file.c: New file. + * gdb.base/cached-source-file.exp: New file. + +Change-Id: Ib1b074342ebe8613c6d1dfde631691ebdf6d81c6 + +diff --git a/gdb/testsuite/gdb.base/cached-source-file.c b/gdb/testsuite/gdb.base/cached-source-file.c +new file mode 100644 +--- /dev/null ++++ b/gdb/testsuite/gdb.base/cached-source-file.c +@@ -0,0 +1,43 @@ ++/* This testcase is part of GDB, the GNU debugger. ++ ++ Copyright 2020 Free Software Foundation, Inc. ++ ++ This program is free software; you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation; either version 3 of the License, or ++ (at your option) any later version. ++ ++ This program is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with this program. If not, see . */ ++ ++/* Test for PR tui/25126. ++ ++ The bug is about a regression that makes GDB not reload its source ++ code cache when the inferior's symbols are reloaded, which leads to ++ wrong backtraces/listings. ++ ++ This bug is reproducible even without using the TUI. ++ ++ The .exp testcase depends on the line numbers and contents from ++ this file If you change this file, make sure to double-check the ++ testcase. */ ++ ++#include ++ ++void ++foo (void) ++{ ++ printf ("hello\n"); /* break-here */ ++} ++ ++int ++main () ++{ ++ foo (); ++ return 0; ++} +diff --git a/gdb/testsuite/gdb.base/cached-source-file.exp b/gdb/testsuite/gdb.base/cached-source-file.exp +new file mode 100644 +--- /dev/null ++++ b/gdb/testsuite/gdb.base/cached-source-file.exp +@@ -0,0 +1,98 @@ ++# Copyright (C) 2020 Free Software Foundation, Inc. ++ ++# This program is free software; you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3 of the License, or ++# (at your option) any later version. ++# ++# This program is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program. If not, see . ++ ++# Test for PR tui/25126. ++# ++# The bug is about a regression that makes GDB not reload its source ++# code cache when the inferior's symbols are reloaded, which leads to ++# wrong backtraces/listings. ++# ++# This bug is reproducible even without using the TUI. ++ ++standard_testfile ++ ++# Only run on native boards. ++if { [use_gdb_stub] || [target_info gdb_protocol] == "extended-remote" } { ++ return -1 ++} ++ ++# Because we need to modify the source file later, it's better if we ++# just copy it to our output directory (instead of messing with the ++# user's source directory). ++set newsrc [standard_output_file $testfile].c ++file copy -force -- $srcdir/$subdir/$srcfile $newsrc ++set srcfile $newsrc ++ ++if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { ++ return -1 ++} ++ ++# Get the line number for the line with the "break-here" marker. ++set bp_line [gdb_get_line_number "break-here" $srcfile] ++ ++gdb_assert { [runto "$srcfile:$bp_line"] } \ ++ "run to $srcfile:$bp_line" ++ ++# Do a "list" and check that the printed line matches the line of the ++# original source file. ++gdb_test_no_output "set listsize 1" ++gdb_test "list" "$bp_line\[ \t\]+printf \\(\"hello\\\\n\"\\); /\\* break-here \\*/" \ ++ "check the first version of the source file" ++ ++# Modify the original source file, and add an extra line into it. ++# This only works locally because of the TCL commands. ++set bkpsrc [standard_output_file $testfile].c.bkp ++set bkpsrcfd [open $bkpsrc w] ++set srcfd [open $srcfile r] ++ ++while { [gets $srcfd line] != -1 } { ++ if { [string first "break-here" $line] != -1 } { ++ # Put a "printf" line before the "break-here" line. ++ puts $bkpsrcfd " printf (\"foo\\n\"); /* new-marker */" ++ } ++ puts $bkpsrcfd $line ++} ++ ++close $bkpsrcfd ++close $srcfd ++file rename -force -- $bkpsrc $srcfile ++# We have to wait 1 second because of the way GDB checks whether the ++# binary has changed or not. GDB uses stat(2) and currently checks ++# 'st_mtime', whose precision is measured in seconds. Since the copy, ++# rename, and rebuild can take less than 1 second, GDB might mistakenly ++# assume that the binary is unchanged. ++sleep 1 ++ ++# Recompile the modified source. We use "gdb_compile" here instead of ++# "prepare_for_testing" because we don't want to call "clean_restart". ++if { [gdb_compile "${srcfile}" "${binfile}" executable {debug}] != "" } { ++ return -1 ++} ++ ++# Rerun the program. This should not only force GDB to reload the ++# source cache, but also to break at BP_LINE again, which now has ++# different contents. ++gdb_test_multiple "run" "rerun program" { ++ -re {The program being debugged has been started already\.\r\nStart it from the beginning\? \(y or n\) $} { ++ set binregex [string_to_regexp $binfile] ++ gdb_test "y" "\\`$binregex\\' has changed; re-reading symbols\.\r\nStarting program: ${binregex}.*" \ ++ "rerun program" ++ } ++} ++ ++# Again, perform the listing and check that the line indeed has ++# changed for GDB. ++gdb_test "list" "${bp_line}\[ \t\]+printf \\(\"foo\\\\n\"\\); /\\\* new-marker \\\*/.*" \ ++ "verify that the source code is properly reloaded" diff --git a/gdb.spec b/gdb.spec index 5296691..a4e7462 100644 --- a/gdb.spec +++ b/gdb.spec @@ -35,7 +35,7 @@ Version: 8.3.50.%{snapsrc} # The release always contains a leading reserved number, start it at 1. # `upstream' is not a part of `name' to stay fully rpm dependencies compatible for the testing. -Release: 29%{?dist} +Release: 30%{?dist} License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ and GPLv2+ with exceptions and GPL+ and LGPLv2+ and LGPLv3+ and BSD and Public Domain and GFDL # Do not provide URL for snapshots as the file lasts there only for 2 days. @@ -1147,6 +1147,11 @@ fi %endif %changelog +* Tue Feb 11 2020 Sergio Durigan Junior - 8.3.50.20190824-30 +- Fix 'Incorrect printing of source lines (colorized source lines not + updated when source reloaded?)' (H. J. Lu, Sergio Durigan Junior, + RHBZ 1784210). + * Mon Feb 10 2020 Sergio Durigan Junior - 8.3.50.20190824-29 - Remove 'gdb-rhbz1785768-path-breakpoints-resolved-eclipse-cdt.patch'. - Fix 'Paths for breakpoints are not resolved' (Tom Tromey, RHBZ