From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1025 invoked by alias); 30 Aug 2010 11:29:21 -0000 Received: (qmail 1014 invoked by uid 22791); 30 Aug 2010 11:29:20 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD 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; Mon, 30 Aug 2010 11:29:16 +0000 Received: (qmail 12165 invoked from network); 30 Aug 2010 11:29:14 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 30 Aug 2010 11:29:14 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [PATCH] tui-out: don't "inherit" redirect from CLI Date: Mon, 30 Aug 2010 11:29:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.33-29-realtime; KDE/4.4.2; x86_64; ; ) Cc: Paul Bolle References: <1283160550.10594.1.camel@localhost.localdomain> In-Reply-To: <1283160550.10594.1.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201008301229.12412.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-08/txt/msg00507.txt.bz2 On Monday 30 August 2010 10:29:10, Paul Bolle wrote: > Since revision 1.17 tui_ui_out_impl "inherits" from cli_ui_out_impl (ie, > it starts as a copy of that struct). tui_ui_out_impl.redirect is never > redefined after that so it points to cli_redirect(). (Before revision > 1.17 it was NULL.) That was the main reason that tui_ui_out_impl was made to inherit cli_ui_out_impl in the first place. See . > As a consequence, uo_redirect() will actually try to redirect if passed > a tui_ui_out_impl. That will probably crash gdb (as > tui_ui_out_impl->data->stream and tui_ui_out_impl->data->original_stream > don't exist). Yes they do exist, because tui_ui_out_data "inherits" cli_ui_out_data. See: struct tui_ui_out_data { struct cli_ui_out_data base; ^^^^^^^^^^^^^^^^^^^^^^^^^^^ int line; int start_of_line; }; typedef struct tui_ui_out_data tui_out_data; "base" is the first field of tui_ui_out_data, so you can pass a pointer to a tui_ui_out_data to a function that expects a cli_ui_out_data pointer. This is legal, and a common idiom on C, as means to implementing "is-a" inheritance. > > So set tui_ui_out_impl.redirect to NULL after "inheriting". Nope, sorry, this isn't correct. > (Just something I noticed while trying to understand the ui code.) -- Pedro Alves