Patchwork [libstdc++,v5] - Add xmethods for std::vector and std::unique_ptr

login
register
mail settings
Submitter Siva Chandra
Date Aug. 27, 2014, 9:39 p.m.
Message ID <CAGyQ6gxAYwoi3gLkH-Ut_qRfHpTbV0Dke+bd9BRk_e7cWj4nOA@mail.gmail.com>
Download mbox | patch
Permalink /patch/383574/
State New
Headers show

Comments

Siva Chandra - Aug. 27, 2014, 9:39 p.m.
The attached patch addresses Jonathan Wakely's comments on the
previous version of the patch:
https://gcc.gnu.org/ml/gcc-patches/2014-08/msg02426.html

On Tue, Aug 26, 2014 at 10:58 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> Shouldn't there be a change to python/Makefile.am so that xmethods.py
> gets installed alongside printers.py? Otherwise you can use these new
> xmethods in the libstdc++ testssuite, but they're not available to
> users.

Ah, sorry I missed that. Added in the attached patch.

> I'd also expect something to call the register_libstdcxx_xmethods
> function automatically, as in the attached patch, although this
> doesn't work for me.

gdb.xmethod is a module. Hence, hasattr(gdb, 'xmethod') in your
suggestion will not return True. I have modified this in the attached
patch to something which should work.

I had something in hook.in in my very first patch but Tom Tromey said
it was not required anymore:
https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02405.html

> How am I expected to use these xmethods?

If you use the * operator on a unique_ptr or [] operator on a vector
in GDB, the xmethods will be called. Without the xmethods, GDB will
print something like "No matching method for
unique_ptr<...>::operator* found" if those operators were not used in
the source.

ChangeLog:
2014-08-27  Siva Chandra Reddy  <sivachandra@google.com>

        * python/hook.in: Load the xmethods.
        * python/Makefile.am (nobase_python_DATA): Add xmethods.py.
        * python/Makefile.in: Regenerated.
        * python/libstdcxx/v6/xmethods.py: New file.
        * testsuite/lib/gdb-test.exp (gdb_version_check_xmethods): New
        function.
        (gdb-test): New optional argument LOAD_XMETHODS.  Load xmethods
        python script if LOAD_XMETHODS is true.
        * testsuite/libstdc++-xmethods/unique_ptr.cc: New file.
        * testsuite/libstdc++-xmethods/vector.cc: New file.
        * testsuite/libstdc++-xmethods/xmethods.exp: New file.
Jonathan Wakely - Aug. 27, 2014, 10:19 p.m.
On 27 August 2014 22:39, Siva Chandra wrote:
> The attached patch addresses Jonathan Wakely's comments on the
> previous version of the patch:
> https://gcc.gnu.org/ml/gcc-patches/2014-08/msg02426.html
>
> On Tue, Aug 26, 2014 at 10:58 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
>> Shouldn't there be a change to python/Makefile.am so that xmethods.py
>> gets installed alongside printers.py? Otherwise you can use these new
>> xmethods in the libstdc++ testssuite, but they're not available to
>> users.
>
> Ah, sorry I missed that. Added in the attached patch.

Great, I'll try this new version tomorrow.

>> I'd also expect something to call the register_libstdcxx_xmethods
>> function automatically, as in the attached patch, although this
>> doesn't work for me.
>
> gdb.xmethod is a module. Hence, hasattr(gdb, 'xmethod') in your
> suggestion will not return True. I have modified this in the attached
> patch to something which should work.

OK thanks.

> I had something in hook.in in my very first patch but Tom Tromey said
> it was not required anymore:
> https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02405.html

Interesting, I wonder how they should have been found then. I think I
did test with the files installed, but they weren't used. I'll test
again with the new patch.
Tom Tromey - Aug. 27, 2014, 10:31 p.m.
>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:

Siva> I had something in hook.in in my very first patch but Tom Tromey said
Siva> it was not required anymore:
Siva> https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02405.html

What I meant was that there should just be a single function called by
the hook file, and that it should handle the xmethod additions by some
means as well.

