From patchwork Mon Jan 7 12:42:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 30986 Received: (qmail 8352 invoked by alias); 7 Jan 2019 12:42:38 -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 8108 invoked by uid 89); 7 Jan 2019 12:42:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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.2 spammy=H*RU:209.85.221.65, concerned, Hx-spam-relays-external:209.85.221.65, noticed X-HELO: mail-wr1-f65.google.com Received: from mail-wr1-f65.google.com (HELO mail-wr1-f65.google.com) (209.85.221.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Jan 2019 12:42:35 +0000 Received: by mail-wr1-f65.google.com with SMTP id s12so270578wrt.4 for ; Mon, 07 Jan 2019 04:42:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ZCFdDqlUo1+N0EmCKrFQk1N3mldKEhaSHjaVvhMgvW0=; b=KMa1ChgU3wTq2ltAZwyE8BlDaCa5/v4GdIk/jw/tfKppPP7bX0TsegFZ7HJ/sOlE0W ibqrZMLNYws5JvJ97NhwHbnN2QSaWmtjcIW4z+eiKDREVIy30LIQoIE0zMB4y3VgXyT6 5tEFmMMQ7VSCeUEDk7ElhCUx9Hag4devgc/3XyXaGmmobz600AnBJ+jvK1NxumxWEU6T UH2o2JNGwmk75Pne8PSHnsQ14mrI5WQ68DBx4dVICUgtjzWvCEMw4swk42hWVAoSPdW4 lAfdDugnl9uvdSXPXjRSwzc+PqR1cNDogx3YtpVOW59oH7889fgb8yvqmsD/gL+RzAPZ E6DQ== Return-Path: Received: from localhost (host86-172-198-47.range86-172.btcentralplus.com. [86.172.198.47]) by smtp.gmail.com with ESMTPSA id 125sm9226409wmm.26.2019.01.07.04.42.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 04:42:32 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org, Tom Tromey Cc: Andrew Burgess Subject: [PATCH 2/4] gdb: Handle requests to print source lines backward Date: Mon, 7 Jan 2019 12:42:22 +0000 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes ...by which I mean from high line number to low, not, actually backward character by character! Commit: commit 62f29fda90cf1d5a1899f57ef78452471c707fd6 Date: Tue Oct 9 22:21:05 2018 -0600 Highlight source code using GNU Source Highlight introduced a regression in the test gdb.linespec/explicit.exp, in which a request is made to GDB to print a reverse sequence of lines, from +10 to -10 from the current line number. The expected behaviour is that GDB prints nothing. The above commit changed this so that GDB now prints: Line number 32 out of range; /path/to/gdb/testsuite/gdb.linespec/explicit.c has 71 lines. which is a little confusing. This commit fixes the regression, and restores the behaviour that GDB prints nothing. While I was passing I noticed a call to `back` on a std::string that I was concerned could be empty if the request for source lines returns an empty string. I don't know if it would be possible for a request for lines to return an empty string, I guess it should be impossible, in which case, maybe this should be an assertion, but adding a `empty` check, seems like an easy and cheap safety net. gdb/ChangeLog: * source.c (print_source_lines_base): Handle requests to print reverse line number sequences, and guard against empty lines string. --- gdb/ChangeLog | 6 ++++++ gdb/source.c | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gdb/source.c b/gdb/source.c index e77789c0dba..71da396acc8 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1346,6 +1346,16 @@ print_source_lines_base (struct symtab *s, int line, int stopline, 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. + The use of '- 1' here instead of '<=' is currently critical, we rely + on the undefined wrap around behaviour of 'int' for stopline. When + the use has done: 'set listsize unlimited' then stopline can overflow + and appear as MIN_INT. This is a long-standing bug that needs + fixing. */ + if (stopline - 1 < line) + return; + std::string lines; if (!g_source_cache.get_source_lines (s, line, stopline - 1, &lines)) error (_("Line number %d out of range; %s has %d lines."), @@ -1392,7 +1402,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline, if (c == '\0') break; } - if (lines.back () != '\n') + if (!lines.empty() && lines.back () != '\n') uiout->text ("\n"); }