From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25116 invoked by alias); 7 Apr 2018 17:49:43 -0000 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 Received: (qmail 25101 invoked by uid 89); 7 Apr 2018 17:49:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=accumulates X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Apr 2018 17:49:41 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w37HnZdr009635 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 7 Apr 2018 13:49:39 -0400 Received: by simark.ca (Postfix, from userid 112) id 07EEB1E661; Sat, 7 Apr 2018 13:49:35 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 622991E47D for ; Sat, 7 Apr 2018 13:49:34 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 07 Apr 2018 17:49:00 -0000 From: Simon Marchi To: gdb-patches@sourceware.org Subject: Re: [PATCH] Implement write_async_safe for mi_console_file (PR 22299) In-Reply-To: <20180324190945.21404-1-simon.marchi@polymtl.ca> References: <20180324190945.21404-1-simon.marchi@polymtl.ca> Message-ID: <97515e153f213e8dcf83d10df5f6591f@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.4 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 7 Apr 2018 17:49:35 +0000 X-IsSubscribed: yes X-SW-Source: 2018-04/txt/msg00122.txt.bz2 On 2018-03-24 15:09, Simon Marchi wrote: > Enabling "set debug lin-lwp 1" with the MI interpreter doesn't work. > When the sigchld_handler function wants to print a debug output > ("sigchld\n"), it uses ui_file_write_async_safe. This ends up in the > default implementation of ui_file::write_async_safe, which aborts GDB. > > This patch implements the write_async_safe method for mi_console_file. > The "normal" MI output is line buffered, which means the output > accumulates in m_buffer until a \n is written, at which point it's > flushed in m_raw. The implementation of write_async_safe provided by > this patch bypasses this buffer and writes directly to m_raw. There > are > two reasons for this: > > (1) Appending to m_buffer (therefore to an std::string) is probably not > async-safe, as it may allocate memory. > (2) We may have a partial output already in m_buffer, so that would > lead > to some nested MI output, not so great. > > There is probably still a chance to have bad MI output, if > sigchld_handler is invoked in the middle of mi_console_file's flush, > and > the line being flushed is only partially sent to m_raw. The solution > would probably be to block signals during flushing. Since this is only > used for debug output, I don't know if it's worth the effort to do > that. > > To implement write_async_safe, I needed to use the fputstrn_unfiltered, > which does the necessary escaping (e.g. replace \n with \\n). I > started > by adding printchar's callback parameters to fputstrn_unfiltered, to be > able to pass async-safe versions of them. It's not easy to provide an > async-safe version of do_fprintf, but it turns out that we can easily > replace printchar's callbacks with a single do_fputc quite easily. The > async-safe version of do_fputc simply calls the underlying ui_file's > write_async_safe method. I pushed this patch. Simon