Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit 2f99e8f

Browse files
author
Yao Qi
committed
Change SIGINT handler for extension languages only when target terminal is ours
I see a timeout in gdb.base/random-signal.exp, Continuing.^M PASS: gdb.base/random-signal.exp: continue ^CPython Exception <type 'exceptions.KeyboardInterrupt'> <type exceptions.KeyboardInterrupt'>: ^M FAIL: gdb.base/random-signal.exp: stop with control-c (timeout) it can be reproduced by running random-signal.exp with native-gdbserver in a loop, like this, and the fail will be shown in about 20 runs, $ (set -e; while true; do make check RUNTESTFLAGS="--target_board=native-gdbserver random-signal.exp"; done) In the test, the program is being single-stepped for software watchpoint, and in each internal stop, python unwinder sniffer is used, #0 pyuw_sniffer (self=<optimised out>, this_frame=<optimised out>, cache_ptr=0xd554f8) at /home/yao/SourceCode/gnu/gdb/git/gdb/python/py-unwind.c:608 #1 0x00000000006a10ae in frame_unwind_try_unwinder (this_frame=this_frame@entry=0xd554e0, this_cache=this_cache@entry=0xd554f8, unwinder=0xecd540) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame-unwind.c:107 #2 0x00000000006a143f in frame_unwind_find_by_frame (this_frame=this_frame@entry=0xd554e0, this_cache=this_cache@entry=0xd554f8) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame-unwind.c:163 #3 0x000000000069dc6b in compute_frame_id (fi=0xd554e0) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:454 #4 get_prev_frame_if_no_cycle (this_frame=this_frame@entry=0xd55410) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1781 #5 0x000000000069fdb9 in get_prev_frame_always_1 (this_frame=0xd55410) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1955 #6 get_prev_frame_always (this_frame=this_frame@entry=0xd55410) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1971 #7 0x00000000006a04b1 in get_prev_frame (this_frame=this_frame@entry=0xd55410) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:2213 when GDB goes to python extension, or other language extension, the SIGINT handler is changed, and is restored when GDB leaves extension language. GDB only stays in extension language for a very short period in this case, but if ctrl-c is pressed at that moment, python extension will handle the SIGINT, and exceptions.KeyboardInterrupt is shown. Language extension is used in GDB side rather than inferior side, so GDB should only change SIGINT handler for extension language when the terminal is ours (not inferior's). This is what this patch does. With this patch applied, I run random-signal.exp in a loop for 18 hours, and no fail is shown. gdb: 2016-01-08 Yao Qi <[email protected]> * extension.c: Include target.h. (set_active_ext_lang): Only call install_gdb_sigint_handler, check_quit_flag, and set_quit_flag if target_terminal_is_ours returns false. (restore_active_ext_lang): Likewise. * target.c (target_terminal_is_ours): New function. * target.h (target_terminal_is_ours): Declare.
1 parent 5a0dd67 commit 2f99e8f

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

gdb/ChangeLog

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2016-01-08 Yao Qi <[email protected]>
2+
3+
* extension.c: Include target.h.
4+
(set_active_ext_lang): Only call install_gdb_sigint_handler,
5+
check_quit_flag, and set_quit_flag if target_terminal_is_ours
6+
returns false.
7+
(restore_active_ext_lang): Likewise.
8+
* target.c (target_terminal_is_ours): New function.
9+
* target.h (target_terminal_is_ours): Declare.
10+
111
2016-01-07 Maciej W. Rozycki <[email protected]>
212

313
* mips-tdep.c (mips_breakpoint_from_pc): Rename local `status'

gdb/extension.c

+30-21
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "defs.h"
2424
#include <signal.h>
25+
#include "target.h"
2526
#include "auto-load.h"
2627
#include "breakpoint.h"
2728
#include "event-top.h"
@@ -746,19 +747,24 @@ set_active_ext_lang (const struct extension_language_defn *now_active)
746747
= XCNEW (struct active_ext_lang_state);
747748

748749
previous->ext_lang = active_ext_lang;
750+
previous->sigint_handler.handler_saved = 0;
749751
active_ext_lang = now_active;
750752

751-
/* If the newly active extension language uses cooperative SIGINT handling
752-
then ensure GDB's SIGINT handler is installed. */
753-
if (now_active->language == EXT_LANG_GDB
754-
|| now_active->ops->check_quit_flag != NULL)
755-
install_gdb_sigint_handler (&previous->sigint_handler);
756-
757-
/* If there's a SIGINT recorded in the cooperative extension languages,
758-
move it to the new language, or save it in GDB's global flag if the newly
759-
active extension language doesn't use cooperative SIGINT handling. */
760-
if (check_quit_flag ())
761-
set_quit_flag ();
753+
if (target_terminal_is_ours ())
754+
{
755+
/* If the newly active extension language uses cooperative SIGINT
756+
handling then ensure GDB's SIGINT handler is installed. */
757+
if (now_active->language == EXT_LANG_GDB
758+
|| now_active->ops->check_quit_flag != NULL)
759+
install_gdb_sigint_handler (&previous->sigint_handler);
760+
761+
/* If there's a SIGINT recorded in the cooperative extension languages,
762+
move it to the new language, or save it in GDB's global flag if the
763+
newly active extension language doesn't use cooperative SIGINT
764+
handling. */
765+
if (check_quit_flag ())
766+
set_quit_flag ();
767+
}
762768

763769
return previous;
764770
}
@@ -772,16 +778,19 @@ restore_active_ext_lang (struct active_ext_lang_state *previous)
772778

773779
active_ext_lang = previous->ext_lang;
774780

775-
/* Restore the previous SIGINT handler if one was saved. */
776-
if (previous->sigint_handler.handler_saved)
777-
install_sigint_handler (&previous->sigint_handler);
778-
779-
/* If there's a SIGINT recorded in the cooperative extension languages,
780-
move it to the new language, or save it in GDB's global flag if the newly
781-
active extension language doesn't use cooperative SIGINT handling. */
782-
if (check_quit_flag ())
783-
set_quit_flag ();
784-
781+
if (target_terminal_is_ours ())
782+
{
783+
/* Restore the previous SIGINT handler if one was saved. */
784+
if (previous->sigint_handler.handler_saved)
785+
install_sigint_handler (&previous->sigint_handler);
786+
787+
/* If there's a SIGINT recorded in the cooperative extension languages,
788+
move it to the new language, or save it in GDB's global flag if the
789+
newly active extension language doesn't use cooperative SIGINT
790+
handling. */
791+
if (check_quit_flag ())
792+
set_quit_flag ();
793+
}
785794
xfree (previous);
786795
}
787796

gdb/target.c

+8
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ target_terminal_is_inferior (void)
466466

467467
/* See target.h. */
468468

469+
int
470+
target_terminal_is_ours (void)
471+
{
472+
return (terminal_state == terminal_is_ours);
473+
}
474+
475+
/* See target.h. */
476+
469477
void
470478
target_terminal_inferior (void)
471479
{

gdb/target.h

+4
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,10 @@ extern int target_remove_breakpoint (struct gdbarch *gdbarch,
15031503

15041504
extern int target_terminal_is_inferior (void);
15051505

1506+
/* Returns true if our terminal settings are in effect. */
1507+
1508+
extern int target_terminal_is_ours (void);
1509+
15061510
/* Initialize the terminal settings we record for the inferior,
15071511
before we actually run the inferior. */
15081512

0 commit comments

Comments
 (0)