From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 50167 invoked by alias); 15 Mar 2019 13:56:45 -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 50156 invoked by uid 89); 15 Mar 2019 13:56:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: mail-wr1-f67.google.com Received: from mail-wr1-f67.google.com (HELO mail-wr1-f67.google.com) (209.85.221.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Mar 2019 13:56:43 +0000 Received: by mail-wr1-f67.google.com with SMTP id i8so9709240wrm.0 for ; Fri, 15 Mar 2019 06:56:43 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id 93sm4474410wrh.15.2019.03.15.06.56.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Mar 2019 06:56:40 -0700 (PDT) Subject: Re: Fix pressing down in the TUI (Re: [RFC 8.3 0/3] Some style fixes) To: Eli Zaretskii References: <20190308210433.32683-1-tromey@adacore.com> <83pnr08tc8.fsf@gnu.org> <83zhq26fcw.fsf@gnu.org> <874l899nh3.fsf@tromey.com> <8336ns3uv4.fsf@gnu.org> <831s381cp5.fsf@gnu.org> Cc: tromey@adacore.com, gdb-patches@sourceware.org From: Pedro Alves Message-ID: <432e3aa4-a006-bace-657b-b49ec2314190@redhat.com> Date: Fri, 15 Mar 2019 13:56:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <831s381cp5.fsf@gnu.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-03/txt/msg00312.txt.bz2 On 03/15/2019 01:36 PM, Eli Zaretskii wrote: >> Cc: gdb-patches@sourceware.org >> From: Pedro Alves >> Date: Fri, 15 Mar 2019 12:34:34 +0000 >> >> On 03/12/2019 04:44 PM, Eli Zaretskii wrote: >>> 1. The first patch fixes the problem noticed by Pedro: pressing DOWN >>> arrow in the command window doesn't scroll the source window. This is >>> because we don't initialize the s->nlines field, and then >>> tui_vertical_source_scroll thinks we are off the chart. This fixes >>> that: >>> >>> --- gdb/source-cache.c~4 2019-03-10 08:34:47.422752400 +0200 >>> +++ gdb/source-cache.c 2019-03-12 11:50:15.094147600 +0200 >>> @@ -194,6 +194,12 @@ source_cache::get_source_lines (struct s >>> std::ifstream input (fullname); >>> if (input.is_open ()) >>> { >>> + if (s->line_charpos == 0) >>> + { >>> + scoped_fd desc = open_source_file (s); >>> + if (desc.get () >= 0) >>> + find_source_lines (s, desc.get ()); >> >> I think this should return false if open_source_file fails? > > How could it fail if input.is_open returns non-zero? Are you thinking > about some race, whereby something deletes the file after the > constructor for 'input' returns? Yes, something like that. The possibility is small, but non-zero that it could fail. And if it does, we end up with s->nlines uninitialized again. > >> Otherwise this LGTM. I see get_plain_source_lines has similar >> code, so my immediate thought was to move that to a helper function, >> but there's a difference that makes that unviable -- get_plain_source_lines >> always wants to open the source file first, while here we can avoid >> it unless line_charpos is 0. > > Right. Also, I originally hoped std::ifstream will have a way to get > at the underlying file descriptor, but no such luck, AFAICT. Yeah, I believe GNU has a non-standard way for that, but it's not portable. (And not worth the bother to #ifdef here for that, IMHO. Thanks, Pedro Alves