[PATCH 4.8] libstdc++ pretty-printers: Backport Python 3 support from mainline

2014-08-12 Thread Samuel Bronson

This was a bit trickier than the backport to 4.9: but the tests pass,
except this one:

UNSUPPORTED: libstdc++-prettyprinters/shared_ptr.cc

This is a bit puzzling, but seems unrelated to my change.


2014-08-13  Samuel Bronson  

Backport r212453 from trunk
2014-07-11  Samuel Bronson  
Matthias Klose  

PR libstdc++/58962
* python/libstdcxx/v6/printers.py: Port to Python 2+3
(imap): New compat function.
(izip): Likewise.
(Iterator): New mixin to allow writing iterators in Python 3 style
regardless of which version we're running on.
[Python3] (long) New compat alias for "int".
* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)

Backport r210625 from trunk
2014-05-19  Jonathan Wakely  

* python/libstdcxx/v6/printers.py: Use Python3 raise syntax.
---
 libstdc++-v3/ChangeLog   |  20 +
 libstdc++-v3/python/libstdcxx/v6/printers.py | 108 +++
 libstdc++-v3/testsuite/lib/gdb-test.exp  |   4 +-
 3 files changed, 98 insertions(+), 34 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 9c8408d..4134f13 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,23 @@
+2014-08-13  Samuel Bronson  
+
+	Backport r212453 from trunk
+	2014-07-11  Samuel Bronson  
+		Matthias Klose  
+
+	PR libstdc++/58962
+	* python/libstdcxx/v6/printers.py: Port to Python 2+3
+	(imap): New compat function.
+	(izip): Likewise.
+	(Iterator): New mixin to allow writing iterators in Python 3 style
+	regardless of which version we're running on.
+	[Python3] (long) New compat alias for "int".
+	* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)
+
+	Backport r210625 from trunk
+	2014-05-19  Jonathan Wakely  
+
+	* python/libstdcxx/v6/printers.py: Use Python3 raise syntax.
+
 2014-08-04  Jonathan Wakely  
 
 	Backported from mainline
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index e6f2007..1a1f02d 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1,4 +1,4 @@
-# Pretty-printers for libstc++.
+# Pretty-printers for libstdc++.
 
 # Copyright (C) 2008-2013 Free Software Foundation, Inc.
 
@@ -18,6 +18,50 @@
 import gdb
 import itertools
 import re
+import sys
+
+### Python 2 + Python 3 compatibility code
+
+# Resources about compatibility:
+#
+#  * <http://pythonhosted.org/six/>: Documentation of the "six" module
+
+# FIXME: The handling of e.g. std::basic_string (at least on char)
+# probably needs updating to work with Python 3's new string rules.
+#
+# In particular, Python 3 has a separate type (called byte) for
+# bytestrings, and a special b"" syntax for the byte literals; the old
+# str() type has been redefined to always store Unicode text.
+#
+# We probably can't do much about this until this GDB PR is addressed:
+# <https://sourceware.org/bugzilla/show_bug.cgi?id=17138>
+
+if sys.version_info[0] > 2:
+### Python 3 stuff
+Iterator = object
+# Python 3 folds these into the normal functions.
+imap = map
+izip = zip
+# Also, int subsumes long
+long = int
+else:
+### Python 2 stuff
+class Iterator:
+"""Compatibility mixin for iterators
+
+Instead of writing next() methods for iterators, write
+__next__() methods and use this mixin to make them work in
+Python 2 as well as Python 3.
+
+Idea stolen from the "six" documentation:
+<http://pythonhosted.org/six/#six.Iterator>
+"""
+
+def next(self):
+return self.__next__()
+
+# In Python 2, we still need these from itertools
+from itertools import imap, izip
 
 # Try to use the new-style pretty-printing if available.
 _use_gdb_pp = True
@@ -51,7 +95,7 @@ def find_type(orig, name):
 # anything fancier here.
 field = typ.fields()[0]
 if not field.is_base_class:
-raise ValueError, "Cannot find type %s::%s" % (str(orig), name)
+raise ValueError("Cannot find type %s::%s" % (str(orig), name))
 typ = field.type
 
 class SharedPointerPrinter:
