Re: [commit#2] [patch#2] PR other/65366: Fix gdbhooks.py for GDB with Python3

2015-06-08 Thread Richard Biener
On Mon, Jun 8, 2015 at 3:37 PM, Jan Kratochvil
 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


[commit#2] [patch#2] PR other/65366: Fix gdbhooks.py for GDB with Python3

2015-06-08 Thread Jan Kratochvil
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


Re: [patch#2] PR other/65366: Fix gdbhooks.py for GDB with Python3

2015-06-08 Thread Richard Biener
On Wed, Jun 3, 2015 at 3:26 PM, Jan Kratochvil
 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  global name 'sys' is not defined:
Python Exception  global name 'sys' is not defined:
Python Exception  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=) at 
> /home/jkratoch/redhat/gcchead/gcc/tree-vect-stmts.c:7754
> 7754  free (stmt_info);
>
>
> Jan
>
> gcc/
> 2015-06-03  Jan Kratochvil  
>
> 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 ''
>
>  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 = ' -if int(self.gdbval):
> +result = ' +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 ''
> -result = ' +result = '  result += ' %s' % self.gdbval['die_tag']
> -if int(self.gdbval['die_parent']) != 0:
> -result += ' ' % (int(self.gdbval['die_parent']),
> +if intptr(self.gdbval['die_parent']) != 0:
> +result += ' ' % 
> (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(sel

[patch#2] PR other/65366: Fix gdbhooks.py for GDB with Python3

2015-06-03 Thread Jan Kratochvil
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=) at 
/home/jkratoch/redhat/gcchead/gcc/tree-vect-stmts.c:7754
7754  free (stmt_info);


Jan
gcc/
2015-06-03  Jan Kratochvil  

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 ''
 
 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 = ''
-result = ''
 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 = '