Tom
Siva Chandra - Aug. 27, 2014, 10:36 p.m.
On Wed, Aug 27, 2014 at 3:31 PM, Tom Tromey <tom@tromey.com> wrote:
>>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:
>
> Siva> I had something in hook.in in my very first patch but Tom Tromey said
> Siva> it was not required anymore:
> Siva> https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02405.html
>
> What I meant was that there should just be a single function called by
> the hook file, and that it should handle the xmethod additions by some
> means as well.

I misunderstood then. But, I still do not understand what you mean by
"single function".

Thanks,
Siva Chandra
Siva Chandra - Aug. 27, 2014, 10:38 p.m.
On Wed, Aug 27, 2014 at 3:19 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> I think I
> did test with the files installed, but they weren't used. I'll test
> again with the new patch.

You are probably already doing it, but just in case: are you using GDB
7.8 (or later, like ToT) ? You most likely are as otherwise the tests
added by this patch will not be exercised.

Thanks,
Siva Chandra
Tom Tromey - Aug. 27, 2014, 10:45 p.m.
>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:

Tom> What I meant was that there should just be a single function called by
Tom> the hook file, and that it should handle the xmethod additions by some
Tom> means as well.

Siva> I misunderstood then. But, I still do not understand what you mean by
Siva> "single function".

I re-read my original note, and I think I wasn't very clear.  Sorry
about that.

All I mean here is that I think it's better to have a single
registration function in the libstdc++ python code.  This function can
do all the needed work.

Tom
Jonathan Wakely - Aug. 27, 2014, 10:58 p.m.
On 27 August 2014 23:38, Siva Chandra wrote:
> You are probably already doing it, but just in case: are you using GDB
> 7.8 (or later, like ToT) ? You most likely are as otherwise the tests
> added by this patch will not be exercised.

Yes, I'm testing with both 7.8 (where it should work) and an older
version (where it should fail gracefully).
Siva Chandra - Aug. 28, 2014, 1:51 a.m.
On Wed, Aug 27, 2014 at 3:45 PM, Tom Tromey <tom@tromey.com> wrote:
> Siva> I misunderstood then. But, I still do not understand what you mean by
> Siva> "single function".
>
> I re-read my original note, and I think I wasn't very clear.  Sorry
> about that.
>
> All I mean here is that I think it's better to have a single
> registration function in the libstdc++ python code.  This function can
> do all the needed work.

My patch is still using a single function to register libstdc++
xmethods. Do you mean there should be a single function for pretty
printers and xmethods together?

Thanks,
Siva Chandra
Tom Tromey - Aug. 28, 2014, 2:11 a.m.
Siva> My patch is still using a single function to register libstdc++
Siva> xmethods. Do you mean there should be a single function for pretty
Siva> printers and xmethods together?

Yeah, that's my view.

Tom
Siva Chandra - Aug. 28, 2014, 4:33 p.m.
On Wed, Aug 27, 2014 at 7:11 PM, Tom Tromey <tom@tromey.com> wrote:
> Siva> My patch is still using a single function to register libstdc++
> Siva> xmethods. Do you mean there should be a single function for pretty
> Siva> printers and xmethods together?
>
> Yeah, that's my view.

I am probably not understanding it right again. Are you suggesting
that in hook.in, we just have single function call like this:

register_python_hooks (gdb.current_objfile ())

and, this function register_python_hooks lives somewhere else and
calls register_libstdcxx_printers and register_libstdcxx_xmethods?

Thanks,
Siva Chandra
Tom Tromey - Aug. 28, 2014, 5:15 p.m.
>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:

Tom> Yeah, that's my view.

Siva> I am probably not understanding it right again.

It's ok.  I am having some trouble myself.

Siva> Are you suggesting that in hook.in, we just have single function
Siva> call like this:
Siva> register_python_hooks (gdb.current_objfile ())
Siva> and, this function register_python_hooks lives somewhere else and
Siva> calls register_libstdcxx_printers and register_libstdcxx_xmethods?

Yeah.  I think it's better to put as little as possible in the hook file.
I realize this may sound ridiculous given all the code that is already
there; but that's an artifact of gcc's install-relocatability requirement.

