* [PATCH] gdb: fix field names of GDB's type main_type structure
@ 2021-02-08 22:58 Andrew Burgess
2021-02-24 17:42 ` Andrew Burgess
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2021-02-08 22:58 UTC (permalink / raw)
To: gdb-patches
In commit:
commit 5b7d941b90d1a232dc144dc14850dd2fb63c35da
Date: Fri Jan 22 12:21:09 2021 -0500
gdb: add owner-related methods to struct type
two fields of struct maint_type were renamed. 'flag_objfile_owned'
became 'm_flag_objfile_owned' and 'owner' became 'm_owner'. Update
our python helper script to take this into account.
I've made an attempt at writing a test to do some basic testing of the
gdb-gdb.py helper script. The new test checks that the pretty
printers for GDB's type structures all work. We can extend this test
later as needed.
gdb/ChangeLog:
* gdb-gdb.py.in (StructMainTypePrettyPrinter) <owner_to_string>:
Updated fields names flag_objfile_owned to m_flag_objfile_owned,
and owner to m_owner.
gdb/testsuite/ChangeLog:
* gdb.gdb/python-helper.exp: New file.
---
gdb/ChangeLog | 6 ++
gdb/gdb-gdb.py.in | 6 +-
gdb/testsuite/ChangeLog | 4 +
gdb/testsuite/gdb.gdb/python-helper.exp | 138 ++++++++++++++++++++++++
4 files changed, 151 insertions(+), 3 deletions(-)
create mode 100644 gdb/testsuite/gdb.gdb/python-helper.exp
diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 2b1c7ded4b6..f58b3073d5c 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -142,10 +142,10 @@ class StructMainTypePrettyPrinter:
def owner_to_string(self):
"""Return an image of component "owner".
"""
- if self.val['flag_objfile_owned'] != 0:
- return "%s (objfile)" % self.val['owner']['objfile']
+ if self.val['m_flag_objfile_owned'] != 0:
+ return "%s (objfile)" % self.val['m_owner']['objfile']
else:
- return "%s (gdbarch)" % self.val['owner']['gdbarch']
+ return "%s (gdbarch)" % self.val['m_owner']['gdbarch']
def struct_field_location_img(self, field_val):
"""Return an image of the loc component inside the given field
diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
new file mode 100644
index 00000000000..5753666a9e7
--- /dev/null
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -0,0 +1,138 @@
+# 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/>.
+
+# This test exercises the gdb-gdb.py helper script that is generated
+# into the GDB build directory. This script is intended for use by
+# developers to make debugging GDB easier.
+
+load_lib selftest-support.exp
+
+if [target_info exists gdb,noinferiorio] {
+ verbose "Skipping because of no inferiorio capabilities."
+ return
+}
+
+# Find the helper script in the GDB build directory.
+set py_helper_script [file dirname $GDB]/gdb-gdb.py
+if { ![file readable $py_helper_script] \
+ || [file type $py_helper_script] != "file" } {
+ untested "failed to find gdb-gdb.py helper script"
+ return
+}
+
+# Start GDB and check that we have python support.
+gdb_start
+if { [skip_python_tests] } {
+ untested "skipped gdb-gdb.py tests due to lack of python support"
+ return
+}
+gdb_exit
+
+# The main test. This is called by the self-test framework once GDB
+# has been started on a copy of itself.
+proc test_python_helper {} {
+ global py_helper_script decimal hex gdb_prompt
+
+ # Source the python helper script. This script registers the
+ # pretty printer for the object file called 'gdb', however, in our
+ # selftests we rename 'gdb' to 'xgdb', so the pretty printer
+ # doesn't get registered by default.
+ #
+ # So, after sourcing the script we do our own objfile scan and
+ # register the pretty printer for the objfile called 'xgdb'.
+ gdb_test_no_output "source $py_helper_script" \
+ "source gdb-gdb.py helper script"
+ gdb_test [multi_line_input \
+ "python" \
+ "for objfile in gdb.objfiles():" \
+ " if os.path.basename(objfile.filename) == \"xgdb\":" \
+ " objfile.pretty_printers.append(type_lookup_function)" \
+ "end"] ".*" \
+ "register the type pretty printer"
+
+ # Now place a breakpoint somewhere useful. This can be any function that:
+ # (a) is easy to reach by issuing a simple gdb command, and
+ # (b) is unlikely to be modified very often within gdb, and
+ # (c) has a parameter that is either a 'struct type *' or a 'struct value *'.
+ gdb_breakpoint value_print
+
+ # Adjust the prompt on the outer gdb, this just makes things a
+ # little clearer when trying to unpick which GDB is active.
+ send_inferior "set prompt (xgdb) \n"
+ set msg "Set xgdb_prompt"
+ gdb_test_multiple "" $msg {
+ -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
+ pass $msg
+ }
+ }
+
+ # Send a command to the outer gdb to continue the inner gdb.
+ gdb_test_multiple "continue" "start inner gdb" {
+ -re "\r\n$gdb_prompt $" {
+ pass $gdb_test_name
+ }
+ }
+
+ # Send a command to the inner GDB, this should result in the outer
+ # GDB stopping at the breakpoint we just created.
+ gdb_test_multiple "print 1" "hit breakpoint in inner gdb" {
+ -re "hit Breakpoint $decimal, value_print.*\\(xgdb\\) $" {
+ pass $gdb_test_name
+ }
+ }
+
+ # Now inspect the type of parameter VAL, this should trigger the
+ # pretty printers.
+ set answer [multi_line \
+ "${decimal} = " \
+ "{pointer_type = 0x0," \
+ " reference_type = 0x0," \
+ " chain = 0x0," \
+ " instance_flags = 0," \
+ " length = $decimal," \
+ " main_type = $hex}" \
+ "\\(xgdb\\) $"]
+ gdb_test_multiple "print *val->type" "pretty print type" {
+ -re "$answer" {
+ pass $gdb_test_name
+ }
+ -re "There is no member named.*\r\n\\(xgdb\\) $" {
+ fail $gdb_test_name
+ }
+ }
+
+ set answer [multi_line \
+ "$decimal = " \
+ "{name = $hex \"int\"," \
+ " code = TYPE_CODE_INT," \
+ " flags = \[^\r\n\]+," \
+ " owner = $hex \\(gdbarch\\)," \
+ " target_type = 0x0," \
+ " type_specific_field = TYPE_SPECIFIC_NONE}" \
+ "\\(xgdb\\) $"]
+ gdb_test_multiple "print *val->type->main_type" "pretty print type->main_type" {
+ -re "$answer" {
+ pass $gdb_test_name
+ }
+ -re "There is no member named.*\r\n\\(xgdb\\) $" {
+ fail $gdb_test_name
+ }
+ }
+
+ return 0
+}
+
+# Use the self-test framework to run the test.
+do_self_tests captured_main test_python_helper
--
2.25.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gdb: fix field names of GDB's type main_type structure
2021-02-08 22:58 [PATCH] gdb: fix field names of GDB's type main_type structure Andrew Burgess
@ 2021-02-24 17:42 ` Andrew Burgess
2021-03-05 17:49 ` Andrew Burgess
2021-03-05 18:04 ` Simon Marchi
0 siblings, 2 replies; 5+ messages in thread
From: Andrew Burgess @ 2021-02-24 17:42 UTC (permalink / raw)
To: gdb-patches
Ping!
The changes in gdb-gdb.py are straight forward. I wonder if anyone
wants to comment on the abomination of a test?
Thanks,
Andrew
* Andrew Burgess <andrew.burgess@embecosm.com> [2021-02-08 22:58:33 +0000]:
> In commit:
>
> commit 5b7d941b90d1a232dc144dc14850dd2fb63c35da
> Date: Fri Jan 22 12:21:09 2021 -0500
>
> gdb: add owner-related methods to struct type
>
> two fields of struct maint_type were renamed. 'flag_objfile_owned'
> became 'm_flag_objfile_owned' and 'owner' became 'm_owner'. Update
> our python helper script to take this into account.
>
> I've made an attempt at writing a test to do some basic testing of the
> gdb-gdb.py helper script. The new test checks that the pretty
> printers for GDB's type structures all work. We can extend this test
> later as needed.
>
> gdb/ChangeLog:
>
> * gdb-gdb.py.in (StructMainTypePrettyPrinter) <owner_to_string>:
> Updated fields names flag_objfile_owned to m_flag_objfile_owned,
> and owner to m_owner.
>
> gdb/testsuite/ChangeLog:
>
> * gdb.gdb/python-helper.exp: New file.
> ---
> gdb/ChangeLog | 6 ++
> gdb/gdb-gdb.py.in | 6 +-
> gdb/testsuite/ChangeLog | 4 +
> gdb/testsuite/gdb.gdb/python-helper.exp | 138 ++++++++++++++++++++++++
> 4 files changed, 151 insertions(+), 3 deletions(-)
> create mode 100644 gdb/testsuite/gdb.gdb/python-helper.exp
>
> diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
> index 2b1c7ded4b6..f58b3073d5c 100644
> --- a/gdb/gdb-gdb.py.in
> +++ b/gdb/gdb-gdb.py.in
> @@ -142,10 +142,10 @@ class StructMainTypePrettyPrinter:
> def owner_to_string(self):
> """Return an image of component "owner".
> """
> - if self.val['flag_objfile_owned'] != 0:
> - return "%s (objfile)" % self.val['owner']['objfile']
> + if self.val['m_flag_objfile_owned'] != 0:
> + return "%s (objfile)" % self.val['m_owner']['objfile']
> else:
> - return "%s (gdbarch)" % self.val['owner']['gdbarch']
> + return "%s (gdbarch)" % self.val['m_owner']['gdbarch']
>
> def struct_field_location_img(self, field_val):
> """Return an image of the loc component inside the given field
> diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
> new file mode 100644
> index 00000000000..5753666a9e7
> --- /dev/null
> +++ b/gdb/testsuite/gdb.gdb/python-helper.exp
> @@ -0,0 +1,138 @@
> +# 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/>.
> +
> +# This test exercises the gdb-gdb.py helper script that is generated
> +# into the GDB build directory. This script is intended for use by
> +# developers to make debugging GDB easier.
> +
> +load_lib selftest-support.exp
> +
> +if [target_info exists gdb,noinferiorio] {
> + verbose "Skipping because of no inferiorio capabilities."
> + return
> +}
> +
> +# Find the helper script in the GDB build directory.
> +set py_helper_script [file dirname $GDB]/gdb-gdb.py
> +if { ![file readable $py_helper_script] \
> + || [file type $py_helper_script] != "file" } {
> + untested "failed to find gdb-gdb.py helper script"
> + return
> +}
> +
> +# Start GDB and check that we have python support.
> +gdb_start
> +if { [skip_python_tests] } {
> + untested "skipped gdb-gdb.py tests due to lack of python support"
> + return
> +}
> +gdb_exit
> +
> +# The main test. This is called by the self-test framework once GDB
> +# has been started on a copy of itself.
> +proc test_python_helper {} {
> + global py_helper_script decimal hex gdb_prompt
> +
> + # Source the python helper script. This script registers the
> + # pretty printer for the object file called 'gdb', however, in our
> + # selftests we rename 'gdb' to 'xgdb', so the pretty printer
> + # doesn't get registered by default.
> + #
> + # So, after sourcing the script we do our own objfile scan and
> + # register the pretty printer for the objfile called 'xgdb'.
> + gdb_test_no_output "source $py_helper_script" \
> + "source gdb-gdb.py helper script"
> + gdb_test [multi_line_input \
> + "python" \
> + "for objfile in gdb.objfiles():" \
> + " if os.path.basename(objfile.filename) == \"xgdb\":" \
> + " objfile.pretty_printers.append(type_lookup_function)" \
> + "end"] ".*" \
> + "register the type pretty printer"
> +
> + # Now place a breakpoint somewhere useful. This can be any function that:
> + # (a) is easy to reach by issuing a simple gdb command, and
> + # (b) is unlikely to be modified very often within gdb, and
> + # (c) has a parameter that is either a 'struct type *' or a 'struct value *'.
> + gdb_breakpoint value_print
> +
> + # Adjust the prompt on the outer gdb, this just makes things a
> + # little clearer when trying to unpick which GDB is active.
> + send_inferior "set prompt (xgdb) \n"
> + set msg "Set xgdb_prompt"
> + gdb_test_multiple "" $msg {
> + -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
> + pass $msg
> + }
> + }
> +
> + # Send a command to the outer gdb to continue the inner gdb.
> + gdb_test_multiple "continue" "start inner gdb" {
> + -re "\r\n$gdb_prompt $" {
> + pass $gdb_test_name
> + }
> + }
> +
> + # Send a command to the inner GDB, this should result in the outer
> + # GDB stopping at the breakpoint we just created.
> + gdb_test_multiple "print 1" "hit breakpoint in inner gdb" {
> + -re "hit Breakpoint $decimal, value_print.*\\(xgdb\\) $" {
> + pass $gdb_test_name
> + }
> + }
> +
> + # Now inspect the type of parameter VAL, this should trigger the
> + # pretty printers.
> + set answer [multi_line \
> + "${decimal} = " \
> + "{pointer_type = 0x0," \
> + " reference_type = 0x0," \
> + " chain = 0x0," \
> + " instance_flags = 0," \
> + " length = $decimal," \
> + " main_type = $hex}" \
> + "\\(xgdb\\) $"]
> + gdb_test_multiple "print *val->type" "pretty print type" {
> + -re "$answer" {
> + pass $gdb_test_name
> + }
> + -re "There is no member named.*\r\n\\(xgdb\\) $" {
> + fail $gdb_test_name
> + }
> + }
> +
> + set answer [multi_line \
> + "$decimal = " \
> + "{name = $hex \"int\"," \
> + " code = TYPE_CODE_INT," \
> + " flags = \[^\r\n\]+," \
> + " owner = $hex \\(gdbarch\\)," \
> + " target_type = 0x0," \
> + " type_specific_field = TYPE_SPECIFIC_NONE}" \
> + "\\(xgdb\\) $"]
> + gdb_test_multiple "print *val->type->main_type" "pretty print type->main_type" {
> + -re "$answer" {
> + pass $gdb_test_name
> + }
> + -re "There is no member named.*\r\n\\(xgdb\\) $" {
> + fail $gdb_test_name
> + }
> + }
> +
> + return 0
> +}
> +
> +# Use the self-test framework to run the test.
> +do_self_tests captured_main test_python_helper
> --
> 2.25.4
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gdb: fix field names of GDB's type main_type structure
2021-02-24 17:42 ` Andrew Burgess
@ 2021-03-05 17:49 ` Andrew Burgess
2021-03-05 18:04 ` Simon Marchi
1 sibling, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2021-03-05 17:49 UTC (permalink / raw)
To: gdb-patches
I'm going to push this fix next week.
Thanks,
Andrew
* Andrew Burgess <andrew.burgess@embecosm.com> [2021-02-24 17:42:34 +0000]:
> Ping!
>
> The changes in gdb-gdb.py are straight forward. I wonder if anyone
> wants to comment on the abomination of a test?
>
> Thanks,
> Andrew
>
> * Andrew Burgess <andrew.burgess@embecosm.com> [2021-02-08 22:58:33 +0000]:
>
> > In commit:
> >
> > commit 5b7d941b90d1a232dc144dc14850dd2fb63c35da
> > Date: Fri Jan 22 12:21:09 2021 -0500
> >
> > gdb: add owner-related methods to struct type
> >
> > two fields of struct maint_type were renamed. 'flag_objfile_owned'
> > became 'm_flag_objfile_owned' and 'owner' became 'm_owner'. Update
> > our python helper script to take this into account.
> >
> > I've made an attempt at writing a test to do some basic testing of the
> > gdb-gdb.py helper script. The new test checks that the pretty
> > printers for GDB's type structures all work. We can extend this test
> > later as needed.
> >
> > gdb/ChangeLog:
> >
> > * gdb-gdb.py.in (StructMainTypePrettyPrinter) <owner_to_string>:
> > Updated fields names flag_objfile_owned to m_flag_objfile_owned,
> > and owner to m_owner.
> >
> > gdb/testsuite/ChangeLog:
> >
> > * gdb.gdb/python-helper.exp: New file.
> > ---
> > gdb/ChangeLog | 6 ++
> > gdb/gdb-gdb.py.in | 6 +-
> > gdb/testsuite/ChangeLog | 4 +
> > gdb/testsuite/gdb.gdb/python-helper.exp | 138 ++++++++++++++++++++++++
> > 4 files changed, 151 insertions(+), 3 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.gdb/python-helper.exp
> >
> > diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
> > index 2b1c7ded4b6..f58b3073d5c 100644
> > --- a/gdb/gdb-gdb.py.in
> > +++ b/gdb/gdb-gdb.py.in
> > @@ -142,10 +142,10 @@ class StructMainTypePrettyPrinter:
> > def owner_to_string(self):
> > """Return an image of component "owner".
> > """
> > - if self.val['flag_objfile_owned'] != 0:
> > - return "%s (objfile)" % self.val['owner']['objfile']
> > + if self.val['m_flag_objfile_owned'] != 0:
> > + return "%s (objfile)" % self.val['m_owner']['objfile']
> > else:
> > - return "%s (gdbarch)" % self.val['owner']['gdbarch']
> > + return "%s (gdbarch)" % self.val['m_owner']['gdbarch']
> >
> > def struct_field_location_img(self, field_val):
> > """Return an image of the loc component inside the given field
> > diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
> > new file mode 100644
> > index 00000000000..5753666a9e7
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.gdb/python-helper.exp
> > @@ -0,0 +1,138 @@
> > +# 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/>.
> > +
> > +# This test exercises the gdb-gdb.py helper script that is generated
> > +# into the GDB build directory. This script is intended for use by
> > +# developers to make debugging GDB easier.
> > +
> > +load_lib selftest-support.exp
> > +
> > +if [target_info exists gdb,noinferiorio] {
> > + verbose "Skipping because of no inferiorio capabilities."
> > + return
> > +}
> > +
> > +# Find the helper script in the GDB build directory.
> > +set py_helper_script [file dirname $GDB]/gdb-gdb.py
> > +if { ![file readable $py_helper_script] \
> > + || [file type $py_helper_script] != "file" } {
> > + untested "failed to find gdb-gdb.py helper script"
> > + return
> > +}
> > +
> > +# Start GDB and check that we have python support.
> > +gdb_start
> > +if { [skip_python_tests] } {
> > + untested "skipped gdb-gdb.py tests due to lack of python support"
> > + return
> > +}
> > +gdb_exit
> > +
> > +# The main test. This is called by the self-test framework once GDB
> > +# has been started on a copy of itself.
> > +proc test_python_helper {} {
> > + global py_helper_script decimal hex gdb_prompt
> > +
> > + # Source the python helper script. This script registers the
> > + # pretty printer for the object file called 'gdb', however, in our
> > + # selftests we rename 'gdb' to 'xgdb', so the pretty printer
> > + # doesn't get registered by default.
> > + #
> > + # So, after sourcing the script we do our own objfile scan and
> > + # register the pretty printer for the objfile called 'xgdb'.
> > + gdb_test_no_output "source $py_helper_script" \
> > + "source gdb-gdb.py helper script"
> > + gdb_test [multi_line_input \
> > + "python" \
> > + "for objfile in gdb.objfiles():" \
> > + " if os.path.basename(objfile.filename) == \"xgdb\":" \
> > + " objfile.pretty_printers.append(type_lookup_function)" \
> > + "end"] ".*" \
> > + "register the type pretty printer"
> > +
> > + # Now place a breakpoint somewhere useful. This can be any function that:
> > + # (a) is easy to reach by issuing a simple gdb command, and
> > + # (b) is unlikely to be modified very often within gdb, and
> > + # (c) has a parameter that is either a 'struct type *' or a 'struct value *'.
> > + gdb_breakpoint value_print
> > +
> > + # Adjust the prompt on the outer gdb, this just makes things a
> > + # little clearer when trying to unpick which GDB is active.
> > + send_inferior "set prompt (xgdb) \n"
> > + set msg "Set xgdb_prompt"
> > + gdb_test_multiple "" $msg {
> > + -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
> > + pass $msg
> > + }
> > + }
> > +
> > + # Send a command to the outer gdb to continue the inner gdb.
> > + gdb_test_multiple "continue" "start inner gdb" {
> > + -re "\r\n$gdb_prompt $" {
> > + pass $gdb_test_name
> > + }
> > + }
> > +
> > + # Send a command to the inner GDB, this should result in the outer
> > + # GDB stopping at the breakpoint we just created.
> > + gdb_test_multiple "print 1" "hit breakpoint in inner gdb" {
> > + -re "hit Breakpoint $decimal, value_print.*\\(xgdb\\) $" {
> > + pass $gdb_test_name
> > + }
> > + }
> > +
> > + # Now inspect the type of parameter VAL, this should trigger the
> > + # pretty printers.
> > + set answer [multi_line \
> > + "${decimal} = " \
> > + "{pointer_type = 0x0," \
> > + " reference_type = 0x0," \
> > + " chain = 0x0," \
> > + " instance_flags = 0," \
> > + " length = $decimal," \
> > + " main_type = $hex}" \
> > + "\\(xgdb\\) $"]
> > + gdb_test_multiple "print *val->type" "pretty print type" {
> > + -re "$answer" {
> > + pass $gdb_test_name
> > + }
> > + -re "There is no member named.*\r\n\\(xgdb\\) $" {
> > + fail $gdb_test_name
> > + }
> > + }
> > +
> > + set answer [multi_line \
> > + "$decimal = " \
> > + "{name = $hex \"int\"," \
> > + " code = TYPE_CODE_INT," \
> > + " flags = \[^\r\n\]+," \
> > + " owner = $hex \\(gdbarch\\)," \
> > + " target_type = 0x0," \
> > + " type_specific_field = TYPE_SPECIFIC_NONE}" \
> > + "\\(xgdb\\) $"]
> > + gdb_test_multiple "print *val->type->main_type" "pretty print type->main_type" {
> > + -re "$answer" {
> > + pass $gdb_test_name
> > + }
> > + -re "There is no member named.*\r\n\\(xgdb\\) $" {
> > + fail $gdb_test_name
> > + }
> > + }
> > +
> > + return 0
> > +}
> > +
> > +# Use the self-test framework to run the test.
> > +do_self_tests captured_main test_python_helper
> > --
> > 2.25.4
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gdb: fix field names of GDB's type main_type structure
2021-02-24 17:42 ` Andrew Burgess
2021-03-05 17:49 ` Andrew Burgess
@ 2021-03-05 18:04 ` Simon Marchi
2021-03-09 11:09 ` Andrew Burgess
1 sibling, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2021-03-05 18:04 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches
On 2021-02-24 12:42 p.m., Andrew Burgess wrote:> Ping!
>
> The changes in gdb-gdb.py are straight forward. I wonder if anyone
> wants to comment on the abomination of a test?
>
> Thanks,
> Andrew
I saw this before but then forgot about it. First, thanks for fixing
the pretty printer, I always forget to update it.
I think the test is fine (certainly better than no test). It is
adequately documented / commented, so I would be comfortable debugging
it, if I ever need to (no need to guess "why is it doing that!?").
Thanks!
Simon
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] gdb: fix field names of GDB's type main_type structure
2021-03-05 18:04 ` Simon Marchi
@ 2021-03-09 11:09 ` Andrew Burgess
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2021-03-09 11:09 UTC (permalink / raw)
To: gdb-patches
* Simon Marchi <simon.marchi@polymtl.ca> [2021-03-05 13:04:59 -0500]:
> On 2021-02-24 12:42 p.m., Andrew Burgess wrote:> Ping!
> >
> > The changes in gdb-gdb.py are straight forward. I wonder if anyone
> > wants to comment on the abomination of a test?
> >
> > Thanks,
> > Andrew
>
> I saw this before but then forgot about it. First, thanks for fixing
> the pretty printer, I always forget to update it.
>
> I think the test is fine (certainly better than no test). It is
> adequately documented / commented, so I would be comfortable debugging
> it, if I ever need to (no need to guess "why is it doing that!?").
Thanks for the feedback.
Below is the version that I actually pushed. This has a few minor
tweaks to the test, but nothing huge. The main change is that the
test now works with native-extended-gdbserver, I'd failed to spot that
this test previously failed on this target.
Thanks,
Andrew
---
commit fbb1aacebac7d1fd556cf9c46e9af89aaaa62398
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date: Mon Feb 8 21:24:52 2021 +0000
gdb: fix field names of GDB's type main_type structure
In commit:
commit 5b7d941b90d1a232dc144dc14850dd2fb63c35da
Date: Fri Jan 22 12:21:09 2021 -0500
gdb: add owner-related methods to struct type
two fields of struct maint_type were renamed. 'flag_objfile_owned'
became 'm_flag_objfile_owned' and 'owner' became 'm_owner'. Update
our python helper script to take this into account.
I've added a basic test that uses the self-test framework to load the
pretty printers, and print a type.
The test relies on stopping in GDB's `value_print` function.
gdb/ChangeLog:
* gdb-gdb.py.in (StructMainTypePrettyPrinter) <owner_to_string>:
Updated fields names flag_objfile_owned to m_flag_objfile_owned,
and owner to m_owner.
gdb/testsuite/ChangeLog:
* gdb.gdb/python-helper.exp: New file.
diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 2b1c7ded4b6..f58b3073d5c 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -142,10 +142,10 @@ class StructMainTypePrettyPrinter:
def owner_to_string(self):
"""Return an image of component "owner".
"""
- if self.val['flag_objfile_owned'] != 0:
- return "%s (objfile)" % self.val['owner']['objfile']
+ if self.val['m_flag_objfile_owned'] != 0:
+ return "%s (objfile)" % self.val['m_owner']['objfile']
else:
- return "%s (gdbarch)" % self.val['owner']['gdbarch']
+ return "%s (gdbarch)" % self.val['m_owner']['gdbarch']
def struct_field_location_img(self, field_val):
"""Return an image of the loc component inside the given field
diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
new file mode 100644
index 00000000000..54c256eb2e0
--- /dev/null
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -0,0 +1,142 @@
+# 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/>.
+
+# This test exercises the gdb-gdb.py helper script that is generated
+# into the GDB build directory. This script is intended for use by
+# developers to make debugging GDB easier.
+
+load_lib selftest-support.exp
+
+if [target_info exists gdb,noinferiorio] {
+ verbose "Skipping because of no inferiorio capabilities."
+ return
+}
+
+# Find the helper script in the GDB build directory.
+set py_helper_script [file dirname $GDB]/gdb-gdb.py
+if { ![file readable $py_helper_script] \
+ || [file type $py_helper_script] != "file" } {
+ untested "failed to find gdb-gdb.py helper script"
+ return
+}
+
+# Start GDB and check that we have python support.
+gdb_start
+if { [skip_python_tests] } {
+ untested "skipped gdb-gdb.py tests due to lack of python support"
+ return
+}
+gdb_exit
+
+# The main test. This is called by the self-test framework once GDB
+# has been started on a copy of itself.
+proc test_python_helper {} {
+ global py_helper_script decimal hex gdb_prompt
+ global inferior_spawn_id
+
+ # Source the python helper script. This script registers the
+ # pretty printer for the object file called 'gdb', however, in our
+ # selftests we rename 'gdb' to 'xgdb', so the pretty printer
+ # doesn't get registered by default.
+ #
+ # So, after sourcing the script we do our own objfile scan and
+ # register the pretty printer for the objfile called 'xgdb'.
+ gdb_test_no_output "source $py_helper_script" \
+ "source gdb-gdb.py helper script"
+ gdb_test [multi_line_input \
+ "python" \
+ "for objfile in gdb.objfiles():" \
+ " if os.path.basename(objfile.filename) == \"xgdb\":" \
+ " objfile.pretty_printers.append(type_lookup_function)" \
+ "end"] ".*" \
+ "register the type pretty printer"
+
+ # Now place a breakpoint somewhere useful. This can be any function that:
+ # (a) is easy to reach by issuing a simple gdb command, and
+ # (b) is unlikely to be modified very often within gdb, and
+ # (c) has a parameter that is either a 'struct type *' or a 'struct value *'.
+ gdb_breakpoint value_print
+
+ # Adjust the prompt on the outer gdb, this just makes things a
+ # little clearer when trying to unpick which GDB is active.
+ gdb_test_multiple "set prompt (xgdb) " "set xgdb prompt" {
+ -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
+ pass $gdb_test_name
+ }
+ }
+
+ # Send a command to the outer GDB to continue the inner GDB. The
+ # stop is being detected from the inner GDB, hence the use of -i
+ # here.
+ gdb_test_multiple "continue" "start inner gdb" {
+ -i "$inferior_spawn_id"
+ -re "\r\n$gdb_prompt $" {
+ pass $gdb_test_name
+ }
+ }
+
+ # Send a command to the inner GDB (hence send_inferior), this
+ # should result in the outer GDB stopping at the breakpoint we
+ # just created.
+ send_inferior "print 1\n"
+ gdb_test_multiple "" "hit breakpoint in inner gdb" {
+ -re "hit Breakpoint $decimal, value_print.*\\(xgdb\\) $" {
+ pass $gdb_test_name
+ }
+ }
+
+ # Now inspect the type of parameter VAL, this should trigger the
+ # pretty printers.
+ set answer [multi_line \
+ "${decimal} = " \
+ "{pointer_type = 0x0," \
+ " reference_type = 0x0," \
+ " chain = 0x0," \
+ " instance_flags = 0," \
+ " length = $decimal," \
+ " main_type = $hex}" \
+ "\\(xgdb\\) $"]
+ gdb_test_multiple "print *val->type" "pretty print type" {
+ -re "$answer" {
+ pass $gdb_test_name
+ }
+ -re "There is no member named.*\r\n\\(xgdb\\) $" {
+ fail $gdb_test_name
+ }
+ }
+
+ set answer [multi_line \
+ "$decimal = " \
+ "{name = $hex \"int\"," \
+ " code = TYPE_CODE_INT," \
+ " flags = \[^\r\n\]+," \
+ " owner = $hex \\(gdbarch\\)," \
+ " target_type = 0x0," \
+ " type_specific_field = TYPE_SPECIFIC_NONE}" \
+ "\\(xgdb\\) $"]
+ gdb_test_multiple "print *val->type->main_type" "pretty print type->main_type" {
+ -re "$answer" {
+ pass $gdb_test_name
+ }
+ -re "There is no member named.*\r\n\\(xgdb\\) $" {
+ fail $gdb_test_name
+ }
+ }
+
+ return 0
+}
+
+# Use the self-test framework to run the test.
+do_self_tests captured_main test_python_helper
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-09 11:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-08 22:58 [PATCH] gdb: fix field names of GDB's type main_type structure Andrew Burgess
2021-02-24 17:42 ` Andrew Burgess
2021-03-05 17:49 ` Andrew Burgess
2021-03-05 18:04 ` Simon Marchi
2021-03-09 11:09 ` Andrew Burgess
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).