From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28372 invoked by alias); 24 Jul 2003 15:17:58 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 28364 invoked from network); 24 Jul 2003 15:17:58 -0000 Received: from unknown (HELO mail.drexel.edu) (144.118.25.40) by sources.redhat.com with SMTP; 24 Jul 2003 15:17:58 -0000 Received: from shim2.irt.drexel.edu (shim2.irt.drexel.edu [144.118.25.82]) by mail.drexel.edu (Sun Internet Mail Server sims.4.0.2001.07.26.11.50.p9) with ESMTP id <0HIJ002X5BTVWR@mail.drexel.edu> for gdb@sources.redhat.com; Thu, 24 Jul 2003 11:17:55 -0400 (EDT) Received: from conversion-daemon.shim2.irt.drexel.edu by shim2.irt.drexel.edu (iPlanet Messaging Server 5.2 HotFix 1.17 (built Jun 23 2003)) id <0HIJ00601BIRS4@shim2.irt.drexel.edu>; Thu, 24 Jul 2003 11:17:55 -0400 (EDT) Received: from glue.irt.drexel.edu (glue.irt.drexel.edu [144.118.25.22]) by shim2.irt.drexel.edu (iPlanet Messaging Server 5.2 HotFix 1.17 (built Jun 23 2003)) with ESMTP id <0HIJ005DFBTTI7@shim2.irt.drexel.edu>; Thu, 24 Jul 2003 11:17:53 -0400 (EDT) Received: from drexel.edu (codem-vpn.trueposition.com [63.97.186.231] (may be forged)) (authenticated) by glue.irt.drexel.edu (8.11.3/8.11.3) with ESMTP id h6OFHqN14274; Thu, 24 Jul 2003 11:17:52 -0400 (EDT) Date: Thu, 24 Jul 2003 15:17:00 -0000 From: Nikola Kolev Subject: Re: gdb shows source line multiple times before executing !! In-reply-to: To: mohanlal jangir Cc: gdb@sources.redhat.com Message-id: <3F1FF7E7.1040803@drexel.edu> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 References: <3F1FEF06.20507@drexel.edu> <20030724144832.GA326@nevyn.them.org> X-SW-Source: 2003-07/txt/msg00300.txt.bz2 why don't you take the optimization flags (-ON) out, live the debug flag (-g) in, recompile, fire up the debugger, do your stuff, instead of wasting time, energy, bandwidth, etc. to explain something that is obvious to why it's happening... --Nik mohanlal jangir wrote: >>Because GCC splits the code for the line into multiple parts. Part of >>the line has executed when you step over it, but it may not be >>immediately obvious how. For instance, given: >> a = b + c; >>the first time you step over it may load b and c from memory; the >>second time may add them; and only the third will store the result into >>a. >> >> >hmm... but sometimes it behaves even worse. For example there are two lines >a = b + c; >d = e + f; >then first gdb shows line a = b + c; > that's when it loded b and c from memory, and possibly stored their sum in a temporary register >then d = e + f and then again a = b + >c. And while showing d = e + f first time if I try to print value of a, it >will be some uninitialised (that indicates that a = b + c has not been >executed). > It is uninitialized, because it has not assigned the the sum to a yet, but skipped to load e and f because it determined it will be faster that way (here's where optimization comes to play)... >Then on next "next" command I will see line a = b +c again and >then valute of a will be correct one. > > Well, that's when it assigned a with what you're looking for...