From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15896 invoked by alias); 21 May 2007 23:28:27 -0000 Received: (qmail 15887 invoked by uid 22791); 21 May 2007 23:28:25 -0000 X-Spam-Check-By: sourceware.org Received: from hq.tensilica.com (HELO mailapp.tensilica.com) (65.205.227.29) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 21 May 2007 23:28:19 +0000 Received: from localhost ([127.0.0.1]) by mailapp.tensilica.com with esmtp (Exim 4.34) id 1HqHIX-0004DP-9j; Mon, 21 May 2007 16:28:17 -0700 Received: from mailapp.tensilica.com ([127.0.0.1]) by localhost (mailapp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 14466-04; Mon, 21 May 2007 16:28:17 -0700 (PDT) Received: from nose.hq.tensilica.com ([192.168.11.18]) by mailapp.tensilica.com with esmtp (Exim 4.34) id 1HqHIW-0004DJ-QQ; Mon, 21 May 2007 16:28:16 -0700 Message-ID: <46522B10.6090008@tensilica.com> Date: Mon, 21 May 2007 23:28:00 -0000 From: Ross Morley User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040805 Netscape/7.2 MIME-Version: 1.0 To: Maxim Grigoriev CC: gdb@sourceware.org, Marc Gauthier , Pete MacLiesh Subject: Re: Understanding GDB frames References: <46521C04.7040405@hq.tensilica.com> In-Reply-To: <46521C04.7040405@hq.tensilica.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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 X-SW-Source: 2007-05/txt/msg00098.txt.bz2 There is another interesting case where I think GDB might have an issue, and that is best illustrated using Maxim's previous test case with a modified version of f11(), say f12(). int f11(int b) { int a; a = b + 1; return a; /* <- BP set here. */ } int f12(int b) { int a; while (b < 3) { a = b + 1; b = a; /* <- BP set here. */ } return a; } int main() { int a = 1; a = f11(a); a = f11(a); a = f12(1); return a; } Best compile with -O0 to ensure the loop isn't optimized out. Compare the two iterations of the loop in f12() with the two calls to f11(). For the calls to f11(), each has a separate instantiation of the frame and thus (strictly speaking) has a separate frame and a separate instance of var 'a'. In the two iterations of f12(), the frame is the same one set up at the beginning of the single call, and 'a' is the same variable. In both cases, the PC and SP are the same. How can GDB tell the difference? (using the return address instead of the PC in identifying the frame is one way, but then one only needs to go one level deeper to defeat it). Does GDB need to tell the difference? GDB confronts a similar issue with watchpoints on local vars. It uses a special scope breakpoint to detect the return of the function and thus detect the watched variable going out of scope. That mechanism is not used for MI variables. Is that because the extra overhead is tolerable if a watchpoint is set but not otherwise? Should scoping of MI vars be treated the same as watched vars? Ross Maxim Grigoriev wrote: > I experience some difficulties in finding a precise definition > of gdb frames. > > Any help on choosing the right answer among the list provided > by me at the end of this message will be highly appreciated. > > QUESTION > ======== > > The program (frame.c) is > > #include > > int frame_number = 1; > > int f11(int b) > { > int a; > > printf("f11() frame number %d\n", frame_number++); > > a = b + 1; > b--; > if (b != 0) > { > printf("f11() will be called recursively\n"); > f11(b); > } > return a; /* <-- BP set here. */ > } > > int f1(int a) > { > return f11(a); > } > > int main() > { > int a = 1; > int i; > > for (i = 0; i <2; i++) > a = f11(a); > > a = f11(1); > a = f1(1); > > return 0; > } > > The gdb command file "CMD": > > break frame.c:18 > run > continue > continue > continue > continue > kill > quit > > was used to run a gdb session like this : > gdb --command=CMD > > Let's define that "frames A and B are the same" if > > frame_id_eq ( A->this_id, B->this_id ) == true > > The breakpoit has been set at line 18 and hit 5 times. > Execution control has been subsequently taken by > gdb in five frames numbered 1, 2, 3, 4, and 5. > > According to the definition of GDB frames, > which statement is correct ? > > ANSWERS > ======= > > 1) All frames 1, 2, 3, 4, and 5 are the same; > 2) All frames 1, 2, 3, 4, and 5 are different from each other; > 3) Frames 1,2, and 4 are the same. Frames 3 and 5 are > different from 1, 2, 4 and from each other; > 4) It's implementation-dependent. While doing architecture ports, > people decide how to implement frame_id-related functions > to compare frames; > 5) Other ( explanation would be appreciated ). > > -- Maxim > > > > > > > > > >