public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] PR other/65366: Fix gdbhooks.py for GDB with Python3
@ 2015-03-09 21:43 Jan Kratochvil
  2015-06-01 20:59 ` Jason Merrill
  2015-06-03  8:25 ` Richard Biener
  0 siblings, 2 replies; 9+ messages in thread
From: Jan Kratochvil @ 2015-03-09 21:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: Phil Muldoon

[-- Attachment #1: Type: text/plain, Size: 899 bytes --]

Hi,

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65366

GDB Python support upstream has always been compatible with Python3.
Fedora since F-22 builds GDB with Python3 by default (<=F-21 GDB used Python2).

gdbhooks.py in GCC trunk is compatible with Python2 but not Python3.

gdb-7.9-10.fc23.x86_64
(gdb) source /home/jkratoch/redhat/gcchead/gcc/c/../gdbhooks.py
  File "/home/jkratoch/redhat/gcchead/gcc/c/../gdbhooks.py", line 372
    print format_[i]
                ^
SyntaxError: Missing parentheses in call to 'print'

Additionally after fixing the 'print' incompatibility one gets randomly:

dependence_info = {clique = 257, Python Exception <class 'NameError'> name 'long' is not defined:
base = 1}}}, type = }, 

OK for check-in?

The long()->int() change I have followed from:
	https://stackoverflow.com/questions/14904814/nameerror-global-name-long-is-not-defined/14904834


Thanks,
Jan

[-- Attachment #2: gdbhooks.py.patch --]
[-- Type: text/plain, Size: 7125 bytes --]

2015-03-09  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR other/65366
	* gdbhooks.py: Use int(...) instead of long(...).  Use print(...)
	instead of print ... .

Index: gcc/gdbhooks.py
===================================================================
--- gcc/gdbhooks.py	(revision 221277)
+++ gcc/gdbhooks.py	(working copy)
@@ -158,7 +158,7 @@ class Tree:
         self.gdbval = gdbval
 
     def is_nonnull(self):
-        return long(self.gdbval)
+        return int(self.gdbval)
 
     def TREE_CODE(self):
         """
@@ -197,7 +197,7 @@ class TreePrinter:
         # like gcc/print-tree.c:print_node_brief
         # #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
         # tree_code_name[(int) TREE_CODE (node)])
-        if long(self.gdbval) == 0:
+        if int(self.gdbval) == 0:
             return '<tree 0x0>'
 
         val_TREE_CODE = self.node.TREE_CODE()
@@ -209,17 +209,17 @@ class TreePrinter:
         val_tclass = val_tree_code_type[val_TREE_CODE]
 
         val_tree_code_name = gdb.parse_and_eval('tree_code_name')
-        val_code_name = val_tree_code_name[long(val_TREE_CODE)]
-        #print val_code_name.string()
+        val_code_name = val_tree_code_name[int(val_TREE_CODE)]
+        #print(val_code_name.string())
 
-        result = '<%s 0x%x' % (val_code_name.string(), long(self.gdbval))
-        if long(val_tclass) == tcc_declaration:
+        result = '<%s 0x%x' % (val_code_name.string(), int(self.gdbval))
+        if int(val_tclass) == tcc_declaration:
             tree_DECL_NAME = self.node.DECL_NAME()
             if tree_DECL_NAME.is_nonnull():
                  result += ' %s' % tree_DECL_NAME.IDENTIFIER_POINTER()
             else:
                 pass # TODO: labels etc
-        elif long(val_tclass) == tcc_type:
+        elif int(val_tclass) == tcc_type:
             tree_TYPE_NAME = Tree(self.gdbval['type_common']['name'])
             if tree_TYPE_NAME.is_nonnull():
                 if tree_TYPE_NAME.TREE_CODE() == IDENTIFIER_NODE:
@@ -242,8 +242,8 @@ class CGraphNodePrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<cgraph_node* 0x%x' % long(self.gdbval)
-        if long(self.gdbval):
+        result = '<cgraph_node* 0x%x' % int(self.gdbval)
+        if int(self.gdbval):
             # symtab_node::name calls lang_hooks.decl_printable_name
             # default implementation (lhd_decl_printable_name) is:
             #    return IDENTIFIER_POINTER (DECL_NAME (decl));
@@ -261,12 +261,12 @@ class DWDieRefPrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        if long(self.gdbval) == 0:
+        if int(self.gdbval) == 0:
             return '<dw_die_ref 0x0>'
-        result = '<dw_die_ref 0x%x' % long(self.gdbval)
+        result = '<dw_die_ref 0x%x' % int(self.gdbval)
         result += ' %s' % self.gdbval['die_tag']
-        if long(self.gdbval['die_parent']) != 0:
-            result += ' <parent=0x%x %s>' % (long(self.gdbval['die_parent']),
+        if int(self.gdbval['die_parent']) != 0:
+            result += ' <parent=0x%x %s>' % (int(self.gdbval['die_parent']),
                                              self.gdbval['die_parent']['die_tag'])
                                              
         result += '>'
@@ -279,13 +279,13 @@ class GimplePrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        if long(self.gdbval) == 0:
+        if int(self.gdbval) == 0:
             return '<gimple 0x0>'
         val_gimple_code = self.gdbval['code']
         val_gimple_code_name = gdb.parse_and_eval('gimple_code_name')
-        val_code_name = val_gimple_code_name[long(val_gimple_code)]
+        val_code_name = val_gimple_code_name[int(val_gimple_code)]
         result = '<%s 0x%x' % (val_code_name.string(),
-                               long(self.gdbval))
+                               int(self.gdbval))
         result += '>'
         return result
 
@@ -306,9 +306,9 @@ class BasicBlockPrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<basic_block 0x%x' % long(self.gdbval)
-        if long(self.gdbval):
-            result += ' (%s)' % bb_index_to_str(long(self.gdbval['index']))
+        result = '<basic_block 0x%x' % int(self.gdbval)
+        if int(self.gdbval):
+            result += ' (%s)' % bb_index_to_str(int(self.gdbval['index']))
         result += '>'
         return result
 
@@ -317,10 +317,10 @@ class CfgEdgePrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<edge 0x%x' % long(self.gdbval)
-        if long(self.gdbval):
-            src = bb_index_to_str(long(self.gdbval['src']['index']))
-            dest = bb_index_to_str(long(self.gdbval['dest']['index']))
+        result = '<edge 0x%x' % int(self.gdbval)
+        if int(self.gdbval):
+            src = bb_index_to_str(int(self.gdbval['src']['index']))
+            dest = bb_index_to_str(int(self.gdbval['dest']['index']))
             result += ' (%s -> %s)' % (src, dest)
         result += '>'
         return result
@@ -336,7 +336,7 @@ class Rtx:
 
 def GET_RTX_LENGTH(code):
     val_rtx_length = gdb.parse_and_eval('rtx_length')
-    return long(val_rtx_length[code])
+    return int(val_rtx_length[code])
 
 def GET_RTX_NAME(code):
     val_rtx_name = gdb.parse_and_eval('rtx_name')
@@ -359,17 +359,17 @@ class RtxPrinter:
         """
         # We use print_inline_rtx to avoid a trailing newline
         gdb.execute('call print_inline_rtx (stderr, (const_rtx) %s, 0)'
-                    % long(self.gdbval))
+                    % int(self.gdbval))
         return ''
 
         # or by hand; based on gcc/print-rtl.c:print_rtx
         result = ('<rtx_def 0x%x'
-                  % (long(self.gdbval)))
+                  % (int(self.gdbval)))
         code = self.rtx.GET_CODE()
         result += ' (%s' % GET_RTX_NAME(code)
         format_ = GET_RTX_FORMAT(code)
         for i in range(GET_RTX_LENGTH(code)):
