aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog15
-rw-r--r--gdb/testsuite/gdb.python/python-template.cc30
-rw-r--r--gdb/testsuite/gdb.python/python-template.exp75
-rw-r--r--gdb/testsuite/gdb.python/python-value.c6
-rw-r--r--gdb/testsuite/gdb.python/python-value.exp28
5 files changed, 152 insertions, 2 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index ff1cfea..818b2f7 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,18 @@
+2009-05-27 Thiago Jung Bauermann <bauerman@br.ibm.com>
+ Tom Tromey <tromey@redhat.com>
+ Pedro Alves <pedro@codesourcery.com>
+ Paul Pluzhnikov <ppluzhnikov@google.com>
+
+ * gdb.python/python-template.exp: New file.
+ * gdb.python/python-template.cc: New file.
+ * gdb.python/python.exp (gdb_py_test_multiple): Add two objfile
+ tests.
+ * gdb.python/python-value.exp (py_objfile_tests): New proc.
+ Call it.
+ (test_value_after_death): New proc.
+ * gdb.python/python-value.c (PTR): New typedef.
+ (main): New variable 'x'.
+
2009-05-27 Tom Tromey <tromey@redhat.com>
* gdb.python/python.exp (gdb_py_test_multiple): Add two objfile
diff --git a/gdb/testsuite/gdb.python/python-template.cc b/gdb/testsuite/gdb.python/python-template.cc
new file mode 100644
index 0000000..bd6a212
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-template.cc
@@ -0,0 +1,30 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2008 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/>. */
+
+template <typename T>
+struct Foo {
+};
+
+#ifndef TYPE
+#define TYPE int
+#endif
+
+int main()
+{
+ Foo<TYPE> foo;
+ return 0; // break here
+}
diff --git a/gdb/testsuite/gdb.python/python-template.exp b/gdb/testsuite/gdb.python/python-template.exp
new file mode 100644
index 0000000..1ace5d6
--- /dev/null
+++ b/gdb/testsuite/gdb.python/python-template.exp
@@ -0,0 +1,75 @@
+# Copyright (C) 2008, 2009 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/>.
+
+# This file is part of the GDB testsuite. It tests the mechanism
+# exposing values to Python.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+set testfile "python-template"
+set srcfile ${testfile}.cc
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
+ {debug c++}] != "" } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
+}
+
+# Start with a fresh gdb.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_test_multiple "python print 23" "verify python support" {
+ -re "not supported.*$gdb_prompt $" {
+ unsupported "python support is disabled"
+ return -1
+ }
+ -re "$gdb_prompt $" {}
+}
+
+proc test_template_arg {type} {
+ global testfile srcdir subdir srcfile binfile
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+ executable \
+ [list debug c++ additional_flags="-DTYPE=$type"]] != "" } {
+ untested $type
+ return -1
+ }
+ gdb_load ${binfile}
+ if ![runto_main ] then {
+ perror "couldn't run to breakpoint"
+ return
+ }
+ # There is no executable code in main(), so we are where we want to be
+ gdb_test "print foo" ""
+ gdb_test "python foo = gdb.history(0)" ""
+
+ # Replace '*' with '\*' in regex.
+ regsub -all {\*} $type {\*} t
+ gdb_test "python print foo.type.template_argument(0)" $t $type
+}
+
+test_template_arg "const int"
+test_template_arg "volatile int"
+test_template_arg "const int &"
+test_template_arg "volatile int &"
+test_template_arg "volatile int * const"
+test_template_arg "volatile int * const *"
+test_template_arg "const int * volatile"
+test_template_arg "const int * volatile * const * volatile *"
diff --git a/gdb/testsuite/gdb.python/python-value.c b/gdb/testsuite/gdb.python/python-value.c
index 17e5c62..092c520 100644
--- a/gdb/testsuite/gdb.python/python-value.c
+++ b/gdb/testsuite/gdb.python/python-value.c
@@ -33,19 +33,21 @@ enum e
TWO = 2
};
+typedef struct s *PTR;
+
enum e evalue = TWO;
int
main (int argc, char *argv[])
{
+ char *cp = argv[0]; /* Prevent gcc from optimizing argv[] out. */
struct s s;
union u u;
+ PTR x = &s;
s.a = 3;
s.b = 5;
u.a = 7;
- argv[0][0] = 'a'; /* Just to avoid getting argv optimized out. */
-
return 0; /* break to inspect struct and union */
}
diff --git a/gdb/testsuite/gdb.python/python-value.exp b/gdb/testsuite/gdb.python/python-value.exp
index 93e9d89..20333f6 100644
--- a/gdb/testsuite/gdb.python/python-value.exp
+++ b/gdb/testsuite/gdb.python/python-value.exp
@@ -246,6 +246,33 @@ proc test_objfiles {} {
"pretty_printers attribute must be a list.*Error while executing Python code."
}
+proc test_value_after_death {} {
+ # Construct a type while the inferior is still running.
+ gdb_py_test_silent_cmd "python ptrtype = gdb.lookup_type('PTR')" \
+ "create PTR type" 1
+
+ # Kill the inferior and remove the symbols.
+ gdb_test "kill" "" "kill the inferior" \
+ "Kill the program being debugged. .y or n. $" \
+ "y"
+ gdb_test "file" "" "Discard the symbols" \
+ "Discard symbol table from.*y or n. $" \
+ "y"
+
+ # Now create a value using that type. Relies on arg0, created by
+ # test_value_in_inferior.
+ gdb_py_test_silent_cmd "python castval = arg0.cast(ptrtype.pointer())" \
+ "cast arg0 to PTR" 1
+
+ # Make sure the type is deleted.
+ gdb_py_test_silent_cmd "python ptrtype = None" \
+ "delete PTR type" 1
+
+ # Now see if the value's type is still valid.
+ gdb_test "python print castval.type" "PTR ." \
+ "print value's type"
+}
+
# Start with a fresh gdb.
gdb_exit
@@ -275,3 +302,4 @@ if ![runto_main] then {
}
test_value_in_inferior
+test_value_after_death