diff options
author | Felix Willgerodt <felix.willgerodt@intel.com> | 2021-04-20 08:43:08 +0200 |
---|---|---|
committer | Felix Willgerodt <felix.willgerodt@intel.com> | 2021-04-20 08:43:09 +0200 |
commit | 525174e886044ce3538b13545939421032f77a1b (patch) | |
tree | eab6e8bf24f68745a3c84781b158a08bc2fa33cf /gdb/c-exp.y | |
parent | 66d6b8522e76c158d1224837650674d5c3eff17f (diff) | |
download | gdb-525174e886044ce3538b13545939421032f77a1b.zip gdb-525174e886044ce3538b13545939421032f77a1b.tar.gz gdb-525174e886044ce3538b13545939421032f77a1b.tar.bz2 |
gdb: Allow address space qualifier parsing in C++.
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-04-20 Felix Willgerodt <felix.willgerodt@intel.com>
* c-exp.y (single_qualifier): Handle UNKNOWN_CPP_NAME.
gdb/testsuite/ChangeLog:
2021-04-20 Felix Willgerodt <felix.willgerodt@intel.com>
* gdb.base/address_space_qualifier.exp: New file.
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r-- | gdb/c-exp.y | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 865b155..3e416f4 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1267,6 +1267,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: |