-            print format_[i]
+            print(format_[i])
         result += ')>'
         return result
 
@@ -380,11 +380,11 @@ class PassPrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<opt_pass* 0x%x' % long(self.gdbval)
-        if long(self.gdbval):
+        result = '<opt_pass* 0x%x' % int(self.gdbval)
+        if int(self.gdbval):
             result += (' "%s"(%i)'
                        % (self.gdbval['name'].string(),
-                          long(self.gdbval['static_pass_number'])))
+                          int(self.gdbval['static_pass_number'])))
         result += '>'
         return result
 
@@ -401,10 +401,10 @@ class VecPrinter:
     def to_string (self):
         # A trivial implementation; prettyprinting the contents is done
         # by gdb calling the "children" method below.
-        return '0x%x' % long(self.gdbval)
+        return '0x%x' % int(self.gdbval)
 
     def children (self):
-        if long(self.gdbval) == 0:
+        if int(self.gdbval) == 0:
             return
         m_vecpfx = self.gdbval['m_vecpfx']
         m_num = m_vecpfx['m_num']

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch] PR other/65366: Fix gdbhooks.py for GDB with Python3
  2015-03-09 21:43 [patch] PR other/65366: Fix gdbhooks.py for GDB with Python3 Jan Kratochvil
@ 2015-06-01 20:59 ` Jason Merrill
  2015-06-01 21:02   ` Jason Merrill
  2015-06-02  8:11   ` [commit] " Jan Kratochvil
  2015-06-03  8:25 ` Richard Biener
  1 sibling, 2 replies; 9+ messages in thread
From: Jason Merrill @ 2015-06-01 20:59 UTC (permalink / raw)
  To: gcc-patches; +Cc: Phil Muldoon

OK, thanks.

Jason

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch] PR other/65366: Fix gdbhooks.py for GDB with Python3
  2015-06-01 20:59 ` Jason Merrill
@ 2015-06-01 21:02   ` Jason Merrill
  2015-06-02  8:11   ` [commit] " Jan Kratochvil
  1 sibling, 0 replies; 9+ messages in thread
From: Jason Merrill @ 2015-06-01 21:02 UTC (permalink / raw)
  To: Jan Kratochvil, gcc-patches; +Cc: Phil Muldoon

OK, thanks.

Jason

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [commit] [patch] PR other/65366: Fix gdbhooks.py for GDB with Python3
  2015-06-01 20:59 ` Jason Merrill
  2015-06-01 21:02   ` Jason Merrill
@ 2015-06-02  8:11   ` Jan Kratochvil
  1 sibling, 0 replies; 9+ messages in thread
From: Jan Kratochvil @ 2015-06-02  8:11 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Phil Muldoon

On Mon, 01 Jun 2015 22:59:03 +0200, Jason Merrill wrote:
> OK, thanks.

Checked in: r224012


