From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 572 invoked by alias); 4 Mar 2010 14:02:16 -0000 Received: (qmail 455 invoked by uid 22791); 4 Mar 2010 14:02:15 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 04 Mar 2010 14:02:11 +0000 Received: (qmail 15243 invoked from network); 4 Mar 2010 14:02:09 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 4 Mar 2010 14:02:09 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [RFA] Fix "Segmentation fault" when "gdb -v" Date: Thu, 04 Mar 2010 14:02:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-19-generic; KDE/4.3.2; x86_64; ; ) Cc: Joel Brobecker , Hui Zhu References: <20100304072620.GJ2832@adacore.com> In-Reply-To: <20100304072620.GJ2832@adacore.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201003041402.07512.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-03/txt/msg00175.txt.bz2 On Thursday 04 March 2010 07:26:20, Joel Brobecker wrote: > > All of this code use "printf_filtered". But this function must be > > call after "interp_set". > > But this part of code call before "interp_set". Sorry I missed this could happen. Quite obvious in hindsight. > I think that this was an unforseen side-effect of a recent change. > IMO, it's better to get rid of this side-effect (needing the interpreter > to be set) in printf_filtered. That could mean that GDB could paginate before figuring out if the top level interpreter is MI, which isn't desirable. Unless we always disable pagination until there's an interpreter set, but, now that I look, actually, we already do: I started GDB in a really short window (3 lines height), and noticed that "gdb --version" doesn't paginate either. prompt_for_continue _is_ called, but it's eneffective: it calls gdb_readline_wrapper which first, which tries to print the pagination prompt, but that fails because current_interp_display_prompt_p just doesn't do anything if there's no current interpreter yet. Then it goes into the event loop waiting for input to the prompt, which just returns almost immediately, because there's no waitable file registered in the event loop yet. > > We should NOT change printf_filtered into printf_unfiltered in this case > because the same function is used in two different situations: > - when the user uses -v > - when the user types "show version" > In the latter case, the printf_filtered is appropriate. > > Now, we need to decide whether pagination should be enabled if > the interpreter is not set. I think it makes sense to disable pagination > in this case. If the interpreter is not set yet, we're just printing > stuff on stdout, we haven't started the interactive session (if any) yet... I agree, and turns out this is what's already happening, albeit in a "works almost by accident" way. I think this patch below wouldn't be that bad afterall. It does fix the problem. -- Pedro Alves 2010-03-04 Pedro Alves * utils.c (fputs_maybe_filtered): Check if there's already a top level interpreter before dereferencing it. If there isn't one, don't paginate either. --- gdb/utils.c | 1 + 1 file changed, 1 insertion(+) Index: src/gdb/utils.c =================================================================== --- src.orig/gdb/utils.c 2010-03-04 13:27:17.000000000 +0000 +++ src/gdb/utils.c 2010-03-04 13:29:11.000000000 +0000 @@ -2213,6 +2213,7 @@ fputs_maybe_filtered (const char *linebu if (stream != gdb_stdout || !pagination_enabled || (lines_per_page == UINT_MAX && chars_per_line == UINT_MAX) + || top_level_interpreter () == NULL || ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ()))) { fputs_unfiltered (linebuffer, stream);