From: Matt Rice <ratmice@gmail.com>
To: pmuldoon@redhat.com
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] python prompt additions at first prompt.
Date: Tue, 02 Aug 2011 17:59:00 -0000 [thread overview]
Message-ID: <CACTLOFqBuobvi0kWy0b_zd0JZZFB9=xQxcqwv9feZ3N-XNP4Ow@mail.gmail.com> (raw)
In-Reply-To: <m3sjpk2ncb.fsf@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1373 bytes --]
On Tue, Aug 2, 2011 at 2:07 AM, Phil Muldoon <pmuldoon@redhat.com> wrote:
> Matt Rice <ratmice@gmail.com> writes:
>
>> On Mon, Aug 1, 2011 at 7:13 AM, Phil Muldoon <pmuldoon@redhat.com> wrote:
>
>> Think it was the quoting of $gdb_prompt which had me foiled.
>>
>> 2011-08-01 Matt Rice <ratmice@gmail.com>
>>
>> * gdb.python/py-prompt.exp: New file.
>
> Thanks.
>
>> +++ b/gdb/testsuite/gdb.python/py-prompt.exp
>> @@ -0,0 +1,60 @@
>> +# Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
>> +
>
> This is a new file, so we just need 2011.
Oops,
> Also, the other prompt tests are in python.exp, so this standalone test
> is kind of an anomaly. What do you think about combining the python.exp
> prompt tests into this test file? If you think that is ok, then you can
> just submit another consolidation patch after this one has been approved
> and checked in.
sure don't mind at all,
with all the gdb invocations and global variables in this test
and python.exp being shared between many tests I didn't want to ugly it up.
> If there is a method to utilise a formal PASS/FAIL into the test I would
> prefer that.
I managed to finagle this into working with a modified gdb_start.
I stuck it in lib because i imagine it has to be for the baseboard override
to work, even though its only used by this test?
[-- Attachment #2: testsuite.diff --]
[-- Type: text/x-patch, Size: 5395 bytes --]
diff --git a/gdb/testsuite/gdb.python/py-prompt.exp b/gdb/testsuite/gdb.python/py-prompt.exp
new file mode 100644
index 0000000..1189bc3
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-prompt.exp
@@ -0,0 +1,75 @@
+# Copyright (C) 2011 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
+# for defining the prompt in Python.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+load_lib gdb-python.exp
+load_lib prompt.exp
+
+# Start with a fresh gdb.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
+gdb_exit
+
+global GDBFLAGS
+set saved_gdbflags $GDBFLAGS
+set GDBFLAGS [concat $GDBFLAGS " -ex \"set height 0\""]
+set GDBFLAGS [concat $GDBFLAGS " -ex \"set width 0\""]
+set GDBFLAGS [concat $GDBFLAGS " -ex \"python i = 0\""]
+set prompt_func "python def foo(x): global i; i += 1; return \'(Foo) \'"
+set GDBFLAGS [concat $GDBFLAGS " -ex \"$prompt_func\""]
+set GDBFLAGS [concat $GDBFLAGS " -ex \"python gdb.prompt_hook=foo\""]
+
+set tmp_gdbflags $GDBFLAGS
+set saved_gdb_prompt $gdb_prompt
+set gdb_prompt_fail "\[(\]gdb\[)\]"
+
+global gdb_prompt
+# Does not include the space at the end of the prompt.
+# gdb_test expects it not to be there.
+set gdb_prompt "\[(\]Foo\[)\]"
+
+set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing on\""]
+prompt_gdb_start
+gdb_test "python x = i; print gdb.execute(\"show prompt\", to_string = True)" \
+ ".*prompt is \"$gdb_prompt \".*" \
+ "show prompt gets the correct result"
+gdb_test "python print x, i" "1 2" \
+ "retrieving the prompt causes no extra prompt_hook calls"
+gdb_exit
+
+
+set GDBFLAGS [concat $tmp_gdbflags " -ex \"set editing off\""]
+prompt_gdb_start
+gdb_test "python x = i; print gdb.execute(\"show prompt\", to_string = True)" \
+ ".*prompt is \"$gdb_prompt \".*" \
+ "show prompt gets the correct result 2"
+gdb_test "python print x, i" "1 2" \
+ "retrieving the prompt causes no extra prompt_hook calls 2"
+gdb_exit
+
+set GDBFLAGS $saved_gdbflags
+set gdb_prompt $saved_gdb_prompt
+return 0
diff --git a/gdb/testsuite/lib/prompt.exp b/gdb/testsuite/lib/prompt.exp
new file mode 100644
index 0000000..84186cc
--- /dev/null
+++ b/gdb/testsuite/lib/prompt.exp
@@ -0,0 +1,86 @@
+# Copyright (C) 2011 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/>.
+
+# Specialized subroutines for launching gdb and testing the very first prompt.
+
+
+#
+# start gdb -- start gdb running, prompt procedure
+# this procedure differs from the default in that you must pass 'set height 0',
+# and 'set width 0', yourself in GDBFLAGS, and it has a gdb_prompt_fail variable,
+#
+# uses pass if it sees $gdb_prompt, and fail if it sees $gdb_prompt_fail.
+#
+proc default_prompt_gdb_start { } {
+ global verbose
+ global GDB
+ global INTERNAL_GDBFLAGS GDBFLAGS
+ global gdb_prompt
+ global gdb_prompt_fail
+ global timeout
+ global gdb_spawn_id;
+
+ gdb_stop_suppressing_tests;
+
+ verbose "Spawning $GDB $INTERNAL_GDBFLAGS $GDBFLAGS"
+
+ if [info exists gdb_spawn_id] {
+ return 0;
+ }
+
+ if ![is_remote host] {
+ if { [which $GDB] == 0 } then {
+ perror "$GDB does not exist."
+ exit 1
+ }
+ }
+ set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"];
+ if { $res < 0 || $res == "" } {
+ perror "Spawning $GDB failed."
+ return 1;
+ }
+ gdb_expect 360 {
+ -re "\[\r\n\]$gdb_prompt_fail $" {
+ fail "GDB initializing first prompt"
+ }
+ -re "\[\r\n\]$gdb_prompt $" {
+ pass "GDB initializing first prompt"
+ }
+ -re "$gdb_prompt $" {
+ perror "GDB never initialized."
+ return -1
+ }
+ -re "$gdb_prompt_fail $" {
+ perror "GDB never initialized."
+ return -1
+ }
+ timeout {
+ perror "(timeout) GDB never initialized after 10 seconds."
+ remote_close host;
+ return -1
+ }
+ }
+ set gdb_spawn_id -1;
+ return 0;
+}
+
+#
+# Overridable function. You can override this function in your
+# baseboard file.
+#
+proc prompt_gdb_start { } {
+ default_prompt_gdb_start
+}
+
next prev parent reply other threads:[~2011-08-02 17:59 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-30 22:20 Matt Rice
2011-08-01 9:51 ` Phil Muldoon
2011-08-01 14:08 ` Matt Rice
2011-08-01 14:13 ` Phil Muldoon
2011-08-01 17:44 ` Matt Rice
2011-08-02 9:07 ` Phil Muldoon
2011-08-02 17:59 ` Matt Rice [this message]
2011-08-02 20:37 ` Phil Muldoon
2011-08-03 18:08 ` Tom Tromey
2011-08-09 0:20 ` Matt Rice
2011-08-09 0:25 ` Matt Rice
2011-08-10 15:21 ` Tom Tromey
2011-08-11 12:03 ` Matt Rice
2011-08-12 13:10 ` Matt Rice
2011-08-12 14:44 ` Pedro Alves
2011-08-12 15:07 ` Matt Rice
2011-08-29 16:23 ` Matt Rice
2011-08-29 16:39 ` Pedro Alves
2011-09-02 14:31 ` Pedro Alves
2011-09-02 21:41 ` Matt Rice
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='CACTLOFqBuobvi0kWy0b_zd0JZZFB9=xQxcqwv9feZ3N-XNP4Ow@mail.gmail.com' \
--to=ratmice@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=pmuldoon@redhat.com \
/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