From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17286 invoked by alias); 9 Dec 2011 18:40:24 -0000 Received: (qmail 17266 invoked by uid 22791); 9 Dec 2011 18:40:22 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_GD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 09 Dec 2011 18:40:06 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pB9Idrgr005627 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 9 Dec 2011 13:39:53 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pB9Idr0r009052; Fri, 9 Dec 2011 13:39:53 -0500 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pB9Idp9h027514; Fri, 9 Dec 2011 13:39:51 -0500 From: Tom Tromey To: Jan Kratochvil Cc: Joel Brobecker , gdb-patches@sourceware.org Subject: Re: Crash regression for gdb.base/ending-run.exp [Re: creating the gdb-7.4 branch tomorrow (?)] References: <20111205081911.GG28486@adacore.com> <20111209164653.GA22642@host2.jankratochvil.net> Date: Fri, 09 Dec 2011 19:05:00 -0000 In-Reply-To: <20111209164653.GA22642@host2.jankratochvil.net> (Jan Kratochvil's message of "Fri, 9 Dec 2011 17:46:53 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-12/txt/msg00306.txt.bz2 >>>>> "Jan" == Jan Kratochvil writes: Jan> Regression on Fedoras, such as F-15 x86_64 using .debug_types: Jan> DEJAGNU=$HOME/src/runtest-valgrind/site.exp runtest CC_FOR_TARGET="gcc -gdwarf-4 -fdebug-types-section -g0" CXX_FOR_TARGET="g++ -gdwarf-4 -fdebug-types-section -g0" --target_board valgrind gdb.base/ending-run.exp Thanks. I'm checking in the appended. The bug was that a given breakpoint could end up on the 'found' list more than once. My fix is to remove duplicates from the list. Also I noticed that the VEC created in clear_command was never freed. This patch fixes that as well. Built and regtested on x86-64 F15. I also ran the test above before and after the patch. Tom 2011-12-09 Tom Tromey * breakpoint.c (compare_breakpoints): New function. (clear_command): Remove duplicate breakpoints. Properly clean up. diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d9d5bbe..6f4f2d6 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -10028,18 +10028,41 @@ tcatch_command (char *arg, int from_tty) error (_("Catch requires an event name.")); } +/* A qsort comparison function that sorts breakpoints in order. */ + +static int +compare_breakpoints (const void *a, const void *b) +{ + const breakpoint_p *ba = a; + uintptr_t ua = (uintptr_t) *ba; + const breakpoint_p *bb = b; + uintptr_t ub = (uintptr_t) *bb; + + if ((*ba)->number < (*bb)->number) + return -1; + else if ((*ba)->number > (*bb)->number) + return 1; + + /* Now sort by address, in case we see, e..g, two breakpoints with + the number 0. */ + if (ua < ub) + return -1; + return ub > ub ? 1 : 0; +} + /* Delete breakpoints by address or line. */ static void clear_command (char *arg, int from_tty) { - struct breakpoint *b; + struct breakpoint *b, *prev; VEC(breakpoint_p) *found = 0; int ix; int default_match; struct symtabs_and_lines sals; struct symtab_and_line sal; int i; + struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); if (arg) { @@ -10090,6 +10113,7 @@ clear_command (char *arg, int from_tty) breakpoint. */ found = NULL; + make_cleanup (VEC_cleanup (breakpoint_p), &found); for (i = 0; i < sals.nelts; i++) { /* If exact pc given, clear bpts at that pc. @@ -10143,6 +10167,7 @@ clear_command (char *arg, int from_tty) VEC_safe_push(breakpoint_p, found, b); } } + /* Now go thru the 'found' chain and delete them. */ if (VEC_empty(breakpoint_p, found)) { @@ -10152,6 +10177,21 @@ clear_command (char *arg, int from_tty) error (_("No breakpoint at this line.")); } + /* Remove duplicates from the vec. */ + qsort (VEC_address (breakpoint_p, found), + VEC_length (breakpoint_p, found), + sizeof (breakpoint_p), + compare_breakpoints); + prev = VEC_index (breakpoint_p, found, 0); + for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) + { + if (b == prev) + { + VEC_ordered_remove (breakpoint_p, found, ix); + --ix; + } + } + if (VEC_length(breakpoint_p, found) > 1) from_tty = 1; /* Always report if deleted more than one. */ if (from_tty) @@ -10171,6 +10211,8 @@ clear_command (char *arg, int from_tty) } if (from_tty) putchar_unfiltered ('\n'); + + do_cleanups (cleanups); } /* Delete breakpoint in BS if they are `delete' breakpoints and