From 883964a75e8c6531f167391354f1a4d83d203988 Mon Sep 17 00:00:00 2001 From: Siva Chandra Date: Tue, 20 May 2014 06:53:04 -0700 Subject: Xmethod support in Python. * python/py-xmethods.c: New file. * python/py-objfile.c (objfile_object): New field 'xmethods'. (objfpy_dealloc): XDECREF on the new xmethods field. (objfpy_new, objfile_to_objfile_object): Initialize xmethods field. (objfpy_get_xmethods): New function. (objfile_getset): New entry 'xmethods'. * python/py-progspace.c (pspace_object): New field 'xmethods'. (pspy_dealloc): XDECREF on the new xmethods field. (pspy_new, pspace_to_pspace_object): Initialize xmethods field. (pspy_get_xmethods): New function. (pspace_getset): New entry 'xmethods'. * python/python-internal.h: Add declarations for new functions. * python/python.c (_initialize_python): Invoke gdbpy_initialize_xmethods. * python/lib/gdb/__init__.py (xmethods): New attribute. * python/lib/gdb/xmethod.py: New file. * python/lib/gdb/command/xmethods.py: New file. testuite/ * gdb.python/py-xmethods.cc: New testcase to test xmethods. * gdb.python/py-xmethods.exp: New tests to test xmethods. * gdb.python/py-xmethods.py: Python script supporting the new testcase and tests. --- gdb/testsuite/gdb.python/py-xmethods.cc | 170 ++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 gdb/testsuite/gdb.python/py-xmethods.cc (limited to 'gdb/testsuite/gdb.python/py-xmethods.cc') diff --git a/gdb/testsuite/gdb.python/py-xmethods.cc b/gdb/testsuite/gdb.python/py-xmethods.cc new file mode 100644 index 0000000..96637d8 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-xmethods.cc @@ -0,0 +1,170 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 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 . */ + +#include + +using namespace std; + +namespace dop +{ + +class A +{ +public: + int a; + int array [10]; + virtual ~A (); + int operator+ (const A &obj); + int operator- (const A &obj); + virtual int geta (void); +}; + +A::~A () { } + +int +A::operator+ (const A &obj) +{ + cout << "From CC :" << endl; + return a + obj.a; +} + +int +A::operator- (const A &obj) +{ + cout << "From CC :" << endl; + return a - obj.a; +} + +int +A::geta (void) +{ + cout << "From CC A::geta:" << endl; + return a; +} + +class B : public A +{ +public: + virtual int geta (void); +}; + +int +B::geta (void) +{ + cout << "From CC B::geta:" << endl; + return 2 * a; +} + +typedef B Bt; + +typedef Bt Btt; + +class E : public A +{ +public: + /* This class has a member named 'a', while the base class also has a + member named 'a'. When one invokes A::geta(), A::a should be + returned and not E::a as the 'geta' method is defined on class 'A'. + This class tests this aspect of debug methods. */ + int a; +}; + +template +class G +{ + public: + template + int size_diff (); + + template + int size_mul (); + + template + T mul(const T1 t1); + + public: + T t; +}; + +template +template +int +G::size_diff () +{ + cout << "From CC G<>::size_diff:" << endl; + return sizeof (T1) - sizeof (T); +} + +template +template +int +G::size_mul () +{ + cout << "From CC G<>::size_mul:" << endl; + return M * sizeof (T); +} + +template +template +T +G::mul (const T1 t1) +{ + cout << "From CC G<>::mul:" << endl; + return t1 * t; +} + +} // namespaxe dop + +using namespace dop; + +int main(void) +{ + A a1, a2; + a1.a = 5; + a2.a = 10; + + B b1; + b1.a = 30; + A *a_ptr = &b1; + + Bt bt; + bt.a = 40; + + Btt btt; + btt.a = -5; + + G g, *g_ptr; + g.t = 5; + g_ptr = &g; + + E e; + E &e_ref = e; + E *e_ptr = &e; + e.a = 1000; + e.A::a = 100; + + int diff = g.size_diff (); + int smul = g.size_mul<2> (); + int mul = g.mul (1.0); + + for (int i = 0; i < 10; i++) + { + a1.array[i] = a2.array[i] = i; + } + + return 0; /* Break here. */ +} -- cgit v1.1