Jan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch] PR other/65366: Fix gdbhooks.py for GDB with Python3
  2015-03-09 21:43 [patch] PR other/65366: Fix gdbhooks.py for GDB with Python3 Jan Kratochvil
  2015-06-01 20:59 ` Jason Merrill
@ 2015-06-03  8:25 ` Richard Biener
  2015-06-03 13:28   ` [patch#2] " Jan Kratochvil
  1 sibling, 1 reply; 9+ messages in thread
From: Richard Biener @ 2015-06-03  8:25 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: GCC Patches, Phil Muldoon

On Mon, Mar 9, 2015 at 10:43 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> Hi,
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65366
>
> GDB Python support upstream has always been compatible with Python3.
> Fedora since F-22 builds GDB with Python3 by default (<=F-21 GDB used Python2).
>
> gdbhooks.py in GCC trunk is compatible with Python2 but not Python3.
>
> gdb-7.9-10.fc23.x86_64
> (gdb) source /home/jkratoch/redhat/gcchead/gcc/c/../gdbhooks.py
>   File "/home/jkratoch/redhat/gcchead/gcc/c/../gdbhooks.py", line 372
>     print format_[i]
>                 ^
> SyntaxError: Missing parentheses in call to 'print'
>
> Additionally after fixing the 'print' incompatibility one gets randomly:
>
> dependence_info = {clique = 257, Python Exception <class 'NameError'> name 'long' is not defined:
> base = 1}}}, type = },
>
> OK for check-in?
>
> The long()->int() change I have followed from:
>         https://stackoverflow.com/questions/14904814/nameerror-global-name-long-is-not-defined/14904834

I think this change causes

(gdb) p *$2
$3 = {type = undef_vec_info_type, live = false, Python Exception
<class 'gdb.error'> Cannot convert value to int.:
in_pattern_p = false, stmt = ,
Python Exception <class 'gdb.error'> Cannot convert value to int.:
Python Exception <class 'gdb.error'> Cannot convert value to int.:
  loop_vinfo = 0x2272e70, vectype = , vectorized_stmt = ,
Python Exception <class 'gdb.error'> Cannot convert value to int.:
Python Exception <class 'gdb.error'> Cannot convert value to int.:
Python Exception <class 'gdb.error'> Cannot convert value to int.:
  data_ref_info = 0x226bdd0, dr_base_address = , dr_init = , dr_offset = ,
Python Exception <class 'gdb.error'> Cannot convert value to int.:
Python Exception <class 'gdb.error'> Cannot convert value to int.:
Python Exception <class 'gdb.error'> Cannot convert value to int.:
Python Exception <class 'gdb.error'> Cannot convert value to int.:
...

and makes the pretty-printers compeltely unusable for me.

gdb 7.9, python 2.7.6

Richard.

>
> Thanks,
> Jan
>
> 2015-03-09  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         PR other/65366
>         * gdbhooks.py: Use int(...) instead of long(...).  Use print(...)
>         instead of print ... .
>
> Index: gcc/gdbhooks.py
> ===================================================================
> --- gcc/gdbhooks.py     (revision 221277)
> +++ gcc/gdbhooks.py     (working copy)
> @@ -158,7 +158,7 @@ class Tree:
>          self.gdbval = gdbval
>
>      def is_nonnull(self):
> -        return long(self.gdbval)
> +        return int(self.gdbval)
>
>      def TREE_CODE(self):
>          """
> @@ -197,7 +197,7 @@ class TreePrinter:
>          # like gcc/print-tree.c:print_node_brief
>          # #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
>          # tree_code_name[(int) TREE_CODE (node)])
> -        if long(self.gdbval) == 0:
> +        if int(self.gdbval) == 0:
>              return '<tree 0x0>'
>
>          val_TREE_CODE = self.node.TREE_CODE()
> @@ -209,17 +209,17 @@ class TreePrinter:
>          val_tclass = val_tree_code_type[val_TREE_CODE]
>
>          val_tree_code_name = gdb.parse_and_eval('tree_code_name')
> -        val_code_name = val_tree_code_name[long(val_TREE_CODE)]
> -        #print val_code_name.string()
> +        val_code_name = val_tree_code_name[int(val_TREE_CODE)]
> +        #print(val_code_name.string())
>
> -        result = '<%s 0x%x' % (val_code_name.string(), long(self.gdbval))
> -        if long(val_tclass) == tcc_declaration:
> +        result = '<%s 0x%x' % (val_code_name.string(), int(self.gdbval))
> +        if int(val_tclass) == tcc_declaration:
>              tree_DECL_NAME = self.node.DECL_NAME()
>              if tree_DECL_NAME.is_nonnull():
>                   result += ' %s' % tree_DECL_NAME.IDENTIFIER_POINTER()
>              else:
>                  pass # TODO: labels etc
> -        elif long(val_tclass) == tcc_type:
> +        elif int(val_tclass) == tcc_type:
>              tree_TYPE_NAME = Tree(self.gdbval['type_common']['name'])
>              if tree_TYPE_NAME.is_nonnull():
>                  if tree_TYPE_NAME.TREE_CODE() == IDENTIFIER_NODE:
> @@ -242,8 +242,8 @@ class CGraphNodePrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        result = '<cgraph_node* 0x%x' % long(self.gdbval)
> -        if long(self.gdbval):
> +        result = '<cgraph_node* 0x%x' % int(self.gdbval)
> +        if int(self.gdbval):
>              # symtab_node::name calls lang_hooks.decl_printable_name
>              # default implementation (lhd_decl_printable_name) is:
>              #    return IDENTIFIER_POINTER (DECL_NAME (decl));
> @@ -261,12 +261,12 @@ class DWDieRefPrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        if long(self.gdbval) == 0:
> +        if int(self.gdbval) == 0:
>              return '<dw_die_ref 0x0>'
> -        result = '<dw_die_ref 0x%x' % long(self.gdbval)
> +        result = '<dw_die_ref 0x%x' % int(self.gdbval)
>          result += ' %s' % self.gdbval['die_tag']
> -        if long(self.gdbval['die_parent']) != 0:
> -            result += ' <parent=0x%x %s>' % (long(self.gdbval['die_parent']),
> +        if int(self.gdbval['die_parent']) != 0:
> +            result += ' <parent=0x%x %s>' % (int(self.gdbval['die_parent']),
>                                               self.gdbval['die_parent']['die_tag'])
>
>          result += '>'
> @@ -279,13 +279,13 @@ class GimplePrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        if long(self.gdbval) == 0:
> +        if int(self.gdbval) == 0:
>              return '<gimple 0x0>'
>          val_gimple_code = self.gdbval['code']
>          val_gimple_code_name = gdb.parse_and_eval('gimple_code_name')
> -        val_code_name = val_gimple_code_name[long(val_gimple_code)]
> +        val_code_name = val_gimple_code_name[int(val_gimple_code)]
>          result = '<%s 0x%x' % (val_code_name.string(),
> -                               long(self.gdbval))
> +                               int(self.gdbval))
>          result += '>'
>          return result
>
> @@ -306,9 +306,9 @@ class BasicBlockPrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        result = '<basic_block 0x%x' % long(self.gdbval)
> -        if long(self.gdbval):
> -            result += ' (%s)' % bb_index_to_str(long(self.gdbval['index']))
> +        result = '<basic_block 0x%x' % int(self.gdbval)
> +        if int(self.gdbval):
> +            result += ' (%s)' % bb_index_to_str(int(self.gdbval['index']))
>          result += '>'
>          return result
>
> @@ -317,10 +317,10 @@ class CfgEdgePrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        result = '<edge 0x%x' % long(self.gdbval)
> -        if long(self.gdbval):
> -            src = bb_index_to_str(long(self.gdbval['src']['index']))
> -            dest = bb_index_to_str(long(self.gdbval['dest']['index']))
> +        result = '<edge 0x%x' % int(self.gdbval)
> +        if int(self.gdbval):
> +            src = bb_index_to_str(int(self.gdbval['src']['index']))
> +            dest = bb_index_to_str(int(self.gdbval['dest']['index']))
>              result += ' (%s -> %s)' % (src, dest)
>          result += '>'
>          return result
> @@ -336,7 +336,7 @@ class Rtx:
>
>  def GET_RTX_LENGTH(code):
>      val_rtx_length = gdb.parse_and_eval('rtx_length')
> -    return long(val_rtx_length[code])
> +    return int(val_rtx_length[code])
>
>  def GET_RTX_NAME(code):
>      val_rtx_name = gdb.parse_and_eval('rtx_name')
> @@ -359,17 +359,17 @@ class RtxPrinter:
>          """
>          # We use print_inline_rtx to avoid a trailing newline
>          gdb.execute('call print_inline_rtx (stderr, (const_rtx) %s, 0)'
> -                    % long(self.gdbval))
> +                    % int(self.gdbval))
>          return ''
>
>          # or by hand; based on gcc/print-rtl.c:print_rtx
>          result = ('<rtx_def 0x%x'
> -                  % (long(self.gdbval)))
> +                  % (int(self.gdbval)))
>          code = self.rtx.GET_CODE()
>          result += ' (%s' % GET_RTX_NAME(code)
>          format_ = GET_RTX_FORMAT(code)
>          for i in range(GET_RTX_LENGTH(code)):
> -            print format_[i]
> +            print(format_[i])
>          result += ')>'
>          return result
>
> @@ -380,11 +380,11 @@ class PassPrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        result = '<opt_pass* 0x%x' % long(self.gdbval)
> -        if long(self.gdbval):
> +        result = '<opt_pass* 0x%x' % int(self.gdbval)
> +        if int(self.gdbval):
>              result += (' "%s"(%i)'
>                         % (self.gdbval['name'].string(),
> -                          long(self.gdbval['static_pass_number'])))
> +                          int(self.gdbval['static_pass_number'])))
>          result += '>'
>          return result
>
> @@ -401,10 +401,10 @@ class VecPrinter:
>      def to_string (self):
>          # A trivial implementation; prettyprinting the contents is done
>          # by gdb calling the "children" method below.
> -        return '0x%x' % long(self.gdbval)
> +        return '0x%x' % int(self.gdbval)
>
>      def children (self):
> -        if long(self.gdbval) == 0:
> +        if int(self.gdbval) == 0:
>              return
>          m_vecpfx = self.gdbval['m_vecpfx']
>          m_num = m_vecpfx['m_num']
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [patch#2] PR other/65366: Fix gdbhooks.py for GDB with Python3
  2015-06-03  8:25 ` Richard Biener