@@ -87,7 +131,7 @@ class UniquePointerPrinter:
 class StdListPrinter:
 "Print a std::list"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__(self, nodetype, head):
 self.nodetype = nodetype
 self.base = head['_M_next']
@@ -97,7 +141,7 @@ class StdListPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 if self.base == self.head:
 raise StopIteration
 elt = self.base.cast(self.nodetype).dereference(

Re: [PATCH 4.8] libstdc++ pretty-printers: Backport Python 3 support from mainline

2014-08-26 Thread Samuel Bronson

Ping!

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!


Re: [PATCH 4.8] libstdc++ pretty-printers: Backport Python 3 support from mainline

2014-08-27 Thread Samuel Bronson
Ping?

(My apologies if this is redundant: I tried to send one yesterday and
gnus has your message flagged as Answered, but I don't see that ping on
gmane ...)

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!


Re: [PATCH 4.8] libstdc++ pretty-printers: Backport Python 3 support from mainline

2014-08-28 Thread Samuel Bronson
Thanks!

On 8/28/14, Jonathan Wakely  wrote:
> Applied
>


[RFC] Add a .gitattributes file for use with git-merge-changelog

2014-06-19 Thread Samuel Bronson
[Am I really supposed to CC this to gcc@ like binutils/MAINTAINERS
says I should?]

Individual users will still have to:

 1. Install git-merge-changelog

 2. Set up the merge driver in their git config

See gnulib's lib/git-merge-changelog.c [1] for details.

For example, I:

 1. Patched Debian's gnulib package to build git-merge-changelog, and
sent the patch to the Debian maintainer, who then proceeded to not
only accept my patch but even write a *manpage* for
git-merge-changelog! (Let's hear it for Ian Beckwith.)

So now, I can install it simply by running "apt-get install
git-merge-changelog".  (Except, of course, that I already have it
installed from when I was testing my patch.)

 2. Added this to my ~/.gitconfig:

--8<---cut here---start->8---
[merge "merge-changelog"]
name = GNU-style ChangeLog merge driver
driver = git-merge-changelog %O %A %B
--8<---cut here---end--->8---

(You could just put it in the .git/config file for a given
repository, but I can't really see much point in that.)

With this patch applied and the above two tasks done by whatever means
you deem best, you can say goodbye to merge conflicts in ChangeLog
files.

*IF* people will stop renaming the danged things, anyway.

[1]: 
http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/git-merge-changelog.c

[Note: The docs for git-merge-changelog (the comments at the top) say
you need a .gitattributes in every directory.  The docs are wrong.
Ignore the docs.

You really only need one at the top level, since .gitattributes uses
the same pattern matching rules as .gitignore, which match files in
any subdirectory unless you prefix the pattern with a "/".]

[Note 2: I already have copyright assignment papers on file for GDB.]
---
 .gitattributes | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 .gitattributes

diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000..75abe79
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,3 @@
+# See gnulib's lib/git-merge-changelog.c (or git-merge-changelog(1))
+# to activate this
+ChangeLog   merge=merge-changelog
-- 
2.0.0



Re: [RFC] Add a .gitattributes file for use with git-merge-changelog

2014-06-28 Thread Samuel Bronson
Ouch; it looks like my last attempt to reply to this missed gdb-patches@
due to a gmane accident?

Samuel Bronson  writes:

> Tom Tromey  writes:
>>>>>>> "Samuel" == Samuel Bronson  writes:
>>
>> Samuel> [Am I really supposed to CC this to gcc@ like binutils/MAINTAINERS
>> Samuel> says I should?]
>>
>> I think just for files that are intended to be put in both trees and
>> shared.
>
> Well, they're certainly welcome to add such a file to their repository.
>
>> Samuel> Individual users will still have to:
>> Samuel>  1. Install git-merge-changelog
>> Samuel>  2. Set up the merge driver in their git config
>>
>> What happens if they do not?
>
> Not much; git just falls back to the default ("text") merge driver in
> that case.  (This appears to have been so obvious that nobody actually
> bothered to document it?)
>
> I find myself wondering: how much commentary should go into the
> .gitattributes file, and do such files get ChangeLog entries?
>
> --
> Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
>
>

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!


Re: [RFC] Add a .gitattributes file for use with git-merge-changelog

2014-07-07 Thread Samuel Bronson
Ping?  If nobody has anything else to say, I'm going to assume that such
a change is unobjectionable, and should not be listed in the ChangeLog.

Samuel Bronson  writes:

> Ouch; it looks like my last attempt to reply to this missed gdb-patches@
> due to a gmane accident?
>
> Samuel Bronson  writes:
>
>> Tom Tromey  writes:
>>>>>>>> "Samuel" == Samuel Bronson  writes:
>>>
>>> Samuel> [Am I really supposed to CC this to gcc@ like binutils/MAINTAINERS
>>> Samuel> says I should?]
>>>
>>> I think just for files that are intended to be put in both trees and
>>> shared.
>>
>> Well, they're certainly welcome to add such a file to their repository.
>>
>>> Samuel> Individual users will still have to:
>>> Samuel>  1. Install git-merge-changelog
>>> Samuel>  2. Set up the merge driver in their git config
>>>
>>> What happens if they do not?
>>
>> Not much; git just falls back to the default ("text") merge driver in
>> that case.  (This appears to have been so obvious that nobody actually
>> bothered to document it?)
>>
>> I find myself wondering: how much commentary should go into the
>> .gitattributes file, and do such files get ChangeLog entries?

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!


[PATCH v2 0/3] Port libstdc++ pretty printers to Python 3

2014-07-10 Thread Samuel Bronson
I've ported the libstdc++ pretty printers to work with Python 3 as
well as Python 2, and made a couple of other changes that I think are
improvements along the way.  The important change here is the final
patch; the others just made things easier at some point along the way.

I started with a patch by Mathias Klose; when he sent it out, he said
it should be backported to (what I assume were) all release branches.

Samuel Bronson (3):
  Make libstdc++ testsuite work with pre-color GCC versions again
  libstdc++ testsuite: Turn off GDB's auto-load, list loaded libs
  Port libstdc++ pretty-printers to Python 2 + Python 3

 libstdc++-v3/python/libstdcxx/v6/printers.py | 110 +++
 libstdc++-v3/testsuite/lib/gdb-test.exp  |  15 +++-
 libstdc++-v3/testsuite/lib/libstdc++.exp |   4 +-
 3 files changed, 91 insertions(+), 38 deletions(-)

-- 
2.0.1



[PATCH v2 1/3] Make libstdc++ testsuite work with pre-color GCC versions again

2014-07-10 Thread Samuel Bronson

When I try to build & test just libstdc++, or to run the testsuite
from trunk against my installed libstdc++, the testsuite tries to pass
"-fdiagnostics-color=never" to the system GCC, which is too old to
know what that is.

Since I really just want to test a patch for the gdb pretty-printers,
and since evidently my machine is too puny to actually build GCC, this
is a bit problematic.

According to the documentation, setting GCC_COLORS to "" in the
environment should be just as effective, while it clearly can't cause
older GCCs to freak out, so that's just what I've done.

(I've also taken the liberty of swapping the "set ccflags" and "set
cxxflags" lines here so that ccflags doesn't end up with two
"-DLOCALEDIR" flags.)

libstdc++-v3/

* testsuite/lib/libstdc++.exp (libstdc++_init): Set $GCC_COLORS=""
  instead of insisting that GCC understand -fdiagnostics-color=never

Signed-off-by: Samuel Bronson 
---
 libstdc++-v3/testsuite/lib/libstdc++.exp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index d91bed6..0fdfbdc 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -289,9 +289,11 @@ proc libstdc++_init { testfile } {
 
 v3track cxxflags 2
 
+# Should be as good as -fdiagnostics-color=never, but more compatible
+setenv GCC_COLORS ""
 # Always use MO files built by this test harness.
-set cxxflags "-fdiagnostics-color=never $cxxflags -DLOCALEDIR=\".\""
 set ccflags "$cxxflags -DLOCALEDIR=\".\""
+set cxxflags "$cxxflags -DLOCALEDIR=\".\""
 
 # If a PCH file is available, use it.  We must delay performing
 # this check until $cxx and such have been initialized because we


[PATCH v2 2/3] libstdc++ testsuite: Turn off GDB's auto-load, list loaded libs

2014-07-10 Thread Samuel Bronson

We load our pretty-printers explicitly, and we shouldn't need any other
random -gdb.gdb or -gdb.py files from anywhere, so in this patch we turn
that off by running "set auto-load no".

Also, run "info share" so that the list of loaded libraries ends up in
the logs for the GDB tests.

libstdc++-v3/

* testsuite/lib/gdb-test.exp (gdb-test): Turn off GDB's auto-load, list
  loaded libs

Signed-off-by: Samuel Bronson 
---
 libstdc++-v3/testsuite/lib/gdb-test.exp | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/lib/gdb-test.exp b/libstdc++-v3/testsuite/lib/gdb-test.exp
index 1a72a44..6d7ea9d 100644
--- a/libstdc++-v3/testsuite/lib/gdb-test.exp
+++ b/libstdc++-v3/testsuite/lib/gdb-test.exp
@@ -116,10 +116,18 @@ proc gdb-test { marker {selector {}} } {
 global gdb_tests
 
 set fd [open $cmd_file "w"]
+# We don't want the system copy of the pretty-printers loaded
+puts $fd "set auto-load no"
+# Now that we've disabled auto-load, it's safe to set the target file
+puts $fd "file ./$output_file"
+# Load & register *our* copy of the pretty-printers
 puts $fd "source $pycode"
 puts $fd "python register_libstdcxx_printers(None)"
+# And start the program
 puts $fd "break $line"
 puts $fd "run"
+# So we can verify that we're using the right libs ...
+puts $fd "info share"
 
 set count 0
 foreach {var result kind} $gdb_tests {
@@ -147,8 +155,7 @@ proc gdb-test { marker {selector {}} } {
 puts $fd "quit"
 close $fd
 
-send_log "Spawning: $gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file\n"
-set res [remote_spawn target "$gdb_name -nx -nw -quiet -batch -x $cmd_file ./$output_file"]
+set res [remote_spawn target "$gdb_name -nx -nw -quiet -batch -x $cmd_file "]
 if { $res < 0 || $res == "" } {
 	unsupported "$testname"
 	return


[PATCH v2 3/3] Port libstdc++ pretty-printers to Python 2 + Python 3

2014-07-10 Thread Samuel Bronson

Loosely based on Mathias Klose' earlier patch
<http://patchwork.ozlabs.org/patch/287368/>.

Tested with:

$ make check-target-libstdc++-v3 RUNTESTFLAGS='--directory 
libstdc++-prettyprinters'

libstdc++-v3/

PR libstdc++/58962
* python/libstdcxx/v6/printers.py: Port to Python 2+3
  (imap): New compat function.
  (izip): Likewise.
  (Iterator): New mixin to allow writing iterators in Python 3 style
  regardless of which version we're running on.
  [Python3] (long) New compat alias for "int".
* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)

Signed-off-by: Mathias Klose 
Signed-off-by: Samuel Bronson 
---
 libstdc++-v3/python/libstdcxx/v6/printers.py | 110 +++
 libstdc++-v3/testsuite/lib/gdb-test.exp  |   4 +-
 2 files changed, 79 insertions(+), 35 deletions(-)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 623a815..313b08d 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1,4 +1,4 @@
-# Pretty-printers for libstc++.
+# Pretty-printers for libstdc++.
 
 # Copyright (C) 2008-2014 Free Software Foundation, Inc.
 
@@ -18,6 +18,50 @@
 import gdb
 import itertools
 import re
+import sys
+
+### Python 2 + Python 3 compatability code
+
+# Resources about compatability:
+#
+#  * <http://pythonhosted.org/six/>: Documentation of the "six" module
+
+# FIXME: The handling of e.g. std::basic_string (at least on char)
+# probably needs updating to work with Python 3's new string rules.
+#
+# In particular, Python 3 has a separate type (called byte) for
+# bytestrings, and a special b"" syntax for the byte literals; the old
+# str() type has been redefined to always store Unicode text.
+#
+# We probably can't do much about this until GDB get their act
+# together: <https://sourceware.org/bugzilla/show_bug.cgi?id=17138>
+
+if sys.version_info[0] > 2:
+### Python 3 stuff
+Iterator = object
+# Python 3 folds these into the normal functions.
+imap = map
+izip = zip
+# Also, int subsumes long
+long = int
+else:
+### Python 2 stuff
+class Iterator:
+"""Compatability mixin for iterators
+
+Instead of writing next() methods for iterators, write
+__next__() methods and use this mixin to make them work in
+Python 2 as well as Python 3.
+
+Idea stolen from the "six" documentation:
+<http://pythonhosted.org/six/#six.Iterator>
+"""
+
+def next(self):
+return self.__next__()
+
+# In Python 2, we still need these from itertools
+from itertools import imap, izip
 
 # Try to use the new-style pretty-printing if available.
 _use_gdb_pp = True
@@ -87,7 +131,7 @@ class UniquePointerPrinter:
 class StdListPrinter:
 "Print a std::list"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__(self, nodetype, head):
 self.nodetype = nodetype
 self.base = head['_M_next']
@@ -97,7 +141,7 @@ class StdListPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 if self.base == self.head:
 raise StopIteration
 elt = self.base.cast(self.nodetype).dereference()
@@ -135,7 +179,7 @@ class StdListIteratorPrinter:
 class StdSlistPrinter:
 "Print a __gnu_cxx::slist"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__(self, nodetype, head):
 self.nodetype = nodetype
 self.base = head['_M_head']['_M_next']
@@ -144,7 +188,7 @@ class StdSlistPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 if self.base == 0:
 raise StopIteration
 elt = self.base.cast(self.nodetype).dereference()
@@ -180,7 +224,7 @@ class StdSlistIteratorPrinter:
 class StdVectorPrinter:
 "Print a std::vector"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__ (self, start, finish, bitvec):
 self.bitvec = bitvec
 if bitvec:
@@ -198,7 +242,7 @@ class StdVectorPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 count = self.count
 self.count = self.count + 1
 if self.bitvec:
@@ -265,7 +309,7 @@ class StdVectorIteratorPrinter:
 class StdTuplePrinter:
 "Print a std::tuple"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__ (self, head):
 self.head = head
 
@@ -282,7 +326,7 @@ class StdTuplePrinter:
 def __iter__ (self):
 return 

[PATCH v3 3/3] Port libstdc++ pretty-printers to Python 2 + Python 3

2014-07-10 Thread Samuel Bronson

Loosely based on Matthias Klose's earlier patch
<http://patchwork.ozlabs.org/patch/287368/>.

This time with his name spelled correctly; sorry about that!

Tested with:

$ make check-target-libstdc++-v3 RUNTESTFLAGS='--directory 
libstdc++-prettyprinters'

libstdc++-v3/

PR libstdc++/58962
* python/libstdcxx/v6/printers.py: Port to Python 2+3
  (imap): New compat function.
  (izip): Likewise.
  (Iterator): New mixin to allow writing iterators in Python 3 style
  regardless of which version we're running on.
  [Python3] (long) New compat alias for "int".
* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)

Signed-off-by: Matthias Klose 
Signed-off-by: Samuel Bronson 
---
 libstdc++-v3/python/libstdcxx/v6/printers.py | 110 +++
 libstdc++-v3/testsuite/lib/gdb-test.exp  |   4 +-
 2 files changed, 79 insertions(+), 35 deletions(-)

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 623a815..313b08d 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1,4 +1,4 @@
-# Pretty-printers for libstc++.
+# Pretty-printers for libstdc++.
 
 # Copyright (C) 2008-2014 Free Software Foundation, Inc.
 
@@ -18,6 +18,50 @@
 import gdb
 import itertools
 import re
+import sys
+
+### Python 2 + Python 3 compatability code
+
+# Resources about compatability:
+#
+#  * <http://pythonhosted.org/six/>: Documentation of the "six" module
+
+# FIXME: The handling of e.g. std::basic_string (at least on char)
+# probably needs updating to work with Python 3's new string rules.
+#
+# In particular, Python 3 has a separate type (called byte) for
+# bytestrings, and a special b"" syntax for the byte literals; the old
+# str() type has been redefined to always store Unicode text.
+#
+# We probably can't do much about this until GDB get their act
+# together: <https://sourceware.org/bugzilla/show_bug.cgi?id=17138>
+
+if sys.version_info[0] > 2:
+### Python 3 stuff
+Iterator = object
+# Python 3 folds these into the normal functions.
+imap = map
+izip = zip
+# Also, int subsumes long
+long = int
+else:
+### Python 2 stuff
+class Iterator:
+"""Compatability mixin for iterators
+
+Instead of writing next() methods for iterators, write
+__next__() methods and use this mixin to make them work in
+Python 2 as well as Python 3.
+
+Idea stolen from the "six" documentation:
+<http://pythonhosted.org/six/#six.Iterator>
+"""
+
+def next(self):
+return self.__next__()
+
+# In Python 2, we still need these from itertools
+from itertools import imap, izip
 
 # Try to use the new-style pretty-printing if available.
 _use_gdb_pp = True
@@ -87,7 +131,7 @@ class UniquePointerPrinter:
 class StdListPrinter:
 "Print a std::list"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__(self, nodetype, head):
 self.nodetype = nodetype
 self.base = head['_M_next']
@@ -97,7 +141,7 @@ class StdListPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 if self.base == self.head:
 raise StopIteration
 elt = self.base.cast(self.nodetype).dereference()
@@ -135,7 +179,7 @@ class StdListIteratorPrinter:
 class StdSlistPrinter:
 "Print a __gnu_cxx::slist"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__(self, nodetype, head):
 self.nodetype = nodetype
 self.base = head['_M_head']['_M_next']
@@ -144,7 +188,7 @@ class StdSlistPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 if self.base == 0:
 raise StopIteration
 elt = self.base.cast(self.nodetype).dereference()
@@ -180,7 +224,7 @@ class StdSlistIteratorPrinter:
 class StdVectorPrinter:
 "Print a std::vector"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__ (self, start, finish, bitvec):
 self.bitvec = bitvec
 if bitvec:
@@ -198,7 +242,7 @@ class StdVectorPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 count = self.count
 self.count = self.count + 1
 if self.bitvec:
@@ -265,7 +309,7 @@ class StdVectorIteratorPrinter:
 class StdTuplePrinter:
 "Print a std::tuple"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__ (self, head):
 self.head = head
 
@@ -282,7 +326,7 @@ class

[COMMIT] Add a .gitattributes file for use with git-merge-changelog

2014-07-25 Thread Samuel Bronson
Individual users will still have to:

 1. Install git-merge-changelog

 2. Set up the merge driver in their git config

See gnulib's lib/git-merge-changelog.c [1] for details.

For example, I:

 1. Patched Debian's gnulib package to build git-merge-changelog, and
sent the patch to the Debian maintainer, who then proceeded to not
only accept my patch but even write a *manpage* for
git-merge-changelog! (Let's hear it for Ian Beckwith.)

So now, I can install it simply by running "apt-get install
git-merge-changelog".  (Except, of course, that I already have it
installed from when I was testing my patch.)

 2. Did step (2) from .gitattributes

With this patch applied and the above two steps done by whatever means
you deem best, you can say goodbye to merge conflicts in ChangeLog
files -- at least *IF* people stop renaming the danged things, anyway.

If you don't do step 2, you will continue to suffer from ChangeLog
merge conflicts exactly as before, whether or not you did step 1.

If you do step 2 but not step 1, git will likely start complaining
that it can't find any "git-merge-changelog" to run.

[1]: 
http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/git-merge-changelog.c

[Note: The docs for git-merge-changelog (the comments at the top) say
that you need a .gitattributes in every directory.  The docs are wrong.
Ignore the docs.  Well, not the whole docs; just that part.

You really only need one at the top level, since .gitattributes uses
the same pattern matching rules as .gitignore, which match files in
any subdirectory unless you prefix the pattern with a "/", as
explained in the gitignore(5) manpage.]
---
 .gitattributes | 20 
 ChangeLog  |  4 
 2 files changed, 24 insertions(+)
 create mode 100644 .gitattributes

diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000..06d51d2
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,20 @@
+# -*- conf -*-
+
+## Set merge driver for ChangeLog files 
+# See gnulib's lib/git-merge-changelog.c (or git-merge-changelog(1))
+# for per-user setup instructions.
+#
+# The short version of this (optional) procedure is:
+# 
+# (1) Install git-merge-changelog (this is the tricky part!)
+#
+# (2) Add something like the following to your ~/.gitconfig:
+#
+# [merge "merge-changelog"]
+# name = GNU-style ChangeLog merge driver
+# driver = git-merge-changelog %O %A %B
+#
+# (3) Enjoy mostly effortless ChangeLog merges, at least until the
+# file gets renamed again ...
+
+ChangeLog   merge=merge-changelog
diff --git a/ChangeLog b/ChangeLog
index 16047d3..5c8fe15 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-07-25  Samuel Bronson  
+
+   * .gitattributes: New file for use with git-merge-changelog.
+
 2014-07-21  Joel Sherrill  
 
Disable gdb for or1k*-*-* until supported
-- 
2.0.1



Re: [PATCH v3 3/3] Port libstdc++ pretty-printers to Python 2 + Python 3

2014-07-25 Thread Samuel Bronson
Tom Tromey  writes:

>>>>>> "Samuel" == Samuel Bronson  writes:
>
> Samuel> +# FIXME: The handling of e.g. std::basic_string (at least on char)
> Samuel> +# probably needs updating to work with Python 3's new string rules.
> Samuel> +#
> Samuel> +# In particular, Python 3 has a separate type (called byte) for
> Samuel> +# bytestrings, and a special b"" syntax for the byte literals; the 
> old
> Samuel> +# str() type has been redefined to always store Unicode text.
> Samuel> +#
> Samuel> +# We probably can't do much about this until GDB get their act
> Samuel> +# together: <https://sourceware.org/bugzilla/show_bug.cgi?id=17138>
>
> I don't think this comment is applicable.
> The libstdc++ pretty-printers use gdb.Value.lazy_string, not the
> built-in Python types.

Hmm, doesn't that just make it a timebomb -- a value that will explode
if, at some point in the future, someone tries to treat it as a string?

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!


[PATCH 4.9] libstdc++ pretty-printers: Backport Python 3 support from mainline

2014-08-03 Thread Samuel Bronson

Since Jonathan Wakely independantly committed some of the changes I was
preparing, I had to backport two commits, r210625 and r212453
(git commits 3a30bda and b0a6074).

2014-08-02  Samuel Bronson  

Backport r212453 from trunk
2014-07-11  Samuel Bronson  
Matthias Klose  

PR libstdc++/58962
* python/libstdcxx/v6/printers.py: Port to Python 2+3
(imap): New compat function.
(izip): Likewise.
(Iterator): New mixin to allow writing iterators in Python 3 style
regardless of which version we're running on.
[Python3] (long) New compat alias for "int".
* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)

Backport r210625 from trunk
2014-05-19  Jonathan Wakely  

* python/libstdcxx/v6/printers.py: Use Python3 raise syntax.
---
 libstdc++-v3/ChangeLog   |  20 +
 libstdc++-v3/python/libstdcxx/v6/printers.py | 120 ++-
 libstdc++-v3/testsuite/lib/gdb-test.exp  |   4 +-
 3 files changed, 104 insertions(+), 40 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 09b7017..26f0372 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,23 @@
+2014-08-02  Samuel Bronson  
+
+	Backport r212453 from trunk
+	2014-07-11  Samuel Bronson  
+		Matthias Klose  
+
+	PR libstdc++/58962
+	* python/libstdcxx/v6/printers.py: Port to Python 2+3
+	(imap): New compat function.
+	(izip): Likewise.
+	(Iterator): New mixin to allow writing iterators in Python 3 style
+	regardless of which version we're running on.
+	[Python3] (long) New compat alias for "int".
+	* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)
+
+	Backport r210625 from trunk
+	2014-05-19  Jonathan Wakely  
+
+	* python/libstdcxx/v6/printers.py: Use Python3 raise syntax.
+
 2014-07-29  Ed Smith-Rowland  <3dw...@verizon.net>
 
 	PR libstdc++/60037 - SIGFPE in std::generate_canonical
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index 1f1f860..1fa08fb 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -1,4 +1,4 @@
-# Pretty-printers for libstc++.
+# Pretty-printers for libstdc++.
 
 # Copyright (C) 2008-2014 Free Software Foundation, Inc.
 
@@ -18,6 +18,50 @@
 import gdb
 import itertools
 import re
+import sys
+
+### Python 2 + Python 3 compatibility code
+
+# Resources about compatibility:
+#
+#  * <http://pythonhosted.org/six/>: Documentation of the "six" module
+
+# FIXME: The handling of e.g. std::basic_string (at least on char)
+# probably needs updating to work with Python 3's new string rules.
+#
+# In particular, Python 3 has a separate type (called byte) for
+# bytestrings, and a special b"" syntax for the byte literals; the old
+# str() type has been redefined to always store Unicode text.
+#
+# We probably can't do much about this until this GDB PR is addressed:
+# <https://sourceware.org/bugzilla/show_bug.cgi?id=17138>
+
+if sys.version_info[0] > 2:
+### Python 3 stuff
+Iterator = object
+# Python 3 folds these into the normal functions.
+imap = map
+izip = zip
+# Also, int subsumes long
+long = int
+else:
+### Python 2 stuff
+class Iterator:
+"""Compatibility mixin for iterators
+
+Instead of writing next() methods for iterators, write
+__next__() methods and use this mixin to make them work in
+Python 2 as well as Python 3.
+
+Idea stolen from the "six" documentation:
+<http://pythonhosted.org/six/#six.Iterator>
+"""
+
+def next(self):
+return self.__next__()
+
+# In Python 2, we still need these from itertools
+from itertools import imap, izip
 
 # Try to use the new-style pretty-printing if available.
 _use_gdb_pp = True
@@ -51,7 +95,7 @@ def find_type(orig, name):
 # anything fancier here.
 field = typ.fields()[0]
 if not field.is_base_class:
-raise ValueError, "Cannot find type %s::%s" % (str(orig), name)
+raise ValueError("Cannot find type %s::%s" % (str(orig), name))
 typ = field.type
 
 class SharedPointerPrinter:
@@ -87,7 +131,7 @@ class UniquePointerPrinter:
 class StdListPrinter:
 "Print a std::list"
 
-class _iterator:
+class _iterator(Iterator):
 def __init__(self, nodetype, head):
 self.nodetype = nodetype
 self.base = head['_M_next']
@@ -97,7 +141,7 @@ class StdListPrinter:
 def __iter__(self):
 return self
 
-def next(self):
+def __next__(self):
 if self.base == self.head:
 raise StopIteration
 elt = self.base.cast(se

Converting function pointers to PC values in Python (was: [patch] Add libstdc++ type printers for class templates)

2014-08-04 Thread Samuel Bronson
Jonathan Wakely  writes:

> One part of the patch I wasn't sure about was this, where 'mgr' is a
> function pointer:
>
>  func = gdb.block_for_pc(int(mgr.cast(gdb.lookup_type('intptr_t'
>
> Is there a better way to get a pc from the function pointer?
> I tried simply int(mgr) but it didn't work.

Well, long() WFM; e.g. with Python 2 and gdb 7.8.50.20140706-cvs I can do:

(gdb) python print(long(gdb.parse_and_eval("(void(*)())-1")))
4294967295

The fact that int() does not work the same way may indicate a
shortcoming in gdb.Value.__int__(); I'm told that in recent 2.x
versions, int() is perfectly happy returning a long instead of an int.

Of course, this still presumably won't work on architectures where
function pointers don't point straight to the code, e.g. most PowerPC,
where as I understand things it actually points at a "function
descriptor", which in turn references the actual code.

So it seems we're missing an API for this.

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!