Tom
Siva Chandra - Aug. 28, 2014, 6:45 p.m.
On Thu, Aug 28, 2014 at 10:15 AM, Tom Tromey <tom@tromey.com> wrote:
> Siva> Are you suggesting that in hook.in, we just have single function
> Siva> call like this:
> Siva> register_python_hooks (gdb.current_objfile ())
> Siva> and, this function register_python_hooks lives somewhere else and
> Siva> calls register_libstdcxx_printers and register_libstdcxx_xmethods?
>
> Yeah.  I think it's better to put as little as possible in the hook file.
> I realize this may sound ridiculous given all the code that is already
> there; but that's an artifact of gcc's install-relocatability requirement.

OK. Do you think I could do this as a follow up? May be not
considerable, but seems to me like it distracts the intent of this
patch?

Thanks,
Siva Chandra
Siva Chandra - Sept. 3, 2014, 6:01 p.m.
Ping. I am not sure if the "OK to ping weekly" applies to GCC patches
as well. I apologize if it has to be longer.

On Wed, Aug 27, 2014 at 3:58 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 27 August 2014 23:38, Siva Chandra wrote:
>> You are probably already doing it, but just in case: are you using GDB
>> 7.8 (or later, like ToT) ? You most likely are as otherwise the tests
>> added by this patch will not be exercised.
>
> Yes, I'm testing with both 7.8 (where it should work) and an older
> version (where it should fail gracefully).
Jonathan Wakely - Sept. 3, 2014, 10:35 p.m.
On 03/09/14 11:01 -0700, Siva Chandra wrote:
>Ping. I am not sure if the "OK to ping weekly" applies to GCC patches
>as well. I apologize if it has to be longer.

I was waiting to see which version of the patch actually works, so
that users can use the xmethods. There's no point committing the patch
if they aren't installed and can't be used!

Also, Tom had objections to the most recent patch, which haven't been
addressed. 

I suppose we can fix that later.
Siva Chandra - Sept. 3, 2014, 10:47 p.m.
On Wed, Sep 3, 2014 at 3:35 PM, Jonathan Wakely <jwakely@redhat.com> wrote:
> I was waiting to see which version of the patch actually works, so
> that users can use the xmethods. There's no point committing the patch
> if they aren't installed and can't be used!

Doesn't the latest version of the patch I posted work for you:
https://gcc.gnu.org/ml/gcc-patches/2014-08/msg02516.html

If not, what errors or missing things do you see?

> Also, Tom had objections to the most recent patch, which haven't been
> addressed.

I am a bit confused about his suggestion and hence I asked if it can
be addressed as a follow up. It seems to me like his suggestion is a
code cleanup, but I am not really sure what the aim of the cleanup is.
To avoid mixing up discussing that versus the aim the patch in
question, I am asking if it can addressed as a follow up.

Thanks,
Siva Chandra
Siva Chandra - Sept. 4, 2014, 12:56 p.m.
On Wed, Sep 3, 2014 at 3:47 PM, Siva Chandra <sivachandra@google.com> wrote:
> On Wed, Sep 3, 2014 at 3:35 PM, Jonathan Wakely <jwakely@redhat.com> wrote:
>> I was waiting to see which version of the patch actually works, so
>> that users can use the xmethods. There's no point committing the patch
>> if they aren't installed and can't be used!
>
> Doesn't the latest version of the patch I posted work for you:
> https://gcc.gnu.org/ml/gcc-patches/2014-08/msg02516.html
>
> If not, what errors or missing things do you see?

To clarify, the reason I am asking for errors or missing pieces is
because things work as expected for me with the latest patch; The
xmethods get installed and GDB automatically loads them.
Jonathan Wakely - Sept. 10, 2014, 1:18 p.m.
On 04/09/14 05:56 -0700, Siva Chandra wrote:
>On Wed, Sep 3, 2014 at 3:47 PM, Siva Chandra <sivachandra@google.com> wrote:
>> On Wed, Sep 3, 2014 at 3:35 PM, Jonathan Wakely <jwakely@redhat.com> wrote:
>>> I was waiting to see which version of the patch actually works, so
>>> that users can use the xmethods. There's no point committing the patch
>>> if they aren't installed and can't be used!
>>
>> Doesn't the latest version of the patch I posted work for you:
>> https://gcc.gnu.org/ml/gcc-patches/2014-08/msg02516.html
>>
>> If not, what errors or missing things do you see?
>
>To clarify, the reason I am asking for errors or missing pieces is
>because things work as expected for me with the latest patch; The
>xmethods get installed and GDB automatically loads them.

