gdb-gdb.py: strip typedefs in intrusive_list printer assertion
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
Commit Message
When debugging gdb itself and trying to print a intrusive_list that has
more than one element, I get:
File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 365, in _children_generator
node_ptr = self._as_node_ptr(elem_ptr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 345, in _as_node_ptr
assert elem_ptr.type.code == gdb.TYPE_CODE_PTR
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
This is because node_ptr is a typedef
(intrusive_list_base_iterator::pointer). Add a call to strip_typedefs
to get to the real type.
Enhance gdb.gdb/python-helper.exp with a test that would have caught
this bug.
Change-Id: I3eaca8de5ed06d05756ed979332b6a431e15b700
---
gdb/gdb-gdb.py.in | 2 +-
gdb/testsuite/gdb.gdb/python-helper.exp | 15 +++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
base-commit: 0ed152c5c6b3c72fc505b331ed77e08b438d643a
Comments
Simon Marchi <simon.marchi@polymtl.ca> writes:
> When debugging gdb itself and trying to print a intrusive_list that has
> more than one element, I get:
>
> File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 365, in _children_generator
> node_ptr = self._as_node_ptr(elem_ptr)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 345, in _as_node_ptr
> assert elem_ptr.type.code == gdb.TYPE_CODE_PTR
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> AssertionError
>
> This is because node_ptr is a typedef
> (intrusive_list_base_iterator::pointer). Add a call to strip_typedefs
> to get to the real type.
>
> Enhance gdb.gdb/python-helper.exp with a test that would have caught
> this bug.
Thanks for extending the test case.
This LGTM.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Thanks,
Andrew
>
> Change-Id: I3eaca8de5ed06d05756ed979332b6a431e15b700
> ---
> gdb/gdb-gdb.py.in | 2 +-
> gdb/testsuite/gdb.gdb/python-helper.exp | 15 +++++++++++++++
> 2 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
> index b5a7fa4f3903..7cab6941f02c 100644
> --- a/gdb/gdb-gdb.py.in
> +++ b/gdb/gdb-gdb.py.in
> @@ -342,7 +342,7 @@ class IntrusiveListPrinter:
> corresponding intrusive_list_node.
> """
>
> - assert elem_ptr.type.code == gdb.TYPE_CODE_PTR
> + assert elem_ptr.type.strip_typedefs().code == gdb.TYPE_CODE_PTR
>
> if self._uses_member_node():
> # Node as a member: add the member node offset from to the element's
> diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
> index 8a8afb12257b..4589edc388fd 100644
> --- a/gdb/testsuite/gdb.gdb/python-helper.exp
> +++ b/gdb/testsuite/gdb.gdb/python-helper.exp
> @@ -111,6 +111,16 @@ proc test_python_helper {} {
> }
> }
>
> + # Add a second inferior, useful to the intrusive_list pretty-printer test
> + # below.
> + send_inferior "add-inferior\n"
> + gdb_test_multiple "" "add second inferior in inner GDB" {
> + -i "$inferior_spawn_id"
> + -re "Added inferior 2\r\n$gdb_prompt $" {
> + pass $gdb_test_name
> + }
> + }
> +
> # Send Ctrl-C to the inner GDB, this should kick us back to the
> # prompt of the outer GDB.
> send_inferior "\003"
> @@ -253,6 +263,11 @@ proc test_python_helper {} {
> # Test the htab_t pretty-printer.
> gdb_test -prompt $outer_prompt_re "print all_bfds" "htab_t with ${::decimal} elements = \\{${::hex}.*\\}"
>
> + # Test the intrusive_list pretty-printer. A bug occured in the
> + # pretty-printer for lists with more than one element. Verify that
> + # we see both elements of the inferior_list list being printed.
> + gdb_test -prompt $outer_prompt_re "print inferior_list" "intrusive list of inferior = {.*, num = 1,.*, num = 2,.*}"
> +
> return 0
> }
>
>
> base-commit: 0ed152c5c6b3c72fc505b331ed77e08b438d643a
> --
> 2.45.2
On 2024-07-19 07:42, Andrew Burgess wrote:
> Simon Marchi <simon.marchi@polymtl.ca> writes:
>
>> When debugging gdb itself and trying to print a intrusive_list that has
>> more than one element, I get:
>>
>> File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 365, in _children_generator
>> node_ptr = self._as_node_ptr(elem_ptr)
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> File "/home/simark/build/binutils-gdb-all-targets/gdb/gdb-gdb.py", line 345, in _as_node_ptr
>> assert elem_ptr.type.code == gdb.TYPE_CODE_PTR
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> AssertionError
>>
>> This is because node_ptr is a typedef
>> (intrusive_list_base_iterator::pointer). Add a call to strip_typedefs
>> to get to the real type.
>>
>> Enhance gdb.gdb/python-helper.exp with a test that would have caught
>> this bug.
>
> Thanks for extending the test case.
>
> This LGTM.
>
> Approved-By: Andrew Burgess <aburgess@redhat.com>
>
> Thanks,
> Andrew
Thanks, pushed.
Simon
@@ -342,7 +342,7 @@ class IntrusiveListPrinter:
corresponding intrusive_list_node.
"""
- assert elem_ptr.type.code == gdb.TYPE_CODE_PTR
+ assert elem_ptr.type.strip_typedefs().code == gdb.TYPE_CODE_PTR
if self._uses_member_node():
# Node as a member: add the member node offset from to the element's
@@ -111,6 +111,16 @@ proc test_python_helper {} {
}
}
+ # Add a second inferior, useful to the intrusive_list pretty-printer test
+ # below.
+ send_inferior "add-inferior\n"
+ gdb_test_multiple "" "add second inferior in inner GDB" {
+ -i "$inferior_spawn_id"
+ -re "Added inferior 2\r\n$gdb_prompt $" {
+ pass $gdb_test_name
+ }
+ }
+
# Send Ctrl-C to the inner GDB, this should kick us back to the
# prompt of the outer GDB.
send_inferior "\003"
@@ -253,6 +263,11 @@ proc test_python_helper {} {
# Test the htab_t pretty-printer.
gdb_test -prompt $outer_prompt_re "print all_bfds" "htab_t with ${::decimal} elements = \\{${::hex}.*\\}"
+ # Test the intrusive_list pretty-printer. A bug occured in the
+ # pretty-printer for lists with more than one element. Verify that
+ # we see both elements of the inferior_list list being printed.
+ gdb_test -prompt $outer_prompt_re "print inferior_list" "intrusive list of inferior = {.*, num = 1,.*, num = 2,.*}"
+
return 0
}