From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1974 invoked by alias); 18 Mar 2010 07:22:35 -0000 Received: (qmail 1963 invoked by uid 22791); 18 Mar 2010 07:22:33 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Mar 2010 07:22:28 +0000 Received: from kpbe19.cbf.corp.google.com (kpbe19.cbf.corp.google.com [172.25.105.83]) by smtp-out.google.com with ESMTP id o2I7MO8r021004 for ; Thu, 18 Mar 2010 08:22:25 +0100 Received: from wwa36 (wwa36.prod.google.com [10.241.241.36]) by kpbe19.cbf.corp.google.com with ESMTP id o2I7MLMD003743 for ; Thu, 18 Mar 2010 00:22:21 -0700 Received: by wwa36 with SMTP id 36so18047wwa.10 for ; Thu, 18 Mar 2010 00:22:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.89.202 with SMTP id c52mr1133581wef.84.1268896940793; Thu, 18 Mar 2010 00:22:20 -0700 (PDT) In-Reply-To: <11611.203.63.255.139.1268879984.squirrel@webmail5.pair.com> References: <11611.203.63.255.139.1268879984.squirrel@webmail5.pair.com> Date: Thu, 18 Mar 2010 07:22:00 -0000 Message-ID: Subject: Re: Getting pissed off by gdb. Please help with stepping in. From: Doug Evans To: temp@sourceboost.com Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-System-Of-Record: true 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: 2010-03/txt/msg00120.txt.bz2 On Wed, Mar 17, 2010 at 7:39 PM, wrote: > I had to use gdb many times over the years all the time it pisses me off > with one of its features and makes me move back to microsoft debugger as > soon as possible. Now I want to get to the bottom of it and figure out if > it's me or gdb. I'm talking about stepping into a function. Imagine a call > to a function 'foo' that has one argument and the value of this argument > is returned by a call to another function 'bar' like: > > ... > foo( bar() ); > ... > > All I want to do is to step into 'foo' without having to set any > additional breakpoints. > > When I use microsoft debugger and do step into on this line I get into the > function 'bar' first. Than I step out what brings me back to the line > where 'foo' is called. I do another step into and get into 'foo'. > > When I debug same code under gdb and do step into I get into 'bar'. So far > so good. I do a step out and wtf... Instead of getting back to the line > where 'foo' is called I get passed it. My step out of 'bar' command caused > call to 'foo' to execute as well. But I just wanted to step out of 'bar' > but not have 'foo' executed yet. Not happy. > > So my question is it possible to step out of a function in gdb in code > like above and remain on the line where this function was called from? > What's the secret? Please advise. I agree it should work as you expect. I don't see the step out of bar continuing passed foo, but I do see it stepping into foo (as if you had done two steps, so to speak: step out of bar and step into foo). [This is with gdb 7.0 and cvs head.] One *could* use `finish' to accomplish what you want but I think a `step' at the end of the function should behave like `finish' (modulo printing the return value of course). This patch for cvs head gets things working for me. I haven't run it through the testsuite, and it might be nice compare more than just frame ids (and for the gdb crowd, yes, the FIXME needs to go before being checked in ...), but .... this patch seems otherwise reasonable to me. At the point where the patch is applied gdb has already decided to continue - what's a case where it *should* continue at this point *if* the frame has changed? [Note that gdb has already handled various cases like stopping in trampolines and such.] diff -u -p -r1.434 infrun.c --- infrun.c 14 Mar 2010 17:35:21 -0000 1.434 +++ infrun.c 18 Mar 2010 07:11:29 -0000 @@ -4770,6 +4770,23 @@ infrun: not switching back to stepped th return; } + /* See if we stepped out of a function into its caller. */ + /* FIXME: IWBN to do an inner-than test on the stack addresses + but that doesn't necessarily work in a split-stack environment. + Or we could call frame_unwind_caller_id (step_stack_frame_id), + but that seems dubious. */ + + if (!frame_id_eq (get_stack_frame_id (frame), + ecs->event_thread->step_stack_frame_id)) + { + if (debug_infrun) + fprintf_unfiltered (gdb_stdlog, "infrun: stepped out of function\n"); + ecs->event_thread->stop_step = 1; + print_stop_reason (END_STEPPING_RANGE, 0); + stop_stepping (ecs); + return; + } + /* We aren't done stepping. Optimize by setting the stepping range to the line.