[2/2] gdb: Fix reduce/reduce conflicts for qualifier_seq_noopt in the C parser.

Message ID 20210326142609.245016-3-felix.willgerodt@intel.com
State Superseded
Headers show
Series
  • Expression parser fixes for address space qualifiers.
Related show

Commit Message

Lancelot SIX via Gdb-patches March 26, 2021, 2:26 p.m.
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(-)

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

Comments

Tom Tromey April 1, 2021, 6:20 p.m. | #1
>>>>> "Felix" == Felix Willgerodt via Gdb-patches <gdb-patches@sourceware.org> writes:


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

Probably we should follow whatever GCC does here.

Felix> 	* c-exp.y (qualifier_seq_noopt): Replace qualifier_seq with
Felix> 	qualifier_seq_noopt.

This seems fine to me.  Thanks again.

Tom
Lancelot SIX via Gdb-patches April 2, 2021, 12:33 p.m. | #2
>Felix> Note that how the binding of this qualifier is interpreted and 

>Felix> resolved for an address/pointer is target specific.  Hence only 

>Felix> the prepended qualifier works for AVR, even if it seems 

>Felix> syntactically incorrect.  I won't change this for AVR, as I am not familiar with that target.


Tom>Probably we should follow whatever GCC does here.

We should, but we don't for AVR (the binding in GDBs internal type representation is correct). I checked with avr-gcc 9.2.0 and 'target sim avr', hence this paragraph.
But I am not familiar enough with AVR to fix this, as it would require changes to the avr-tdep file and the address tagging/translation logic in there.
	
Thanks, I will push this together with the first patch once the testing question is resolved there.
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

Patch

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index e2ceb2057a1..256937f2034 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: