From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57304 invoked by alias); 12 Oct 2015 14:14:22 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 57289 invoked by uid 89); 12 Oct 2015 14:14:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 12 Oct 2015 14:14:21 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id E5D8936B1F4; Mon, 12 Oct 2015 14:14:19 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9CEEIbN007062; Mon, 12 Oct 2015 10:14:19 -0400 Message-ID: <561BC039.9050708@redhat.com> Date: Mon, 12 Oct 2015 14:14:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Nancy , gdb@sourceware.org Subject: Re: Is that a GDB bug? References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-10/txt/msg00055.txt.bz2 On 10/12/2015 01:46 PM, Nancy wrote: > Hi, > > Why line 5 execute twice? Is that a GDB bug? > > debug.c : > 1 int main() > 2 { > 3 int x; > 4 x=0; > 5 L1: switch(x) { case 0: x=1; goto L1; case 1: if(x==0) > goto L1; else break; } > 6 x=2; > 7 } > > $ gcc -O0 -g debug.c -o debug > $ gdb debug > GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 > Copyright (C) 2014 Free Software Foundation, Inc. > .................... > Reading symbols from debug...done. > (gdb) b 5 > Breakpoint 1 at 0x80483fa: file debug.c, line 5. > (gdb) r > Starting program: /mnt/hgfs/cygwin/tmp/debug > > Breakpoint 1, main () at debug.c:5 > 5 L1: switch(x) { case 0: x=1; goto L1; case 1: if(x==0) goto > L1; else break; } > (gdb) n x starts as 0. So the fist time, "goto L1" is executed. That makes execution flow back to the address where the breakpoint was inserted, so you get another breakpoint hit: > > Breakpoint 1, main () at debug.c:5 > 5 L1: switch(x) { case 0: x=1; goto L1; case 1: if(x==0) goto > L1; else break; } It doesn't matter that "next" was in progress. The breakpoint hit takes priority. > (gdb) n > 6 x=2; > > Thanks, Pedro Alves