* [patch] [python] python/12686
@ 2011-04-20 13:50 Phil Muldoon
2011-04-20 19:32 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Phil Muldoon @ 2011-04-20 13:50 UTC (permalink / raw)
To: gdb-patches
Kevin Pouget noticed that when GDB called the Python 'stop' callback,
the terminal stilled belonged to the inferior. GDB intercepts the
signal generated from terminal input and it forces GDB into the
background. While this patch is simple, I would like feedback. I
believe the terminal is restored to the inferior when the inferior is
resumed (local tests seem to show this), but I am not totally sure. Is
acquiring the terminal the right thing to do here? I was trying to think
of a scenario where the Python method would need the inferior terminal,
but could not.
Comments?
Cheers,
Phil
--
2011-04-20 Phil Muldoon <pmuldoon@redhat.com>
PR python/12686
* python/py-breakpoint.c (gdbpy_should_stop): Acquire terminal
before executing Python code.
2011-04-20 Phil Muldoon <pmuldoon@redhat.com>
PR python/12686
* gdb.python/py-breakpoint.exp: Add terminal input 'stop' method
test.
--
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 0c21bfc..3ee23be 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -729,7 +729,13 @@ gdbpy_should_stop (struct breakpoint_object *bp_obj)
if (PyObject_HasAttrString (py_bp, stop_func))
{
- PyObject *result = PyObject_CallMethod (py_bp, stop_func, NULL);
+ PyObject *result;
+
+ /* GDB acquires the terminal from the inferior before the
+ call. The Python 'stop' method might need to do
+ input/output. */
+ terminal_ours ();
+ result = PyObject_CallMethod (py_bp, stop_func, NULL);
if (result)
{
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index f0a83f1..d46a37c 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -237,6 +237,15 @@ gdb_py_test_multiple "Sub-class a third breakpoint" \
" count = 0" "" \
"end" ""
+gdb_py_test_multiple "Breakpoint that asks for input" \
+ "python" "" \
+ "class ask_bp_input (gdb.Breakpoint):" "" \
+ " def stop (self):" "" \
+ " inp = raw_input(\"Input\")" "" \
+ " print inp" "" \
+ " return True" "" \
+ "end" ""
+
set bp_location2 [gdb_get_line_number "Break at multiply."]
set end_location [gdb_get_line_number "Break at end."]
gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" "Set breakpoint" 0
@@ -293,3 +302,39 @@ gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOIN
gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" "Test watchpoint write"
gdb_test "python print never_eval_bp1.count" "0" \
"Check that this unrelated breakpoints eval function was never called."
+
+# Test breakpoints that require user input.
+# Start with a fresh gdb.
+delete_breakpoints
+clean_restart ${testfile}
+
+gdb_py_test_multiple "Breakpoint that asks for input" \
+ "python" "" \
+ "class ask_bp_input (gdb.Breakpoint):" "" \
+ " def stop (self):" "" \
+ " inp = raw_input(\"Input? \")" "" \
+ " print \"Output =\", inp" "" \
+ " return True" "" \
+ "end" ""
+
+set input_bp [gdb_get_line_number "Break at multiply."]
+gdb_py_test_silent_cmd "python np_input = ask_bp_input(\"$input_bp\")" \
+ "Set breakpoint" 0
+send_gdb "run\n"
+gdb_expect {
+ -re "Input\?.*" {
+ pass "Input prompt has appeard and awaiting for input."
+ }
+ timeout {
+ fail "Input prompt has not appearead."
+ }
+}
+send_gdb "123\n"
+gdb_expect {
+ -re "Output = 123.*Breakpoint.*main.*py-breakpoint.*" {
+ pass "Output recieved from input is correct and printed."
+ }
+ timeout {
+ fail "Output not recieved from input prompt."
+ }
+}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] [python] python/12686
2011-04-20 13:50 [patch] [python] python/12686 Phil Muldoon
@ 2011-04-20 19:32 ` Tom Tromey
2011-04-20 20:10 ` Kevin Pouget
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2011-04-20 19:32 UTC (permalink / raw)
To: pmuldoon; +Cc: gdb-patches
>>>>> "Phil" == Phil Muldoon <pmuldoon@redhat.com> writes:
Phil> Kevin Pouget noticed that when GDB called the Python 'stop' callback,
Phil> the terminal stilled belonged to the inferior. GDB intercepts the
Phil> signal generated from terminal input and it forces GDB into the
Phil> background. While this patch is simple, I would like feedback. I
Phil> believe the terminal is restored to the inferior when the inferior is
Phil> resumed (local tests seem to show this), but I am not totally sure. Is
Phil> acquiring the terminal the right thing to do here? I was trying to think
Phil> of a scenario where the Python method would need the inferior terminal,
Phil> but could not.
Phil> Comments?
I don't think we want to do this here.
I'm not really sure of the implications, but it isn't something that
most implementations of the `stop' method are going to want.
If we really need to, we can provide some explicit functions to
manipulate this state from Python. TBH I think asking the user
questions here is weird.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] [python] python/12686
2011-04-20 19:32 ` Tom Tromey
@ 2011-04-20 20:10 ` Kevin Pouget
2011-04-25 19:29 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Kevin Pouget @ 2011-04-20 20:10 UTC (permalink / raw)
To: Tom Tromey; +Cc: pmuldoon, gdb-patches
> TBH I think asking the user questions here is weird.
I'm not sure about the right way to do, I haven't had time to consider
your suggestion on the main mailing list, but if you consider the
situation where you want to ask the user (from Python) if s/he wants
to stop the inferior.
Currently, one way would be to do it here, the other would be in the
"stop" event handler, with `gdb.execute("continue")', but I don't
really like this solution, being under a Python callstack during the
execution seems a bit strange, doesn't it ?
Cordially,
Kevin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] [python] python/12686
2011-04-20 20:10 ` Kevin Pouget
@ 2011-04-25 19:29 ` Tom Tromey
2011-04-28 13:40 ` Kevin Pouget
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2011-04-25 19:29 UTC (permalink / raw)
To: Kevin Pouget; +Cc: pmuldoon, gdb-patches
>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:
Tom> TBH I think asking the user questions here is weird.
Kevin> I'm not sure about the right way to do, I haven't had time to consider
Kevin> your suggestion on the main mailing list, but if you consider the
Kevin> situation where you want to ask the user (from Python) if s/he wants
Kevin> to stop the inferior.
I would suggest simply not asking.
Kevin> Currently, one way would be to do it here, the other would be in the
Kevin> "stop" event handler, with `gdb.execute("continue")', but I don't
Kevin> really like this solution, being under a Python callstack during the
Kevin> execution seems a bit strange, doesn't it ?
Yeah, if you are committed to asking, then I agree about the placement
of the query.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] [python] python/12686
2011-04-25 19:29 ` Tom Tromey
@ 2011-04-28 13:40 ` Kevin Pouget
0 siblings, 0 replies; 5+ messages in thread
From: Kevin Pouget @ 2011-04-28 13:40 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey, pmuldoon
one thing I just noticed, python debugging ("import pdb ;
pdb.set_trace()") faces the same SIGTTIN problem ...
On Mon, Apr 25, 2011 at 3:28 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:
>
> Tom> TBH I think asking the user questions here is weird.
>
> Kevin> I'm not sure about the right way to do, I haven't had time to consider
> Kevin> your suggestion on the main mailing list, but if you consider the
> Kevin> situation where you want to ask the user (from Python) if s/he wants
> Kevin> to stop the inferior.
>
> I would suggest simply not asking.
>
> Kevin> Currently, one way would be to do it here, the other would be in the
> Kevin> "stop" event handler, with `gdb.execute("continue")', but I don't
> Kevin> really like this solution, being under a Python callstack during the
> Kevin> execution seems a bit strange, doesn't it ?
>
> Yeah, if you are committed to asking, then I agree about the placement
> of the query.
>
> Tom
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-04-28 13:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-20 13:50 [patch] [python] python/12686 Phil Muldoon
2011-04-20 19:32 ` Tom Tromey
2011-04-20 20:10 ` Kevin Pouget
2011-04-25 19:29 ` Tom Tromey
2011-04-28 13:40 ` Kevin Pouget
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox