From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 948B53858C55; Mon, 4 Apr 2022 18:50:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 948B53858C55 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix bug in Ada attributes lexing X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: c3f2a3738a3603f51e3621504d8207767526add9 X-Git-Newrev: 45016746f1a992e7300cae74761c681a8a3f4fe7 Message-Id: <20220404185025.948B53858C55@sourceware.org> Date: Mon, 4 Apr 2022 18:50:25 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2022 18:50:25 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D45016746f1a9= 92e7300cae74761c681a8a3f4fe7 commit 45016746f1a992e7300cae74761c681a8a3f4fe7 Author: Tom Tromey Date: Tue Feb 22 12:02:10 2022 -0700 Fix bug in Ada attributes lexing =20 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; } =20 /* ATTRIBUTES */ =20 -{TICK}[a-z][a-z_]+ { BEGIN INITIAL; return processAttribute (yytext+1); } +{TICK}[a-z][a-z_]+ { BEGIN INITIAL; return processAttribute (yytext); } =20 /* PUNCTUATION */ =20 @@ -663,6 +663,11 @@ attributes[] =3D { static int processAttribute (const char *str) { + gdb_assert (*str =3D=3D '\''); + ++str; + while (isspace (*str)) + ++str; + for (const auto &item : attributes) if (strcasecmp (str, item.name) =3D=3D 0) return item.code; diff --git a/gdb/testsuite/gdb.ada/formatted_ref.exp b/gdb/testsuite/gdb.ad= a/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 =20 foreach attr {access unchecked_access unrestricted_access} { - set test "print/x $var'$attr" - gdb_test_multiple $test $test { - -re "\\$\[0-9\]+ =3D $addr.*$gdb_prompt $" { - pass $test - } - -re "\\$\[0-9\]+ =3D 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\]+ =3D $addr.*$gdb_prompt $" { + pass $test + } + -re "\\$\[0-9\]+ =3D 0x\[a-f0-9+\]+.*$gdb_prompt $" { + fail "$test (prints unexpected address)" + } } } }