I've committed the v5 patch to trunk now.

It would be nice to address Tom's comment at some future time, so we
only have one entry point in the hook.in file.
Siva Chandra - Sept. 10, 2014, 1:44 p.m.
On Wed, Sep 10, 2014 at 6:18 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> I've committed the v5 patch to trunk now.

Thanks a lot.

> It would be nice to address Tom's comment at some future time, so we
> only have one entry point in the hook.in file.

I will do it before I add more xmethods.

Thanks,
Siva Chandra

Patch

diff --git a/libstdc++-v3/python/Makefile.am b/libstdc++-v3/python/Makefile.am
index ac7341a..c34c860 100644
--- a/libstdc++-v3/python/Makefile.am
+++ b/libstdc++-v3/python/Makefile.am
@@ -33,6 +33,7 @@  all-local: gdb.py
 
 nobase_python_DATA = \
     libstdcxx/v6/printers.py \
+    libstdcxx/v6/xmethods.py \
     libstdcxx/v6/__init__.py \
     libstdcxx/__init__.py
 
diff --git a/libstdc++-v3/python/Makefile.in b/libstdc++-v3/python/Makefile.in
index 21d74a90..7d0c8ac 100644
--- a/libstdc++-v3/python/Makefile.in
+++ b/libstdc++-v3/python/Makefile.in
@@ -316,6 +316,7 @@  AM_CPPFLAGS = $(GLIBCXX_INCLUDES)
 @ENABLE_PYTHONDIR_TRUE@pythondir = $(prefix)/$(python_mod_dir)
 nobase_python_DATA = \
     libstdcxx/v6/printers.py \
+    libstdcxx/v6/xmethods.py \
     libstdcxx/v6/__init__.py \
     libstdcxx/__init__.py
 
diff --git a/libstdc++-v3/python/hook.in b/libstdc++-v3/python/hook.in
index 3620523..aeb1cdb 100644
--- a/libstdc++-v3/python/hook.in
+++ b/libstdc++-v3/python/hook.in
@@ -58,3 +58,15 @@  if gdb.current_objfile () is not None:
 # Load the pretty-printers.
 from libstdcxx.v6.printers import register_libstdcxx_printers
 register_libstdcxx_printers (gdb.current_objfile ())
