gdbhooks: Update gdbhooks.py for recent tree_code_type changes [PR108634]

Message ID ZBCV7EF97QkCHs+U@tucnak
State Unresolved
Headers
Series gdbhooks: Update gdbhooks.py for recent tree_code_type changes [PR108634] |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jakub Jelinek March 14, 2023, 3:42 p.m. UTC
  Hi!

On Mon, Mar 13, 2023 at 04:15:12PM -0400, Jason Merrill wrote:
> The r13-6577 change to use tree_code_type_tmpl in earlier C++ dialects broke
> gdbhooks, which expects tree_code_type to always be available.  I considered
> trying to make gdbhooks more robust, but it seemed simpler to define
> tree_code_type as a reference to the template.

As I said earlier, I think it is better to tweak gdbhooks.

The following patch does that, I've tested it now both with gcc 12 and
older gcc as system compiler and the patch fixed the latter while keeping
the former working as before.

Ok for trunk?

2023-03-14  Jakub Jelinek  <jakub@redhat.com>

	PR plugins/108634
	* gdbhooks.py (TreePrinter.to_string): Wrap
	gdb.parse_and_eval('tree_code_type') in a try block, parse
	and eval 'tree_code_type_tmpl<0>::tree_code_type' instead if it
	raises exception.  Update comments for the recent tree_code_type
	changes.



	Jakub
  

Comments

Jason Merrill March 14, 2023, 3:54 p.m. UTC | #1
On 3/14/23 11:42, Jakub Jelinek wrote:
> Hi!
> 
> On Mon, Mar 13, 2023 at 04:15:12PM -0400, Jason Merrill wrote:
>> The r13-6577 change to use tree_code_type_tmpl in earlier C++ dialects broke
>> gdbhooks, which expects tree_code_type to always be available.  I considered
>> trying to make gdbhooks more robust, but it seemed simpler to define
>> tree_code_type as a reference to the template.
> 
> As I said earlier, I think it is better to tweak gdbhooks.
> 
> The following patch does that, I've tested it now both with gcc 12 and
> older gcc as system compiler and the patch fixed the latter while keeping
> the former working as before.
> 
> Ok for trunk?

LGTM, OK on Friday if no other comments.

> 2023-03-14  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR plugins/108634
> 	* gdbhooks.py (TreePrinter.to_string): Wrap
> 	gdb.parse_and_eval('tree_code_type') in a try block, parse
> 	and eval 'tree_code_type_tmpl<0>::tree_code_type' instead if it
> 	raises exception.  Update comments for the recent tree_code_type
> 	changes.
> 
> --- gcc/gdbhooks.py.jj	2023-03-04 11:24:01.348791347 +0100
> +++ gcc/gdbhooks.py	2023-03-14 16:35:48.445671242 +0100
> @@ -220,13 +220,23 @@ class TreePrinter:
>   
>           val_TREE_CODE = self.node.TREE_CODE()
>   
> -        # extern const enum tree_code_class tree_code_type[];
> +        # constexpr inline enum tree_code_class tree_code_type[] = { ... };
>           # #define TREE_CODE_CLASS(CODE)	tree_code_type[(int) (CODE)]
> +        # or
> +        # template <int N>
> +        # struct tree_code_type_tmpl {
> +        # static constexpr enum tree_code_class tree_code_type[] = { ... };
> +        # }; };
> +        # #define TREE_CODE_CLASS(CODE) \
> +        # tree_code_type_tmpl <0>::tree_code_type[(int) (CODE)]
>   
>           if val_TREE_CODE == 0xa5a5:
>               return '<ggc_freed 0x%x>' % intptr(self.gdbval)
>   
> -        val_tree_code_type = gdb.parse_and_eval('tree_code_type')
> +        try:
> +            val_tree_code_type = gdb.parse_and_eval('tree_code_type')
> +        except:
> +            val_tree_code_type = gdb.parse_and_eval('tree_code_type_tmpl<0>::tree_code_type')
>           val_tclass = val_tree_code_type[val_TREE_CODE]
>   
>           val_tree_code_name = gdb.parse_and_eval('tree_code_name')
> 
> 
> 	Jakub
>
  

Patch

--- gcc/gdbhooks.py.jj	2023-03-04 11:24:01.348791347 +0100
+++ gcc/gdbhooks.py	2023-03-14 16:35:48.445671242 +0100
@@ -220,13 +220,23 @@  class TreePrinter:
 
         val_TREE_CODE = self.node.TREE_CODE()
 
-        # extern const enum tree_code_class tree_code_type[];
+        # constexpr inline enum tree_code_class tree_code_type[] = { ... };
         # #define TREE_CODE_CLASS(CODE)	tree_code_type[(int) (CODE)]
+        # or
+        # template <int N>
+        # struct tree_code_type_tmpl {
+        # static constexpr enum tree_code_class tree_code_type[] = { ... };
+        # }; };
+        # #define TREE_CODE_CLASS(CODE) \
+        # tree_code_type_tmpl <0>::tree_code_type[(int) (CODE)]
 
         if val_TREE_CODE == 0xa5a5:
             return '<ggc_freed 0x%x>' % intptr(self.gdbval)
 
-        val_tree_code_type = gdb.parse_and_eval('tree_code_type')
+        try:
+            val_tree_code_type = gdb.parse_and_eval('tree_code_type')
+        except:
+            val_tree_code_type = gdb.parse_and_eval('tree_code_type_tmpl<0>::tree_code_type')
         val_tclass = val_tree_code_type[val_TREE_CODE]
 
         val_tree_code_name = gdb.parse_and_eval('tree_code_name')