@ 2015-06-03 13:28   ` Jan Kratochvil
  2015-06-08  7:49     ` Richard Biener
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Kratochvil @ 2015-06-03 13:28 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Phil Muldoon, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 618 bytes --]

On Wed, 03 Jun 2015 10:25:20 +0200, Richard Biener wrote:
> gdb 7.9, python 2.7.6

attaching a fix; I do not know much Python so check it, please.

OK for check-in?

I have found it reproducible by :
	gdb -ex 'source /home/jkratoch/redhat/gcchead/gcc/gdbhooks.py' -ex 'b *0xec25b0' -ex r -ex 'set python print-stack full' -ex 'p *(stmt_vec_info)$r12' --args /home/jkratoch/redhat/gcchead-build/gcc/cc1plus ~/t/sigtest.C -o /dev/null -Wall -g -O3

0xec25b0=
Breakpoint 1, free_stmt_vec_info (stmt=<gimple_debug 0x7ffff1635b80>) at /home/jkratoch/redhat/gcchead/gcc/tree-vect-stmts.c:7754
7754	  free (stmt_info);


Jan

[-- Attachment #2: 1 --]
[-- Type: text/plain, Size: 7557 bytes --]

gcc/
2015-06-03  Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR other/65366
	* gdbhooks.py (intptr): New function.  Replace int(...) by intptr(...).

diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 20842bb..fe83376 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -149,6 +149,12 @@ tree_code_class_dict = gdb.types.make_enum_dict(gdb.lookup_type('enum tree_code_
 tcc_type = tree_code_class_dict['tcc_type']
 tcc_declaration = tree_code_class_dict['tcc_declaration']
 
+# Python3 has int() with arbitrary precision (bignum).  Python2 int() is 32-bit
+# on 32-bit hosts but remote targets may have 64-bit pointers there; Python2
+# long() is always 64-bit but Python3 no longer has anything named long.
+def intptr(gdbval):
+    return long(gdbval) if sys.version_info.major == 2 else int(gdbval)
+
 class Tree:
     """
     Wrapper around a gdb.Value for a tree, with various methods
@@ -158,7 +164,7 @@ class Tree:
         self.gdbval = gdbval
 
     def is_nonnull(self):
-        return int(self.gdbval)
+        return intptr(self.gdbval)
 
     def TREE_CODE(self):
         """
@@ -197,7 +203,7 @@ class TreePrinter:
         # like gcc/print-tree.c:print_node_brief
         # #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
         # tree_code_name[(int) TREE_CODE (node)])
-        if int(self.gdbval) == 0:
+        if intptr(self.gdbval) == 0:
             return '<tree 0x0>'
 
         val_TREE_CODE = self.node.TREE_CODE()
@@ -209,17 +215,17 @@ class TreePrinter:
         val_tclass = val_tree_code_type[val_TREE_CODE]
 
         val_tree_code_name = gdb.parse_and_eval('tree_code_name')
-        val_code_name = val_tree_code_name[int(val_TREE_CODE)]
+        val_code_name = val_tree_code_name[intptr(val_TREE_CODE)]
         #print(val_code_name.string())
 
-        result = '<%s 0x%x' % (val_code_name.string(), int(self.gdbval))
-        if int(val_tclass) == tcc_declaration:
+        result = '<%s 0x%x' % (val_code_name.string(), intptr(self.gdbval))
+        if intptr(val_tclass) == tcc_declaration:
             tree_DECL_NAME = self.node.DECL_NAME()
             if tree_DECL_NAME.is_nonnull():
                  result += ' %s' % tree_DECL_NAME.IDENTIFIER_POINTER()
             else:
                 pass # TODO: labels etc
-        elif int(val_tclass) == tcc_type:
+        elif intptr(val_tclass) == tcc_type:
             tree_TYPE_NAME = Tree(self.gdbval['type_common']['name'])
             if tree_TYPE_NAME.is_nonnull():
                 if tree_TYPE_NAME.TREE_CODE() == IDENTIFIER_NODE:
@@ -242,8 +248,8 @@ class CGraphNodePrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<cgraph_node* 0x%x' % int(self.gdbval)
-        if int(self.gdbval):
+        result = '<cgraph_node* 0x%x' % intptr(self.gdbval)
+        if intptr(self.gdbval):
             # symtab_node::name calls lang_hooks.decl_printable_name
             # default implementation (lhd_decl_printable_name) is:
             #    return IDENTIFIER_POINTER (DECL_NAME (decl));
@@ -261,12 +267,12 @@ class DWDieRefPrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        if int(self.gdbval) == 0:
+        if intptr(self.gdbval) == 0:
             return '<dw_die_ref 0x0>'
-        result = '<dw_die_ref 0x%x' % int(self.gdbval)
+        result = '<dw_die_ref 0x%x' % intptr(self.gdbval)
         result += ' %s' % self.gdbval['die_tag']
-        if int(self.gdbval['die_parent']) != 0:
-            result += ' <parent=0x%x %s>' % (int(self.gdbval['die_parent']),
+        if intptr(self.gdbval['die_parent']) != 0:
+            result += ' <parent=0x%x %s>' % (intptr(self.gdbval['die_parent']),
                                              self.gdbval['die_parent']['die_tag'])
                                              
         result += '>'
@@ -279,13 +285,13 @@ class GimplePrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        if int(self.gdbval) == 0:
+        if intptr(self.gdbval) == 0:
             return '<gimple 0x0>'
         val_gimple_code = self.gdbval['code']
         val_gimple_code_name = gdb.parse_and_eval('gimple_code_name')
-        val_code_name = val_gimple_code_name[int(val_gimple_code)]
+        val_code_name = val_gimple_code_name[intptr(val_gimple_code)]
         result = '<%s 0x%x' % (val_code_name.string(),
-                               int(self.gdbval))
+                               intptr(self.gdbval))
         result += '>'
         return result
 
@@ -306,9 +312,9 @@ class BasicBlockPrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<basic_block 0x%x' % int(self.gdbval)
-        if int(self.gdbval):
-            result += ' (%s)' % bb_index_to_str(int(self.gdbval['index']))
+        result = '<basic_block 0x%x' % intptr(self.gdbval)
+        if intptr(self.gdbval):
+            result += ' (%s)' % bb_index_to_str(intptr(self.gdbval['index']))
         result += '>'
         return result
 
@@ -317,10 +323,10 @@ class CfgEdgePrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<edge 0x%x' % int(self.gdbval)
-        if int(self.gdbval):
-            src = bb_index_to_str(int(self.gdbval['src']['index']))
-            dest = bb_index_to_str(int(self.gdbval['dest']['index']))
+        result = '<edge 0x%x' % intptr(self.gdbval)
+        if intptr(self.gdbval):
+            src = bb_index_to_str(intptr(self.gdbval['src']['index']))
+            dest = bb_index_to_str(intptr(self.gdbval['dest']['index']))
             result += ' (%s -> %s)' % (src, dest)
         result += '>'
         return result
@@ -336,7 +342,7 @@ class Rtx:
 
 def GET_RTX_LENGTH(code):
     val_rtx_length = gdb.parse_and_eval('rtx_length')
-    return int(val_rtx_length[code])
+    return intptr(val_rtx_length[code])
 
 def GET_RTX_NAME(code):
     val_rtx_name = gdb.parse_and_eval('rtx_name')
@@ -359,12 +365,12 @@ class RtxPrinter:
         """
         # We use print_inline_rtx to avoid a trailing newline
         gdb.execute('call print_inline_rtx (stderr, (const_rtx) %s, 0)'
-                    % int(self.gdbval))
+                    % intptr(self.gdbval))
         return ''
 
         # or by hand; based on gcc/print-rtl.c:print_rtx
         result = ('<rtx_def 0x%x'
-                  % (int(self.gdbval)))
+                  % (intptr(self.gdbval)))
         code = self.rtx.GET_CODE()
         result += ' (%s' % GET_RTX_NAME(code)
         format_ = GET_RTX_FORMAT(code)
@@ -380,11 +386,11 @@ class PassPrinter:
         self.gdbval = gdbval
 
     def to_string (self):
-        result = '<opt_pass* 0x%x' % int(self.gdbval)
-        if int(self.gdbval):
+        result = '<opt_pass* 0x%x' % intptr(self.gdbval)
+        if intptr(self.gdbval):
             result += (' "%s"(%i)'
                        % (self.gdbval['name'].string(),
-                          int(self.gdbval['static_pass_number'])))
+                          intptr(self.gdbval['static_pass_number'])))
         result += '>'
         return result
 
@@ -401,10 +407,10 @@ class VecPrinter:
     def to_string (self):
         # A trivial implementation; prettyprinting the contents is done
         # by gdb calling the "children" method below.
-        return '0x%x' % int(self.gdbval)
+        return '0x%x' % intptr(self.gdbval)
 
     def children (self):
-        if int(self.gdbval) == 0:
+        if intptr(self.gdbval) == 0:
             return
         m_vecpfx = self.gdbval['m_vecpfx']
         m_num = m_vecpfx['m_num']

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [patch#2] PR other/65366: Fix gdbhooks.py for GDB with Python3
  2015-06-03 13:28   ` [patch#2] " Jan Kratochvil
@ 2015-06-08  7:49     ` Richard Biener
  2015-06-08 13:38       ` [commit#2] " Jan Kratochvil
  0 siblings, 1 reply; 9+ messages in thread
From: Richard Biener @ 2015-06-08  7:49 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: GCC Patches, Phil Muldoon, Jason Merrill

On Wed, Jun 3, 2015 at 3:26 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> On Wed, 03 Jun 2015 10:25:20 +0200, Richard Biener wrote:
>> gdb 7.9, python 2.7.6
>
> attaching a fix; I do not know much Python so check it, please.
>
> OK for check-in?

Python Exception <type 'exceptions.NameError'> global name 'sys' is not defined:
Python Exception <type 'exceptions.NameError'> global name 'sys' is not defined:
Python Exception <type 'exceptions.NameError'> global name 'sys' is not defined:
Breakpoint 5, fold_binary_loc (loc=17953, code=LT_EXPR, type=, op0=, op1=)
    at /space/rguenther/tramp3d/trunk/gcc/fold-const.c:9862

adding a

import sys

makes it work fine though.

Thus, ok with also adding a imoprt sys.

Thanks,
Richard.

> I have found it reproducible by :
>         gdb -ex 'source /home/jkratoch/redhat/gcchead/gcc/gdbhooks.py' -ex 'b *0xec25b0' -ex r -ex 'set python print-stack full' -ex 'p *(stmt_vec_info)$r12' --args /home/jkratoch/redhat/gcchead-build/gcc/cc1plus ~/t/sigtest.C -o /dev/null -Wall -g -O3
>
> 0xec25b0=
> Breakpoint 1, free_stmt_vec_info (stmt=<gimple_debug 0x7ffff1635b80>) at /home/jkratoch/redhat/gcchead/gcc/tree-vect-stmts.c:7754
> 7754      free (stmt_info);
>
>
> Jan
>
> gcc/
> 2015-06-03  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
>         PR other/65366
>         * gdbhooks.py (intptr): New function.  Replace int(...) by intptr(...).
>
> diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
> index 20842bb..fe83376 100644
> --- a/gcc/gdbhooks.py
> +++ b/gcc/gdbhooks.py
> @@ -149,6 +149,12 @@ tree_code_class_dict = gdb.types.make_enum_dict(gdb.lookup_type('enum tree_code_
>  tcc_type = tree_code_class_dict['tcc_type']
>  tcc_declaration = tree_code_class_dict['tcc_declaration']
>
> +# Python3 has int() with arbitrary precision (bignum).  Python2 int() is 32-bit
> +# on 32-bit hosts but remote targets may have 64-bit pointers there; Python2
> +# long() is always 64-bit but Python3 no longer has anything named long.
> +def intptr(gdbval):
> +    return long(gdbval) if sys.version_info.major == 2 else int(gdbval)
> +
>  class Tree:
>      """
>      Wrapper around a gdb.Value for a tree, with various methods
> @@ -158,7 +164,7 @@ class Tree:
>          self.gdbval = gdbval
>
>      def is_nonnull(self):
> -        return int(self.gdbval)
> +        return intptr(self.gdbval)
>
>      def TREE_CODE(self):
>          """
> @@ -197,7 +203,7 @@ class TreePrinter:
>          # like gcc/print-tree.c:print_node_brief
>          # #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
>          # tree_code_name[(int) TREE_CODE (node)])
> -        if int(self.gdbval) == 0:
> +        if intptr(self.gdbval) == 0:
>              return '<tree 0x0>'
>
>          val_TREE_CODE = self.node.TREE_CODE()
> @@ -209,17 +215,17 @@ class TreePrinter:
>          val_tclass = val_tree_code_type[val_TREE_CODE]
>
>          val_tree_code_name = gdb.parse_and_eval('tree_code_name')
> -        val_code_name = val_tree_code_name[int(val_TREE_CODE)]
> +        val_code_name = val_tree_code_name[intptr(val_TREE_CODE)]
>          #print(val_code_name.string())
>
> -        result = '<%s 0x%x' % (val_code_name.string(), int(self.gdbval))
> -        if int(val_tclass) == tcc_declaration:
> +        result = '<%s 0x%x' % (val_code_name.string(), intptr(self.gdbval))
> +        if intptr(val_tclass) == tcc_declaration:
>              tree_DECL_NAME = self.node.DECL_NAME()
>              if tree_DECL_NAME.is_nonnull():
>                   result += ' %s' % tree_DECL_NAME.IDENTIFIER_POINTER()
>              else:
>                  pass # TODO: labels etc
> -        elif int(val_tclass) == tcc_type:
> +        elif intptr(val_tclass) == tcc_type:
>              tree_TYPE_NAME = Tree(self.gdbval['type_common']['name'])
>              if tree_TYPE_NAME.is_nonnull():
>                  if tree_TYPE_NAME.TREE_CODE() == IDENTIFIER_NODE:
> @@ -242,8 +248,8 @@ class CGraphNodePrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        result = '<cgraph_node* 0x%x' % int(self.gdbval)
> -        if int(self.gdbval):
> +        result = '<cgraph_node* 0x%x' % intptr(self.gdbval)
> +        if intptr(self.gdbval):
>              # symtab_node::name calls lang_hooks.decl_printable_name
>              # default implementation (lhd_decl_printable_name) is:
>              #    return IDENTIFIER_POINTER (DECL_NAME (decl));
> @@ -261,12 +267,12 @@ class DWDieRefPrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        if int(self.gdbval) == 0:
> +        if intptr(self.gdbval) == 0:
>              return '<dw_die_ref 0x0>'
> -        result = '<dw_die_ref 0x%x' % int(self.gdbval)
> +        result = '<dw_die_ref 0x%x' % intptr(self.gdbval)
>          result += ' %s' % self.gdbval['die_tag']
> -        if int(self.gdbval['die_parent']) != 0:
> -            result += ' <parent=0x%x %s>' % (int(self.gdbval['die_parent']),
> +        if intptr(self.gdbval['die_parent']) != 0:
> +            result += ' <parent=0x%x %s>' % (intptr(self.gdbval['die_parent']),
>                                               self.gdbval['die_parent']['die_tag'])
>
>          result += '>'
> @@ -279,13 +285,13 @@ class GimplePrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        if int(self.gdbval) == 0:
> +        if intptr(self.gdbval) == 0:
>              return '<gimple 0x0>'
>          val_gimple_code = self.gdbval['code']
>          val_gimple_code_name = gdb.parse_and_eval('gimple_code_name')
> -        val_code_name = val_gimple_code_name[int(val_gimple_code)]
> +        val_code_name = val_gimple_code_name[intptr(val_gimple_code)]
>          result = '<%s 0x%x' % (val_code_name.string(),
> -                               int(self.gdbval))
> +                               intptr(self.gdbval))
>          result += '>'
>          return result
>
> @@ -306,9 +312,9 @@ class BasicBlockPrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        result = '<basic_block 0x%x' % int(self.gdbval)
> -        if int(self.gdbval):
> -            result += ' (%s)' % bb_index_to_str(int(self.gdbval['index']))
> +        result = '<basic_block 0x%x' % intptr(self.gdbval)
> +        if intptr(self.gdbval):
> +            result += ' (%s)' % bb_index_to_str(intptr(self.gdbval['index']))
>          result += '>'
>          return result
>
> @@ -317,10 +323,10 @@ class CfgEdgePrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        result = '<edge 0x%x' % int(self.gdbval)
> -        if int(self.gdbval):
> -            src = bb_index_to_str(int(self.gdbval['src']['index']))
> -            dest = bb_index_to_str(int(self.gdbval['dest']['index']))
> +        result = '<edge 0x%x' % intptr(self.gdbval)
> +        if intptr(self.gdbval):
> +            src = bb_index_to_str(intptr(self.gdbval['src']['index']))
> +            dest = bb_index_to_str(intptr(self.gdbval['dest']['index']))
>              result += ' (%s -> %s)' % (src, dest)
>          result += '>'
>          return result
> @@ -336,7 +342,7 @@ class Rtx:
>
>  def GET_RTX_LENGTH(code):
>      val_rtx_length = gdb.parse_and_eval('rtx_length')
> -    return int(val_rtx_length[code])
> +    return intptr(val_rtx_length[code])
>
>  def GET_RTX_NAME(code):
>      val_rtx_name = gdb.parse_and_eval('rtx_name')
> @@ -359,12 +365,12 @@ class RtxPrinter:
>          """
>          # We use print_inline_rtx to avoid a trailing newline
>          gdb.execute('call print_inline_rtx (stderr, (const_rtx) %s, 0)'
> -                    % int(self.gdbval))
> +                    % intptr(self.gdbval))
>          return ''
>
>          # or by hand; based on gcc/print-rtl.c:print_rtx
>          result = ('<rtx_def 0x%x'
> -                  % (int(self.gdbval)))
> +                  % (intptr(self.gdbval)))
>          code = self.rtx.GET_CODE()
>          result += ' (%s' % GET_RTX_NAME(code)
>          format_ = GET_RTX_FORMAT(code)
> @@ -380,11 +386,11 @@ class PassPrinter:
>          self.gdbval = gdbval
>
>      def to_string (self):
> -        result = '<opt_pass* 0x%x' % int(self.gdbval)
> -        if int(self.gdbval):
> +        result = '<opt_pass* 0x%x' % intptr(self.gdbval)
> +        if intptr(self.gdbval):
>              result += (' "%s"(%i)'
>                         % (self.gdbval['name'].string(),
> -                          int(self.gdbval['static_pass_number'])))
> +                          intptr(self.gdbval['static_pass_number'])))
>          result += '>'
>          return result
>
> @@ -401,10 +407,10 @@ class VecPrinter:
>      def to_string (self):
>          # A trivial implementation; prettyprinting the contents is done
>          # by gdb calling the "children" method below.
> -        return '0x%x' % int(self.gdbval)
> +        return '0x%x' % intptr(self.gdbval)
>
>      def children (self):
> -        if int(self.gdbval) == 0:
> +        if intptr(self.gdbval) == 0:
>              return
>          m_vecpfx = self.gdbval['m_vecpfx']
>          m_num = m_vecpfx['m_num']
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [commit#2] [patch#2] PR other/65366: Fix gdbhooks.py for GDB with Python3
  2015-06-08  7:49     ` Richard Biener
@ 2015-06-08 13:38       ` Jan Kratochvil
  2015-06-08 13:48         ` Richard Biener
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Kratochvil @ 2015-06-08 13:38 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Phil Muldoon, Jason Merrill

On Mon, 08 Jun 2015 09:46:59 +0200, Richard Biener wrote:
> adding a
> 
> import sys
> 
> makes it work fine though.

I do not see the sys error with either FSF GDB HEAD or Fedora 22 GDB.
I agree it probably should be there.


> Thus, ok with also adding a imoprt sys.

Done and checked in: r224223


Jan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [commit#2] [patch#2] PR other/65366: Fix gdbhooks.py for GDB with Python3
  2015-06-08 13:38       ` [commit#2] " Jan Kratochvil
@ 2015-06-08 13:48         ` Richard Biener
  0 siblings, 0 replies; 9+ messages in thread
From: Richard Biener @ 2015-06-08 13:48 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: GCC Patches, Phil Muldoon, Jason Merrill

On Mon, Jun 8, 2015 at 3:37 PM, Jan Kratochvil
<jan.kratochvil@redhat.com> wrote:
> On Mon, 08 Jun 2015 09:46:59 +0200, Richard Biener wrote:
>> adding a
>>
>> import sys
>>
>> makes it work fine though.
>
> I do not see the sys error with either FSF GDB HEAD or Fedora 22 GDB.
> I agree it probably should be there.

Yeah, I suspect you have other auto-loads that eventually import sys
(I suppose the different python modules are not isolated)

>
>> Thus, ok with also adding a imoprt sys.
>
> Done and checked in: r224223

Thanks.

>
> Jan

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-06-08 13:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09 21:43 [patch] PR other/65366: Fix gdbhooks.py for GDB with Python3 Jan Kratochvil
2015-06-01 20:59 ` Jason Merrill
2015-06-01 21:02   ` Jason Merrill
2015-06-02  8:11   ` [commit] " Jan Kratochvil
2015-06-03  8:25 ` Richard Biener
2015-06-03 13:28   ` [patch#2] " Jan Kratochvil
2015-06-08  7:49     ` Richard Biener
2015-06-08 13:38       ` [commit#2] " Jan Kratochvil
2015-06-08 13:48         ` Richard Biener

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