public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Fix bug in Ada attributes lexing
Date: Mon,  4 Apr 2022 18:50:25 +0000 (GMT)	[thread overview]
Message-ID: <20220404185025.948B53858C55@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=45016746f1a992e7300cae74761c681a8a3f4fe7

commit 45016746f1a992e7300cae74761c681a8a3f4fe7
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Feb 22 12:02:10 2022 -0700

    Fix bug in Ada attributes lexing
    
    The Ada lexer allows whitespace between the apostrophe and the
    attribute text, but processAttribute does not handle this.  This patch
    fixes the problem and introduces a regression test.

Diff:
---
 gdb/ada-lex.l                           |  7 ++++++-
 gdb/testsuite/gdb.ada/formatted_ref.exp | 16 +++++++++-------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index a0c9816e568..c6ce1aec53a 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -227,7 +227,7 @@ false		{ return FALSEKEYWORD; }
 
         /* ATTRIBUTES */
 
-{TICK}[a-z][a-z_]+ { BEGIN INITIAL; return processAttribute (yytext+1); }
+{TICK}[a-z][a-z_]+ { BEGIN INITIAL; return processAttribute (yytext); }
 
 	/* PUNCTUATION */
 
@@ -663,6 +663,11 @@ attributes[] = {
 static int
 processAttribute (const char *str)
 {
+  gdb_assert (*str == '\'');
+  ++str;
+  while (isspace (*str))
+    ++str;
+
   for (const auto &item : attributes)
     if (strcasecmp (str, item.name) == 0)
       return item.code;
diff --git a/gdb/testsuite/gdb.ada/formatted_ref.exp b/gdb/testsuite/gdb.ada/formatted_ref.exp
index bb5f78c0d72..882dbf17725 100644
--- a/gdb/testsuite/gdb.ada/formatted_ref.exp
+++ b/gdb/testsuite/gdb.ada/formatted_ref.exp
@@ -70,13 +70,15 @@ proc test_p_x_addr { var addr } {
     global gdb_prompt
 
     foreach attr {access unchecked_access unrestricted_access} {
-	set test "print/x $var'$attr"
-	gdb_test_multiple $test $test {
-	    -re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" {
-		pass $test
-	    }
-	    -re "\\$\[0-9\]+ = 0x\[a-f0-9+\]+.*$gdb_prompt $" {
-		fail "$test (prints unexpected address)"
+	foreach space {"" "  "} {
+	    set test "print/x $var'$space$attr"
+	    gdb_test_multiple $test $test {
+		-re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" {
+		    pass $test
+		}
+		-re "\\$\[0-9\]+ = 0x\[a-f0-9+\]+.*$gdb_prompt $" {
+		    fail "$test (prints unexpected address)"
+		}
 	    }
 	}
     }


                 reply	other threads:[~2022-04-04 18:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220404185025.948B53858C55@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).