From f9775d16c502ab5b6806510bc267d943bfde465f948f0d3874fa51e70d73b0b1 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Thu, 7 May 2020 17:55:58 +0000 Subject: [PATCH] Accepting request 801284 from home:tomdevries:branches:devel:gcc-gdb-debug-types - Fix .debug_types problems [swo#24480, swo#25889, bsc#1168394]. - gdb-fix-range-loop-index-in-find_method.patch - gdb-fix-toplevel-types-with-fdebug-types-section.patch OBS-URL: https://build.opensuse.org/request/show/801284 OBS-URL: https://build.opensuse.org/package/show/devel:gcc/gdb?expand=0&rev=249 --- gdb-fix-range-loop-index-in-find_method.patch | 133 ++++++++++++++++++ ...evel-types-with-fdebug-types-section.patch | 124 ++++++++++++++++ gdb.changes | 7 + gdb.spec | 4 + 4 files changed, 268 insertions(+) create mode 100644 gdb-fix-range-loop-index-in-find_method.patch create mode 100644 gdb-fix-toplevel-types-with-fdebug-types-section.patch diff --git a/gdb-fix-range-loop-index-in-find_method.patch b/gdb-fix-range-loop-index-in-find_method.patch new file mode 100644 index 0000000..de901db --- /dev/null +++ b/gdb-fix-range-loop-index-in-find_method.patch @@ -0,0 +1,133 @@ +[gdb] Fix range loop index in find_method + +With target board debug-types, we have: +... +FAIL: gdb.cp/cpexprs.exp: list policy1::function +... + +This is a regression triggered by commit 770479f223e "gdb: Fix toplevel types +with -fdebug-types-section". + +However, the FAIL is caused by commit 4dedf84da98 "Change +decode_compound_collector to use std::vector" which changes a VEC_iterate loop +into a range loop: +... +- for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix) ++ unsigned int ix = 0; ++ for (const auto &sym : *sym_classes) +... +but fails to ensure that the increment of ix happens every iteration. + +Fix this by calculating the index variable at the start of the loop body: +... + for (const auto &elt : *sym_classes) + { + unsigned int ix = &elt - &*sym_classes->begin (); +... + +Tested on x86_64-linux, with native and target board debug-types. + +gdb/ChangeLog: + +2020-04-29 Tom de Vries + + PR symtab/25889 + * linespec.c (find_method): Fix ix calculation. + +gdb/testsuite/ChangeLog: + +2020-04-29 Tom de Vries + + PR symtab/25889 + * gdb.cp/cpexprs.exp: Adapt for inclusion. + * gdb.cp/cpexprs-debug-types.exp: New file. Set -fdebug-types-section + and include cpexprs.exp. + +--- + gdb/linespec.c | 3 +-- + gdb/testsuite/gdb.cp/cpexprs-debug-types.exp | 20 ++++++++++++++++++++ + gdb/testsuite/gdb.cp/cpexprs.exp | 14 ++++++++++++-- + 5 files changed, 45 insertions(+), 4 deletions(-) + +diff --git a/gdb/linespec.c b/gdb/linespec.c +index e902b11c8e8..2231a5674c8 100644 +--- a/gdb/linespec.c ++++ b/gdb/linespec.c +@@ -3680,12 +3680,12 @@ find_method (struct linespec_state *self, std::vector *file_symtabs, + because we collect data across the program space before deciding + what to do. */ + last_result_len = 0; +- unsigned int ix = 0; + for (const auto &elt : *sym_classes) + { + struct type *t; + struct program_space *pspace; + struct symbol *sym = elt.symbol; ++ unsigned int ix = &elt - &*sym_classes->begin (); + + /* Program spaces that are executing startup should have + been filtered out earlier. */ +@@ -3716,7 +3716,6 @@ find_method (struct linespec_state *self, std::vector *file_symtabs, + + superclass_vec.clear (); + last_result_len = result_names.size (); +- ++ix; + } + } + +diff --git a/gdb/testsuite/gdb.cp/cpexprs-debug-types.exp b/gdb/testsuite/gdb.cp/cpexprs-debug-types.exp +new file mode 100644 +index 00000000000..9499aecf4c6 +--- /dev/null ++++ b/gdb/testsuite/gdb.cp/cpexprs-debug-types.exp +@@ -0,0 +1,20 @@ ++# 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 . ++ ++# This file is part of the gdb testsuite. ++ ++# Run cpexprs.exp with -fdebug-types-section. ++set flags {additional_flags=-fdebug-types-section} ++source $srcdir/$subdir/cpexprs.exp +diff --git a/gdb/testsuite/gdb.cp/cpexprs.exp b/gdb/testsuite/gdb.cp/cpexprs.exp +index ecf3a2fbc8d..618388cef3d 100644 +--- a/gdb/testsuite/gdb.cp/cpexprs.exp ++++ b/gdb/testsuite/gdb.cp/cpexprs.exp +@@ -690,13 +690,23 @@ if { [istarget "spu*-*-*"] } { + # test running programs + # + +-standard_testfile .cc ++standard_testfile cpexprs.cc + + if {[get_compiler_info "c++"]} { + return -1 + } + +-if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { ++if { [info exists flags] } { ++ # Already set externally. ++} else { ++ # Initialize to empty. ++ set flags {} ++} ++ ++# Include required flags. ++set flags "$flags debug c++" ++ ++if {[prepare_for_testing "failed to prepare" $testfile $srcfile "$flags"]} { + return -1 + } + diff --git a/gdb-fix-toplevel-types-with-fdebug-types-section.patch b/gdb-fix-toplevel-types-with-fdebug-types-section.patch new file mode 100644 index 0000000..3a89148 --- /dev/null +++ b/gdb-fix-toplevel-types-with-fdebug-types-section.patch @@ -0,0 +1,124 @@ +gdb: Fix toplevel types with -fdebug-types-section + +When debugging a program compiled with -fdebug-types-section, +only the first top-level type in each file is visible to gdb. + +The problem was caused by moving the assignment to list_in_scope +from process_full_comp_unit and process_full_type_unit to +start_symtab. This was fine for process_full_comp_unit, because +symtabs and comp units are one-to-one. But there can be many type +units per symtab (one for each type), and we only call start_symtab +for the first one. This adds the necessary assignments on the paths +where start_symtab is not called. + +gdb/Changelog: + +2020-04-28 Mark Williams + + PR gdb/24480 + * dwarf2read.c: Add missing assingments to list_in_scope when + start_symtab was already called. + +gdb/testsuite/Changelog: + +2020-04-28 Mark Williams + + PR gdb/24480 + * dw4-toplevel-types.exp: Test for top level types. + * dw4-toplevel-types.cc: Test for top level types. + +--- + gdb/dwarf2read.c | 2 ++ + gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.cc | 21 +++++++++++++++ + gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.exp | 36 +++++++++++++++++++++++++ + 3 files changed, 59 insertions(+) + +diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c +index 4251ed03b46..7e6f1a0ff62 100644 +--- a/gdb/dwarf2read.c ++++ b/gdb/dwarf2read.c +@@ -11666,6 +11666,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) + COMPUNIT_DIRNAME (cust), + compunit_language (cust), + 0, cust)); ++ list_in_scope = get_builder ()->get_file_symbols (); + } + return; + } +@@ -11717,6 +11718,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) + COMPUNIT_DIRNAME (cust), + compunit_language (cust), + 0, cust)); ++ list_in_scope = get_builder ()->get_file_symbols (); + + for (i = 0; i < line_header->file_names.size (); ++i) + { +diff --git a/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.cc b/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.cc +new file mode 100644 +index 00000000000..c47598c46ef +--- /dev/null ++++ b/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.cc +@@ -0,0 +1,21 @@ ++/* 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 . */ ++ ++struct X {} x; ++struct Y {} y; ++struct Z {} z; ++int main() {} +diff --git a/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.exp b/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.exp +new file mode 100644 +index 00000000000..8e3875ad71e +--- /dev/null ++++ b/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.exp +@@ -0,0 +1,36 @@ ++# 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 dwarf4 signatured types (DW_TAG_type_unit). ++ ++standard_testfile .cc ++ ++# This test is intended for targets which support DWARF-4. ++# Since we pass an explicit -gdwarf-4 -fdebug-types-section to the compiler, ++# we let that be the test of whether the target supports it. ++ ++if { [prepare_for_testing "failed to prepare" "${testfile}" \ ++ $srcfile {debug c++ additional_flags=-gdwarf-4 \ ++ additional_flags=-fdebug-types-section}] } { ++ return -1 ++} ++ ++if ![runto_main] { ++ return -1 ++} ++ ++gdb_test "ptype X" "type = struct X {.*" ++gdb_test "ptype Y" "type = struct Y {.*" ++gdb_test "ptype Z" "type = struct Z {.*" diff --git a/gdb.changes b/gdb.changes index 3cc99fe..65d1881 100644 --- a/gdb.changes +++ b/gdb.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Wed May 6 03:46:31 UTC 2020 - Tom de Vries + +- Fix .debug_types problems [swo#24480, swo#25889, bsc#1168394]. + - gdb-fix-range-loop-index-in-find_method.patch + - gdb-fix-toplevel-types-with-fdebug-types-section.patch + ------------------------------------------------------------------- Mon Apr 20 14:29:12 UTC 2020 - Tom de Vries diff --git a/gdb.spec b/gdb.spec index d84f6e1..bef0ae1 100644 --- a/gdb.spec +++ b/gdb.spec @@ -253,6 +253,8 @@ Patch2014: gdb-arch13-2.diff Patch2015: gdb-arch13-3.diff Patch2016: bfd-change-num_group-to-unsigned-int.patch Patch2017: gdb-fix-incorrect-use-of-is-operator-for-comparison-in-python-lib-gdb-command-prompt.py.patch +Patch2018: gdb-fix-toplevel-types-with-fdebug-types-section.patch +Patch2019: gdb-fix-range-loop-index-in-find_method.patch # Proposed patch for PR symtab/24971 Patch2500: gdb-symtab-prefer-var-def-over-decl.patch @@ -614,6 +616,8 @@ find -name "*.info*"|xargs rm -f %patch2015 -p1 %patch2016 -p1 %patch2017 -p1 +%patch2018 -p1 +%patch2019 -p1 %patch2500 -p1 %patch2501 -p1