public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Expression parser fixes for address space qualifiers.
@ 2021-04-06  9:29 Felix Willgerodt
  2021-04-06  9:29 ` [PATCH v2 1/2] gdb: Allow address space qualifier parsing in C++ Felix Willgerodt
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Felix Willgerodt @ 2021-04-06  9:29 UTC (permalink / raw)
  To: gdb-patches, felix.willgerodt

Changes to v1:
* Added a testcase to patch 1.

Regards,
Felix

Felix Willgerodt (2):
  gdb: Allow address space qualifier parsing in C++.
  gdb: Fix reduce/reduce conflicts for qualifier_seq_noopt in the C
    parser.

 gdb/c-exp.y                                   |  7 +++-
 .../gdb.base/address_space_qualifier.exp      | 35 +++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.base/address_space_qualifier.exp

-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] gdb: Allow address space qualifier parsing in C++.
  2021-04-06  9:29 [PATCH v2 0/2] Expression parser fixes for address space qualifiers Felix Willgerodt
@ 2021-04-06  9:29 ` Felix Willgerodt
  2021-04-06  9:29 ` [PATCH v2 2/2] gdb: Fix reduce/reduce conflicts for qualifier_seq_noopt in the C parser Felix Willgerodt
  2021-04-19 19:43 ` [PATCH v2 0/2] Expression parser fixes for address space qualifiers Tom Tromey
  2 siblings, 0 replies; 5+ messages in thread
From: Felix Willgerodt @ 2021-04-06  9:29 UTC (permalink / raw)
  To: gdb-patches, felix.willgerodt

The goal of this patch is to allow target dependent address space qualifiers
in the C++ expression parser.  This can be useful for memory examination on
targets that actually use different address spaces in hardware without
having to deep-dive into implementation details of the whole solution.

GDB uses the @ symbol to parse address space qualifiers.  The only current
user that I am aware of is the __flash support for avr, which was added in
"Add support for the __flash qualifier on AVR"
(487d975399dfcb2bb2f0998a7d12bd62acdd9fa1)
and only works for C.

One use-case of the AVR patch is:

~~~
const __flash char data_in_flash = 0xab;

int
main (void)
{
  const __flash char *pointer_to_flash = &data_in_flash;
}
~~~

~~~
(gdb) print pointer_to_flash
$1 = 0x1e8 <data_in_flash> "\253"
(gdb) print/x *pointer_to_flash
$2 = 0xab
(gdb) x/x pointer_to_flash
0x1e8 <data_in_flash>: 0xXXXXXXab
(gdb)
(gdb) p/x *(char* @flash) pointer_to_flash
$3 = 0xab
~~~

I want to enable a similar usage of e.g. @local in C++.

Before this patch (using "set debug parser on"):

~~~
(gdb) p *(int* @local) 0x1234
(...)
Reading a token: Next token is token '@' ()
Shifting token '@' ()
Entering state 46
Reading a token: Next token is token UNKNOWN_CPP_NAME (ssym<name=local, sym=(null), field_of_this=0>)
A syntax error in expression, near `local) &x'.
~~~

After:
~~~
(gdb) p *(int* @local) 0x1234
(...)
Reading a token: Next token is token '@' ()
Shifting token '@' ()
Entering state 46
Reading a token: Next token is token UNKNOWN_CPP_NAME (ssym<name=local, sym=(null), field_of_this=0>)
Shifting token UNKNOWN_CPP_NAME (ssym<name=local, sym=(null), field_of_this=0>)
Entering state 121
Reducing stack by rule 278 (line 1773):
   $1 = token UNKNOWN_CPP_NAME (ssym<name=local, sym=(null), field_of_this=0>)
-> $$ = nterm name ()
Stack now 0 49 52 76 222 337 46
Entering state 167
Reducing stack by rule 131 (line 1225):
   $1 = token '@' ()
   $2 = nterm name ()
Unknown address space specifier: "local"
~~~

The "Unknown address space qualifier" is the right behaviour, as I ran this
on a target that doesn't have multiple address spaces and therefore obviously
no support for such qualifiers.

gdb/ChangeLog:
2021-03-19  Felix Willgerodt  <felix.willgerodt@intel.com>

	* c-exp.y (single_qualifier): Handle UNKNOWN_CPP_NAME.

gdb/testsuite/ChangeLog:
2021-03-19  Felix Willgerodt  <felix.willgerodt@intel.com>

	* gdb.base/address_space_qualifier.exp: New file.
---
 gdb/c-exp.y                                   |  5 +++
 .../gdb.base/address_space_qualifier.exp      | 35 +++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/address_space_qualifier.exp

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index d6a2322dbf6..d3232fb25bc 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1266,6 +1266,11 @@ single_qualifier:
 		  cpstate->type_stack.insert (pstate,
 					      copy_name ($2.stoken).c_str ());
 		}
+	|	'@' UNKNOWN_CPP_NAME
+		{
+		  cpstate->type_stack.insert (pstate,
+					      copy_name ($2.stoken).c_str ());
+		}
 	;
 
 qualifier_seq_noopt:
diff --git a/gdb/testsuite/gdb.base/address_space_qualifier.exp b/gdb/testsuite/gdb.base/address_space_qualifier.exp
new file mode 100644
index 00000000000..b8209dc565b
--- /dev/null
+++ b/gdb/testsuite/gdb.base/address_space_qualifier.exp
@@ -0,0 +1,35 @@
+# Copyright 2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+# Regression test for expression evaluation of address space qualifiers
+# in C and C++.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_test_no_output "set language c"
+
+with_test_prefix "C" {
+	gdb_test "p *(@somerandomqualifiername int *) 0x12345678" \
+		"Unknown address space specifier: \"somerandomqualifiername\""
+}
+
+gdb_test_no_output "set language c++"
+
+with_test_prefix "C++" {
+	gdb_test "p *(@somerandomqualifiername int *) 0x12345678" \
+		"Unknown address space specifier: \"somerandomqualifiername\""
+}
-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] gdb: Fix reduce/reduce conflicts for qualifier_seq_noopt in the C parser.
  2021-04-06  9:29 [PATCH v2 0/2] Expression parser fixes for address space qualifiers Felix Willgerodt
  2021-04-06  9:29 ` [PATCH v2 1/2] gdb: Allow address space qualifier parsing in C++ Felix Willgerodt
