From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 407 invoked by alias); 10 Nov 2004 17:03:25 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 349 invoked from network); 10 Nov 2004 17:03:15 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 10 Nov 2004 17:03:15 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id iAAH3DOU026870 for ; Wed, 10 Nov 2004 12:03:14 -0500 Received: from localhost.redhat.com (to-dhcp51.toronto.redhat.com [172.16.14.151]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id iAAH3Dr28321; Wed, 10 Nov 2004 12:03:13 -0500 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 5270B129D8C; Wed, 10 Nov 2004 12:02:10 -0500 (EST) Message-ID: <41924990.9060504@gnu.org> Date: Wed, 10 Nov 2004 17:03:00 -0000 From: Andrew Cagney User-Agent: Mozilla Thunderbird 0.8 (X11/20041020) MIME-Version: 1.0 To: Randolph Chung , Eli Zaretskii Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA] Don't unwind past entry point References: <20041109192430.GW15714@tausq.org> In-Reply-To: <20041109192430.GW15714@tausq.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-11/txt/msg00198.txt.bz2 Randolph Chung wrote: > Here's a proposed patch to fix the problem i mentioned in > http://sources.redhat.com/ml/gdb/2004-11/msg00020.html > > Briefly, if a compiler does a tail-call optimization to main, a function > called from main will return directly to the caller of main, and we > never terminate a backtrace. > > It doesn't address Joel's problem with threads though. Check eli for the doco. The code change is ok (while your though though, can you do me a favour and move inside_entry_func to frame.c and make it static?). This is missing a testcase but for that I'll need to take a raincheck - we've almost but not quite got a setbacktrace testcase and it should be extended to include this. Can you watch for that. Andrew > randolph > > > 2004-11-09 Randolph Chung > > * frame.c (backtrace_past_entry): New flag. > (get_prev_frame): Stop backtrace at the entry function if enabled > by flag. Update comments. > (_initialize_frame): Add command to set backtrace_past_entry flag. > > doc/ > * gdb.texinfo: Document set/show backtrace past-entry commands. > Rearrange index entries for set/show backtrace past-main. > > Index: frame.c > =================================================================== > RCS file: /cvs/src/src/gdb/frame.c,v > retrieving revision 1.192 > diff -u -p -r1.192 frame.c > --- frame.c 29 Oct 2004 20:23:06 -0000 1.192 > +++ frame.c 9 Nov 2004 19:21:38 -0000 > @@ -115,6 +115,7 @@ static int frame_debug; > /* Flag to indicate whether backtraces should stop at main et.al. */ > > static int backtrace_past_main; > +static int backtrace_past_entry; > static unsigned int backtrace_limit = UINT_MAX; > > static void > @@ -1213,8 +1214,6 @@ get_prev_frame (struct frame_info *this_ > dummy frame PCs typically land in the entry func. Don't apply > this test to the sentinel frame. Sentinel frames should always > be allowed to unwind. */ > - /* NOTE: cagney/2003-02-25: Don't enable until someone has found > - hard evidence that this is needed. */ > /* NOTE: cagney/2003-07-07: Fixed a bug in inside_main_func() - > wasn't checking for "main" in the minimal symbols. With that > fixed asm-source tests now stop in "main" instead of halting the > @@ -1227,13 +1226,12 @@ get_prev_frame (struct frame_info *this_ > I guess) to determine the address range of the start function. > That should provide a far better stopper than the current > heuristics. */ > - /* NOTE: cagney/2003-07-15: Need to add a "set backtrace > - beyond-entry-func" command so that this can be selectively > - disabled. */ > - if (0 > -#if 0 > - && backtrace_beyond_entry_func > -#endif > + /* NOTE: tausq/2004-10-09: this is needed if, for example, the compiler > + applied tail-call optimizations to main so that a function called > + from main returns directly to the caller of main. Since we don't > + stop at main, we should at least stop at the entry point of the > + application. */ > + if (!backtrace_past_entry > && this_frame->unwind->type != DUMMY_FRAME && this_frame->level >= 0 > && inside_entry_func (this_frame)) > { > @@ -1531,6 +1529,17 @@ Whether backtraces should continue past > NULL, NULL, &set_backtrace_cmdlist, > &show_backtrace_cmdlist); > > + add_setshow_boolean_cmd ("past-entry", class_obscure, > + &backtrace_past_entry, "\ > +Set whether backtraces should continue past the entry point of a program.", "\ > +Show whether backtraces should continue past the entry point of a program.", "\ > +Normally there are no callers beyond the entry point of a program, so GDB\n\ > +will terminate the backtrace there. Set this variable if you need to see \n\ > +the rest of the stack trace.", "\ > +Whether backtraces should continue past the entry point is %s.", > + NULL, NULL, &set_backtrace_cmdlist, > + &show_backtrace_cmdlist); > + > add_setshow_uinteger_cmd ("limit", class_obscure, > &backtrace_limit, "\ > Set an upper bound on the number of backtrace levels.", "\ > Index: doc/gdb.texinfo > =================================================================== > RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v > retrieving revision 1.223 > diff -u -p -r1.223 gdb.texinfo > --- doc/gdb.texinfo 8 Nov 2004 17:25:49 -0000 1.223 > +++ doc/gdb.texinfo 9 Nov 2004 19:21:47 -0000 > @@ -4109,7 +4109,7 @@ in a backtrace, you can change this beha > @table @code > @item set backtrace past-main > @itemx set backtrace past-main on > -@kindex set backtrace > +@kindex set backtrace past-main > Backtraces will continue past the user entry point. > > @item set backtrace past-main off > @@ -4117,9 +4117,24 @@ Backtraces will stop when they encounter > default. > > @item show backtrace past-main > -@kindex show backtrace > +@kindex show backtrace past-main > Display the current user entry point backtrace policy. > > +@item set backtrace past-entry > +@itemx set backtrace past-entry on > +@kindex set backtrace past-entry > +Backtraces will continue past the internal entry point of an application. > +This entry point is encoded by the linker when the application is built, > +and is likely before the user entry point ``main'' (or equivalent) is called. > + > +@item set backtrace past-entry off > +Backtraces will stop when they encouter the internal entry point of an > +application. This is the default. > + > +@item show backtrace past-entry > +@kindex show backtrace past-entry > +Display the current internal entry point backtrace policy. > + > @item set backtrace limit @var{n} > @itemx set backtrace limit 0 > @cindex backtrace limit >