+
+# Load the xmethods if GDB supports them.
+def gdb_has_xmethods():
+    try:
+        import gdb.xmethod
+        return True
+    except ImportError:
+        return False
+
+if gdb_has_xmethods():
+    from libstdcxx.v6.xmethods import register_libstdcxx_xmethods
+    register_libstdcxx_xmethods (gdb.current_objfile ())
diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
new file mode 100644
index 0000000..f20f411
--- /dev/null
+++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
@@ -0,0 +1,103 @@ 
+# Xmethods for libstc++.
+
+# Copyright (C) 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import gdb
+import gdb.xmethod
+import re
+
+matcher_name_prefix = 'libstdc++::'
+
+# Xmethods for std::vector
+
+class VectorSizeWorker(gdb.xmethod.XMethodWorker):
+    def __init__(self):
+        self.name = 'size'
+        self.enabled = True
+
+    def get_arg_types(self):
+        return None
+
+    def __call__(self, obj):
+        return obj['_M_impl']['_M_finish'] - obj['_M_impl']['_M_start']
+
+class VectorSubscriptWorker(gdb.xmethod.XMethodWorker):
+    def __init__(self):
+        self.name = 'operator[]'
+        self.enabled = True
+
+    def get_arg_types(self):
+        return gdb.lookup_type('std::size_t')
+
+    def __call__(self, obj, subscript):
+        return obj['_M_impl']['_M_start'][subscript]
+
+class VectorMethodsMatcher(gdb.xmethod.XMethodMatcher):
+    def __init__(self):
+        gdb.xmethod.XMethodMatcher.__init__(self,
+                                            matcher_name_prefix + 'vector')
+        self._subscript_worker = VectorSubscriptWorker()
+        self._size_worker = VectorSizeWorker()
+        self.methods = [self._subscript_worker, self._size_worker]
+
+    def match(self, class_type, method_name):
+        if not re.match('^std::vector<.*>$', class_type.tag):
+            return None
+        if method_name == 'operator[]' and self._subscript_worker.enabled:
+            return self._subscript_worker
+        elif method_name == 'size' and self._size_worker.enabled:
+            return self._size_worker
+
+# Xmethods for std::unique_ptr
+
+class UniquePtrGetWorker(gdb.xmethod.XMethodWorker):
+    def __init__(self):
+        self.name = 'get'
+        self.enabled = True
+
+    def get_arg_types(self):
+        return None
+
+    def __call__(self, obj):
+        return obj['_M_t']['_M_head_impl']
+
+class UniquePtrDerefWorker(UniquePtrGetWorker):
+    def __init__(self):
+        UniquePtrGetWorker.__init__(self)
+        self.name = 'operator*'
+
+    def __call__(self, obj):
+        return UniquePtrGetWorker.__call__(self, obj).dereference()
+
+class UniquePtrMethodsMatcher(gdb.xmethod.XMethodMatcher):
+    def __init__(self):
+        gdb.xmethod.XMethodMatcher.__init__(self,
+                                            matcher_name_prefix + 'unique_ptr')
+        self._get_worker = UniquePtrGetWorker()
+        self._deref_worker = UniquePtrDerefWorker()
+        self.methods = [self._get_worker, self._deref_worker]
+
+    def match(self, class_type, method_name):
+        if not re.match('^std::unique_ptr<.*>$', class_type.tag):
+            return None
+        if method_name == 'operator*' and self._deref_worker.enabled:
+            return self._deref_worker
+        elif method_name == 'get' and self._get_worker.enabled:
+            return self._get_worker
+
+def register_libstdcxx_xmethods(locus):
+    gdb.xmethod.register_xmethod_matcher(locus, VectorMethodsMatcher())
+    gdb.xmethod.register_xmethod_matcher(locus, UniquePtrMethodsMatcher())
diff --git a/libstdc++-v3/testsuite/lib/gdb-test.exp b/libstdc++-v3/testsuite/lib/gdb-test.exp
index 9cb6ecf..1a68217 100644
--- a/libstdc++-v3/testsuite/lib/gdb-test.exp
+++ b/libstdc++-v3/testsuite/lib/gdb-test.exp
@@ -79,7 +79,7 @@  proc whatis-test {var result} {
 #
 # Argument 0 is the marker on which to put a breakpoint
 # Argument 2 handles expected failures and the like
-proc gdb-test { marker {selector {}} } {
+proc gdb-test { marker {selector {}} {load_xmethods 0} } {
     if { ![isnative] || [is_remote target] } { return }
 
     if {[string length $selector] > 0} {
@@ -111,7 +111,8 @@  proc gdb-test { marker {selector {}} } {
     set cmd_file "[file rootname [file tail $prog]].gdb"
 
     global srcdir
-    set pycode [file join $srcdir .. python libstdcxx v6 printers.py]
+    set printer_code [file join $srcdir .. python libstdcxx v6 printers.py]
+    set xmethod_code [file join $srcdir .. python libstdcxx v6 xmethods.py]
 
     global gdb_tests
 
@@ -121,8 +122,13 @@  proc gdb-test { marker {selector {}} } {
     # 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 "source $printer_code"
     puts $fd "python register_libstdcxx_printers(None)"
+    if { $load_xmethods } {
+	# Load a& register xmethods.
+	puts $fd "source $xmethod_code"
+	puts $fd "python register_libstdcxx_xmethods(None)"
+    }
     # And start the program
     puts $fd "break $line"
     puts $fd "run"
@@ -262,3 +268,12 @@  proc gdb_version_check {} {
     return [gdb_batch_check "python print(gdb.lookup_global_symbol)" \
 	      "<built-in function lookup_global_symbol>"]
 }
+
+# Check for a version of gdb which supports xmethod tests.  It is done
+# in a manner similar to the check for a version of gdb which supports the
+# pretty-printer tests below.
+proc gdb_version_check_xmethods {} {
+    return [gdb_batch_check \
+	      "python import gdb.xmethod; print(gdb.xmethod.XMethod)" \
+	      "<class 'gdb\\.xmethod\\.XMethod'>"]
+}
diff --git a/libstdc++-v3/testsuite/libstdc++-xmethods/unique_ptr.cc b/libstdc++-v3/testsuite/libstdc++-xmethods/unique_ptr.cc
new file mode 100644
index 0000000..6c9fd8e
--- /dev/null
+++ b/libstdc++-v3/testsuite/libstdc++-xmethods/unique_ptr.cc
@@ -0,0 +1,36 @@ 
+// { dg-do run }
+// { dg-options "-std=gnu++11 -g -O0" }
+
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <memory>
+
+int
+main ()
+{
+  int *i = new int;
+  *i = 10;
+
+  std::unique_ptr<int> p(i);
+// { dg-final { note-test *p 10 } }
+// { dg-final { regexp-test p.get() 0x.* } }
+
+  return 0;  // Mark SPOT
+}
+
+// { dg-final { gdb-test SPOT {} 1 } }
diff --git a/libstdc++-v3/testsuite/libstdc++-xmethods/vector.cc b/libstdc++-v3/testsuite/libstdc++-xmethods/vector.cc
new file mode 100644
index 0000000..2ee9399
--- /dev/null
+++ b/libstdc++-v3/testsuite/libstdc++-xmethods/vector.cc
@@ -0,0 +1,38 @@ 
+// { dg-do run }
+// { dg-options "-g -O0" }
+
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <vector>
+
+int
+main ()
+{
+  std::vector<int> v;
+  v.push_back(1);
+  v.push_back(2);
+  v.push_back(3);
+// { dg-final { note-test v\[0\] 1 } }
+// { dg-final { note-test v\[1\] 2 } }
+// { dg-final { note-test v\[2\] 3 } }
+// { dg-final { note-test v.size() 3 } }
+
+  return 0;  // Mark SPOT
+}
+
+// { dg-final { gdb-test SPOT {} 1 } }
diff --git a/libstdc++-v3/testsuite/libstdc++-xmethods/xmethods.exp b/libstdc++-v3/testsuite/libstdc++-xmethods/xmethods.exp
new file mode 100644
index 0000000..c51c7e8
--- /dev/null
+++ b/libstdc++-v3/testsuite/libstdc++-xmethods/xmethods.exp
@@ -0,0 +1,51 @@ 
+#   Copyright (C) 2014 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+load_lib gdb-test.exp
+
+dg-init
+v3-build_support
+
+global GDB
+if ![info exists ::env(GUALITY_GDB_NAME)] {
+    if [info exists GDB] {
+	set guality_gdb_name "$GDB"
+    } else {
+	set guality_gdb_name "[transform gdb]"
+    }
+    setenv GUALITY_GDB_NAME "$guality_gdb_name"
+}
+
+if {! [gdb_version_check_xmethods]} {
+    unsupported "xmethods.exp"
+    return
+}
+
+# This can be used to keep the .exe around.  dg-test has an option for
+# this but there is no way to pass it through dg-runtest.
+global dg-interpreter-batch-mode
+set dg-interpreter-batch-mode 1
+
+global DEFAULT_CXXFLAGS
+global PCH_CXXFLAGS
+dg-runtest [lsort [glob $srcdir/$subdir/*.cc]] \
+  "" "$DEFAULT_CXXFLAGS $PCH_CXXFLAGS"
+
+if [info exists guality_gdb_name] {
+    unsetenv GUALITY_GDB_NAME
+}
+
+dg-finish