@ 2021-04-06  9:29 ` Felix Willgerodt
  2021-04-19 19:43 ` [PATCH v2 0/2] Expression parser fixes for address space qualifiers Tom Tromey
  2 siblings, 0 replies; 5+ messages in thread
From: Felix Willgerodt @ 2021-04-06  9:29 UTC (permalink / raw)
  To: gdb-patches, felix.willgerodt

This fixes a problem with GDB's address space qualifier parsing.  GDB uses
'@' as a way to express an address space in expression evaluation.  This can
currently lead to a crash for "Add support for the __flash qualifier on AVR"
(487d975399dfcb2bb2f0998a7d12bd62acdd9fa1)
, the only user I am aware of.

Program:
~~~
const __flash char data_in_flash = 0xab;

int
main (void)
{
  const __flash char *pointer_to_flash = &data_in_flash;
}
~~~

Before:
~~~
(gdb) p data_in_flash
$1 = -85 '\253'
(gdb) p *(const char * @flash) pointer_to_flash
$2 = -85 '\253'
(gdb) p *(@flash const char *) pointer_to_flash
type-stack.c:201: internal-error: type* type_stack::follow_types(type*): unrecognized tp_ value in follow_types
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
~~~

After:
~~~
(gdb) p data_in_flash
$1 = -85 '\253'
(gdb) p *(const char *) pointer_to_flash
$2 = 0 '\000'
(gdb) p *(const char * @flash) pointer_to_flash
$3 = -85 '\253'
(gdb) p *(@flash const char *) pointer_to_flash
$4 = 0 '\000'
(gdb)
~~~

Note that how the binding of this qualifier is interpreted and resolved for an
address/pointer is target specific.  Hence only the prepended qualifier works
for AVR, even if it seems syntactically incorrect.  I won't change this for
AVR, as I am not familiar with that target.

Bison now also complains about less conflicts:

Before:
  YACC   c-exp.c
gdb/gdb/c-exp.y: warning: 153 shift/reduce conflicts [-Wconflicts-sr]
gdb/gdb/c-exp.y: warning: 70 reduce/reduce conflicts [-Wconflicts-rr]

After:
  YACC   c-exp.c
gdb/gdb/c-exp.y: warning: 60 shift/reduce conflicts [-Wconflicts-sr]
gdb/gdb/c-exp.y: warning: 69 reduce/reduce conflicts [-Wconflicts-rr]

gdb/ChangeLog:
2021-03-22  Felix Willgerodt  <felix.willgerodt@intel.com>

	* c-exp.y (qualifier_seq_noopt): Replace qualifier_seq with
	qualifier_seq_noopt.
---
 gdb/c-exp.y | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index d3232fb25bc..36607e2eee1 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1275,7 +1275,7 @@ single_qualifier:
 
 qualifier_seq_noopt:
 		single_qualifier
-	| 	qualifier_seq single_qualifier
+	| 	qualifier_seq_noopt single_qualifier
 	;
 
 qualifier_seq:
-- 
2.25.4

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] Expression parser fixes for address space qualifiers.
  2021-04-06  9:29 [PATCH v2 0/2] Expression parser fixes for address space qualifiers Felix Willgerodt
  2021-04-06  9:29 ` [PATCH v2 1/2] gdb: Allow address space qualifier parsing in C++ Felix Willgerodt
  2021-04-06  9:29 ` [PATCH v2 2/2] gdb: Fix reduce/reduce conflicts for qualifier_seq_noopt in the C parser Felix Willgerodt
@ 2021-04-19 19:43 ` Tom Tromey
  2021-04-20  6:51   ` Willgerodt, Felix
  2 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2021-04-19 19:43 UTC (permalink / raw)
  To: Felix Willgerodt via Gdb-patches

>>>>> "Felix" == Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org> writes:

Felix> Changes to v1:
Felix> * Added a testcase to patch 1.

Thank you.  These are both OK.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2 0/2] Expression parser fixes for address space qualifiers.
  2021-04-19 19:43 ` [PATCH v2 0/2] Expression parser fixes for address space qualifiers Tom Tromey
@ 2021-04-20  6:51   ` Willgerodt, Felix
  0 siblings, 0 replies; 5+ messages in thread
From: Willgerodt, Felix @ 2021-04-20  6:51 UTC (permalink / raw)
  To: Tom Tromey, Felix Willgerodt via Gdb-patches

Tom> Thank you.  These are both OK.

Thanks, I just pushed them.

Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-20  6:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-06  9:29 [PATCH v2 0/2] Expression parser fixes for address space qualifiers Felix Willgerodt
2021-04-06  9:29 ` [PATCH v2 1/2] gdb: Allow address space qualifier parsing in C++ Felix Willgerodt
2021-04-06  9:29 ` [PATCH v2 2/2] gdb: Fix reduce/reduce conflicts for qualifier_seq_noopt in the C parser Felix Willgerodt
2021-04-19 19:43 ` [PATCH v2 0/2] Expression parser fixes for address space qualifiers Tom Tromey
2021-04-20  6:51   ` Willgerodt, Felix

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).