From patchwork Fri Jul 26 13:34:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33811 Received: (qmail 121591 invoked by alias); 26 Jul 2019 13:34:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 121509 invoked by uid 89); 26 Jul 2019 13:34:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*Ad:U*tromey, annoying, HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Jul 2019 13:34:42 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9A217116FD4; Fri, 26 Jul 2019 09:34:40 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id lqtXBf2LM3oQ; Fri, 26 Jul 2019 09:34:40 -0400 (EDT) Received: from murgatroyd.Home (97-122-178-82.hlrn.qwest.net [97.122.178.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 44AF5116D9D; Fri, 26 Jul 2019 09:34:40 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 4/4] Clean up source file error reporting Date: Fri, 26 Jul 2019 07:34:23 -0600 Message-Id: <20190726133422.5896-5-tromey@adacore.com> In-Reply-To: <20190726133422.5896-1-tromey@adacore.com> References: <20190726133422.5896-1-tromey@adacore.com> MIME-Version: 1.0 print_source_lines_base reopens the source file every time that a source line is to be printed. However, there's no need to do this so frequently -- it's enough to do it when switching source files, and otherwise rely on the cache. The code seems to try to avoid these multiple opens; at a guess I'd say something just got confused along the way. This patch fixes the problem by reorganizing the code both to make it more clear, and to ensure that reopens only occur when the "last source visited" changes. gdb/ChangeLog 2019-07-26 Tom Tromey * source.c (last_source_error): Now bool. (print_source_lines_base): Make "noprint" bool. Only open source file when last_source_visited changes. --- gdb/ChangeLog | 6 ++++++ gdb/source.c | 26 ++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/gdb/source.c b/gdb/source.c index e0050f1fb82..066666c7ca3 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -129,7 +129,7 @@ static int first_line_listed; Used to prevent repeating annoying "No such file or directories" msgs. */ static struct symtab *last_source_visited = NULL; -static int last_source_error = 0; +static bool last_source_error = false; /* Return the first line listed by print_source_lines. Used by command interpreters to request listing from @@ -1129,8 +1129,7 @@ static void print_source_lines_base (struct symtab *s, int line, int stopline, print_source_lines_flags flags) { - scoped_fd desc; - int noprint = 0; + bool noprint = false; int nlines = stopline - line; struct ui_out *uiout = current_uiout; @@ -1144,26 +1143,27 @@ print_source_lines_base (struct symtab *s, int line, int stopline, if (uiout->test_flags (ui_source_list)) { /* Only prints "No such file or directory" once. */ - if ((s != last_source_visited) || (!last_source_error)) + if (s == last_source_visited) { - last_source_visited = s; - desc = open_source_file (s); - if (desc.get () < 0) + if (last_source_error) { - last_source_error = desc.get (); - noprint = 1; + flags |= PRINT_SOURCE_LINES_NOERROR; + noprint = true; } } else { - flags |= PRINT_SOURCE_LINES_NOERROR; - noprint = 1; + last_source_visited = s; + scoped_fd desc = open_source_file (s); + last_source_error = desc.get () < 0; + if (last_source_error) + noprint = true; } } else { flags |= PRINT_SOURCE_LINES_NOERROR; - noprint = 1; + noprint = true; } if (noprint) @@ -1209,8 +1209,6 @@ print_source_lines_base (struct symtab *s, int line, int stopline, return; } - last_source_error = 0; - /* If the user requested a sequence of lines that seems to go backward (from high to low line numbers) then we don't print anything. */ if (stopline <= line)