From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Cc: Kevin Buettner <kevinb@redhat.com>
Subject: [PATCH 3/3] Tests for Python -P commandline support
Date: Sun, 21 Jul 2019 23:54:00 -0000 [thread overview]
Message-ID: <20190721235427.21893-4-kevinb@redhat.com> (raw)
In-Reply-To: <20190721235427.21893-1-kevinb@redhat.com>
gdb/testsuite/ChangeLog:
* gdb.python/py-script.c: New file.
* gdb.python/py-script.exp: New file.
* gdb.python/py-script.py: New file.
---
gdb/testsuite/gdb.python/py-script.c | 27 ++++++++++++++
gdb/testsuite/gdb.python/py-script.exp | 51 ++++++++++++++++++++++++++
gdb/testsuite/gdb.python/py-script.py | 25 +++++++++++++
3 files changed, 103 insertions(+)
create mode 100644 gdb/testsuite/gdb.python/py-script.c
create mode 100644 gdb/testsuite/gdb.python/py-script.exp
create mode 100644 gdb/testsuite/gdb.python/py-script.py
diff --git a/gdb/testsuite/gdb.python/py-script.c b/gdb/testsuite/gdb.python/py-script.c
new file mode 100644
index 0000000000..bff3a5edf5
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-script.c
@@ -0,0 +1,27 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2019 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 program is intended to be started outside of gdb, and then
+ attached to by gdb. It loops for a while, but not forever. */
+
+#include <unistd.h>
+
+int
+main ()
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.python/py-script.exp b/gdb/testsuite/gdb.python/py-script.exp
new file mode 100644
index 0000000000..fc5b87cb34
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-script.exp
@@ -0,0 +1,51 @@
+# Copyright (C) 2019 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 loading
+# and execution of scripts specified on the GDB command line.
+
+load_lib gdb-python.exp
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
+ return -1
+}
+
+set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
+save_vars { GDBFLAGS } {
+ append GDBFLAGS " -P $pyfile"
+ clean_restart ${binfile}
+}
+
+if ![runto_main] then {
+ perror "couldn't run to breakpoint"
+ continue
+}
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+
+gdb_test "python print(gdb.script_var1)" "script var 1"
+gdb_test "python print(gdb.script_var2)" "script var 2"
+
+save_vars { GDBFLAGS } {
+ append GDBFLAGS " -P $pyfile first_arg second_arg third_arg"
+ clean_restart ${binfile}
+}
+
+gdb_test "python print(gdb.script_args\[0\])" "first_arg"
+gdb_test "python print(gdb.script_args\[1\])" "second_arg"
+gdb_test "python print(gdb.script_args\[2\])" "third_arg"
diff --git a/gdb/testsuite/gdb.python/py-script.py b/gdb/testsuite/gdb.python/py-script.py
new file mode 100644
index 0000000000..4bbd5ba593
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-script.py
@@ -0,0 +1,25 @@
+# Copyright (C) 2019 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 loading
+# and execution of a Python script specified on the GDB command line.
+
+import gdb
+import sys
+
+gdb.script_var1 = "script var 1"
+gdb.script_var2 = "script var 2"
+
+gdb.script_args = list(sys.argv)
--
2.21.0
next prev parent reply other threads:[~2019-07-21 23:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-21 23:54 [PATCH 0/3] Add -P command line switch for executing Python scripts Kevin Buettner
2019-07-21 23:54 ` Kevin Buettner [this message]
2019-07-21 23:54 ` [PATCH 2/3] " Kevin Buettner
2019-07-23 2:47 ` Simon Marchi
2019-07-23 20:25 ` Tom Tromey
2019-07-27 20:47 ` Kevin Buettner
2019-08-21 16:39 ` Pedro Alves
2019-07-21 23:54 ` [PATCH 1/3] Documentation for Python -P commandline support Kevin Buettner
2019-07-22 14:42 ` Eli Zaretskii
2019-07-22 16:04 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190721235427.21893-4-kevinb@redhat.com \
--to=kevinb@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox