From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id D90BC385DC0C for ; Wed, 29 Apr 2020 09:40:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D90BC385DC0C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 39A9BADDD for ; Wed, 29 Apr 2020 09:40:55 +0000 (UTC) Date: Wed, 29 Apr 2020 11:40:53 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb] Fix range loop index in find_method Message-ID: <20200429094051.GA32042@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-28.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Apr 2020 09:41:07 -0000 Hi, 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. Committed to trunk. Thanks, - Tom [gdb] Fix range loop index in find_method 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 ++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 0eb3bc5b8d4..6e4fe6cb771 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -3670,12 +3670,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. */ @@ -3706,7 +3706,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 e8b898fa111..383def9fb64 100644 --- a/gdb/testsuite/gdb.cp/cpexprs.exp +++ b/gdb/testsuite/gdb.cp/cpexprs.exp @@ -685,13 +685,23 @@ if {[skip_cplus_tests]} { continue } # 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 }