From patchwork Sat Apr 27 15:31:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 32438 Received: (qmail 95516 invoked by alias); 27 Apr 2019 15:31:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 95507 invoked by uid 89); 27 Apr 2019 15:31:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=closer, simonmarchipolymtlca, simon.marchi@polymtl.ca, D*polymtl.ca X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 27 Apr 2019 15:31:41 +0000 Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 1873A1E7B0; Sat, 27 Apr 2019 11:31:40 -0400 (EDT) Subject: Re: [PATCH 1/2] Remove a VEC from ppc-linux-nat.c From: Simon Marchi To: Tom Tromey , gdb-patches@sourceware.org References: <20190427143134.14048-1-tom@tromey.com> <20190427143134.14048-2-tom@tromey.com> <89f81213-c73d-9ed9-8915-cf71487efaba@simark.ca> Message-ID: <58b9e825-f0b6-3fe6-d29c-1edf970ab99c@simark.ca> Date: Sat, 27 Apr 2019 11:31:39 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <89f81213-c73d-9ed9-8915-cf71487efaba@simark.ca> On 2019-04-27 11:23 a.m., Simon Marchi wrote: > Hi Tom, > > LGTM, I just wrote some suggestions below. > > On 2019-04-27 10:31 a.m., Tom Tromey wrote: >> @@ -1758,14 +1757,11 @@ hwdebug_point_cmp (struct ppc_hw_breakpoint *a, struct ppc_hw_breakpoint *b) >> static struct thread_points * >> hwdebug_find_thread_points_by_tid (int tid, int alloc_new) >> { >> - int i; >> - struct thread_points *t; >> - >> - for (i = 0; VEC_iterate (thread_points_p, ppc_threads, i, t); i++) >> + for (thread_points *t : ppc_threads) >> if (t->tid == tid) >> return t; > > Could you add braces to this for, to match our coding style? > >> @@ -2392,22 +2388,22 @@ ppc_linux_thread_exit (struct thread_info *tp, int silent) >> int i; >> int tid = tp->ptid.lwp (); >> struct hw_break_tuple *hw_breaks; >> - struct thread_points *t = NULL, *p; >> + struct thread_points *t = NULL; >> >> if (!have_ptrace_hwdebug_interface ()) >> return; >> >> - for (i = 0; VEC_iterate (thread_points_p, ppc_threads, i, p); i++) >> - if (p->tid == tid) >> + for (i = 0; i < ppc_threads.size (); i++) >> + if (ppc_threads[i].tid == tid) >> { >> - t = p; >> + t = &ppc_threads[i]; >> break; >> } > > Here too? > > I believe this loop could be a range-based one, though it also works like this. Nevermind about this last suggestion, as the value of the `i` variable is required below to do the removal. But actually when looking at the code a bit closer, I am not sure it works, since ppc_threads[i] yields a pointer, so using the '.' operator is not valid. And indeed: /home/simark/src/binutils-gdb/gdb/ppc-linux-nat.c: In function 'void ppc_linux_thread_exit(thread_info*, int)': /home/simark/src/binutils-gdb/gdb/ppc-linux-nat.c:2397:24: error: request for member 'tid' in 'ppc_threads.std::vector<_Tp, _Alloc>::operator[] >(((std::vector::size_type)i))', which is of pointer type '__gnu_cxx::__alloc_traits >::value_type {aka thread_points*}' (maybe you meant to use '->' ?) if (ppc_threads[i].tid == tid) ^~~ /home/simark/src/binutils-gdb/gdb/ppc-linux-nat.c:2399:20: error: cannot convert 'thread_points**' to 'thread_points*' in assignment t = &ppc_threads[i]; ^ Building also points out this error, where you probably meant to use .back (): /home/simark/src/binutils-gdb/gdb/ppc-linux-nat.c: In member function 'virtual void ppc_linux_nat_target::low_new_thread(lwp_info*)': /home/simark/src/binutils-gdb/gdb/ppc-linux-nat.c:2362:23: error: 'class std::vector' has no member named 'last'; did you mean 'at'? p = ppc_threads.last (); ^~~~ Applying this fixup to your patch makes it build for me: From b687773f708d21e04dfe3b7d7094514d4cf8b7b7 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 27 Apr 2019 11:30:58 -0400 Subject: [PATCH] fixup --- gdb/ppc-linux-nat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c index 45cf594ffcac..59e7ca5863f1 100644 --- a/gdb/ppc-linux-nat.c +++ b/gdb/ppc-linux-nat.c @@ -2359,7 +2359,7 @@ ppc_linux_nat_target::low_new_thread (struct lwp_info *lp) return; /* Get a list of breakpoints from any thread. */ - p = ppc_threads.last (); + p = ppc_threads.back (); hw_breaks = p->hw_breaks; /* Copy that thread's breakpoints and watchpoints to the new thread. */ @@ -2394,9 +2394,9 @@ ppc_linux_thread_exit (struct thread_info *tp, int silent) return; for (i = 0; i < ppc_threads.size (); i++) - if (ppc_threads[i].tid == tid) + if (ppc_threads[i]->tid == tid) { - t = &ppc_threads[i]; + t = ppc_threads[i]; break; }