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

Commit de97996

Browse files
committed
New vCtrlC packet, non-stop mode equivalent of \003
There's currently no non-stop equivalent of the all-stop ^C (\003) "packet" that GDB sends when a ctrl-c is pressed while a foreground command is active. There's vCont;t, but that's defined to cause a "signal 0" stop. This fixes many tests that type ^C, when testing with extended-remote with "maint set target-non-stop on". E.g.: Continuing. talk to me baby PASS: gdb.base/interrupt.exp: process is alive a a PASS: gdb.base/interrupt.exp: child process ate our char ^C [Thread 22730.22730] #1 stopped. 0x0000003615ee6650 in __read_nocancel () at ../sysdeps/unix/syscall-template.S:81 81 T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS) (gdb) FAIL: gdb.base/interrupt.exp: send_gdb control C p func1 () gdb/ 2015-11-30 Pedro Alves <[email protected]> * NEWS (New remote packets): Mention vCtrlC. * remote.c (PACKET_vCtrlC): New enum value. (async_remote_interrupt): Call target_interrupt instead of target_stop. (remote_interrupt_as): Remove 'ptid' parameter. (remote_interrupt_ns): New function. (remote_stop): Adjust. (remote_interrupt): If the target is in non-stop mode, try interrupting with vCtrlC. (initialize_remote): Install set remote ctrl-c packet. gdb/doc/ 2015-11-30 Pedro Alves <[email protected]> * gdb.texinfo (Bootstrapping): Add "interrupting remote targets" anchor. (Packets): Document vCtrlC. gdb/gdbserver/ 2015-11-30 Pedro Alves <[email protected]> * server.c (handle_v_requests): Handle vCtrlC.
1 parent 799a2ab commit de97996

File tree

7 files changed

+122
-11
lines changed

7 files changed

+122
-11
lines changed

gdb/ChangeLog

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2015-11-30 Pedro Alves <[email protected]>
2+
3+
* NEWS (New remote packets): Mention vCtrlC.
4+
* remote.c (PACKET_vCtrlC): New enum value.
5+
(async_remote_interrupt): Call target_interrupt instead of
6+
target_stop.
7+
(remote_interrupt_as): Remove 'ptid' parameter.
8+
(remote_interrupt_ns): New function.
9+
(remote_stop): Adjust.
10+
(remote_interrupt): If the target is in non-stop mode, try
11+
interrupting with vCtrlC.
12+
(initialize_remote): Install set remote ctrl-c packet.
13+
114
2015-11-30 Pedro Alves <[email protected]>
215

316
* remote.c (struct remote_state) <remote_watch_data_address,

gdb/NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ exec-events feature in qSupported
8484
response can contain the corresponding 'stubfeature'. Set and
8585
show commands can be used to display whether these features are enabled.
8686

87+
vCtrlC
88+
Equivalent to interrupting with the ^C character, but works in
89+
non-stop mode.
90+
8791
* Extended-remote exec events
8892

8993
** GDB now has support for exec events on extended-remote Linux targets.

gdb/doc/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2015-11-30 Pedro Alves <[email protected]>
2+
3+
* gdb.texinfo (Bootstrapping): Add "interrupting remote targets"
4+
anchor.
5+
(Packets): Document vCtrlC.
6+
17
2015-11-26 Simon Marchi <[email protected]>
28

39
* gdb.texinfo (Thread List Format): Mention thread names.

gdb/doc/gdb.texinfo

+30-4
Original file line numberDiff line numberDiff line change
@@ -35090,6 +35090,24 @@ command in the @samp{vCont} packet.
3509035090
The @samp{vCont} packet is not supported.
3509135091
@end table
3509235092

35093+
@anchor{vCtrlC packet}
35094+
@item vCtrlC
35095+
@cindex @samp{vCtrlC} packet
35096+
Interrupt remote target as if a control-C was pressed on the remote
35097+
terminal. This is the equivalent to reacting to the @code{^C}
35098+
(@samp{\003}, the control-C character) character in all-stop mode
35099+
while the target is running, except this works in non-stop mode.
35100+
@xref{interrupting remote targets}, for more info on the all-stop
35101+
variant.
35102+
35103+
Reply:
35104+
@table @samp
35105+
@item E @var{nn}
35106+
for an error
35107+
@item OK
35108+
for success
35109+
@end table
35110+
3509335111
@item vFile:@var{operation}:@var{parameter}@dots{}
3509435112
@cindex @samp{vFile} packet
3509535113
Perform a file operation on the target system. For details,
@@ -37857,11 +37875,12 @@ operation.
3785737875
@node Interrupts
3785837876
@section Interrupts
3785937877
@cindex interrupts (remote protocol)
37878+
@anchor{interrupting remote targets}
3786037879

37861-
When a program on the remote target is running, @value{GDBN} may
37862-
attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
37863-
a @code{BREAK} followed by @code{g},
37864-
control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
37880+
In all-stop mode, when a program on the remote target is running,
37881+
@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
37882+
@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
37883+
is specified via @value{GDBN}'s @samp{interrupt-sequence}.
3786537884

3786637885
The precise meaning of @code{BREAK} is defined by the transport
3786737886
mechanism and may, in fact, be undefined. @value{GDBN} does not
@@ -37882,6 +37901,13 @@ and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
3788237901
When Linux kernel receives this sequence from serial port,
3788337902
it stops execution and connects to gdb.
3788437903

37904+
In non-stop mode, because packet resumptions are asynchronous
37905+
(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
37906+
command to the remote stub, even when the target is running. For that
37907+
reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
37908+
packet}) with the usual packet framing instead of the single byte
37909+
@code{0x03}.
37910+
3788537911
Stubs are not required to recognize these interrupt mechanisms and the
3788637912
precise meaning associated with receipt of the interrupt is
3788737913
implementation defined. If the target supports debugging of multiple

gdb/gdbserver/ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2015-11-30 Pedro Alves <[email protected]>
2+
3+
* server.c (handle_v_requests): Handle vCtrlC.
4+
15
2015-11-30 Pedro Alves <[email protected]>
26

37
* gdbthread.h (find_any_thread_of_pid): Declare.

gdb/gdbserver/server.c

+7
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,13 @@ handle_v_requests (char *own_buf, int packet_len, int *new_packet_len)
28612861
{
28622862
if (!disable_packet_vCont)
28632863
{
2864+
if (strcmp (own_buf, "vCtrlC") == 0)
2865+
{
2866+
(*the_target->request_interrupt) ();
2867+
write_ok (own_buf);
2868+
return;
2869+
}
2870+
28642871
if (startswith (own_buf, "vCont;"))
28652872
{
28662873
require_running (own_buf);

gdb/remote.c

+58-7
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,9 @@ enum {
14801480
/* Support for query supported vCont actions. */
14811481
PACKET_vContSupported,
14821482

1483+
/* Support remote CTRL-C. */
1484+
PACKET_vCtrlC,
1485+
14831486
PACKET_MAX
14841487
};
14851488

@@ -5581,7 +5584,7 @@ async_remote_interrupt (gdb_client_data arg)
55815584
if (remote_debug)
55825585
fprintf_unfiltered (gdb_stdlog, "async_remote_interrupt called\n");
55835586

5584-
target_stop (inferior_ptid);
5587+
target_interrupt (inferior_ptid);
55855588
}
55865589

55875590
/* Perform interrupt, if the first attempt did not succeed. Just give
@@ -5688,7 +5691,7 @@ remote_stop_ns (ptid_t ptid)
56885691
process reports the interrupt. */
56895692

56905693
static void
5691-
remote_interrupt_as (ptid_t ptid)
5694+
remote_interrupt_as (void)
56925695
{
56935696
struct remote_state *rs = get_remote_state ();
56945697

@@ -5704,6 +5707,38 @@ remote_interrupt_as (ptid_t ptid)
57045707
send_interrupt_sequence ();
57055708
}
57065709

5710+
/* Non-stop version of target_interrupt. Uses `vCtrlC' to interrupt
5711+
the remote target. It is undefined which thread of which process
5712+
reports the interrupt. Returns true if the packet is supported by
5713+
the server, false otherwise. */
5714+
5715+
static int
5716+
remote_interrupt_ns (void)
5717+
{
5718+
struct remote_state *rs = get_remote_state ();
5719+
char *p = rs->buf;
5720+
char *endp = rs->buf + get_remote_packet_size ();
5721+
5722+
xsnprintf (p, endp - p, "vCtrlC");
5723+
5724+
/* In non-stop, we get an immediate OK reply. The stop reply will
5725+
come in asynchronously by notification. */
5726+
putpkt (rs->buf);
5727+
getpkt (&rs->buf, &rs->buf_size, 0);
5728+
5729+
switch (packet_ok (rs->buf, &remote_protocol_packets[PACKET_vCtrlC]))
5730+
{
5731+
case PACKET_OK:
5732+
break;
5733+
case PACKET_UNKNOWN:
5734+
return 0;
5735+
case PACKET_ERROR:
5736+
error (_("Interrupting target failed: %s"), rs->buf);
5737+
}
5738+
5739+
return 1;
5740+
}
5741+
57075742
/* Implement the to_stop function for the remote targets. */
57085743

57095744
static void
@@ -5718,7 +5753,7 @@ remote_stop (struct target_ops *self, ptid_t ptid)
57185753
{
57195754
/* We don't currently have a way to transparently pause the
57205755
remote target in all-stop mode. Interrupt it instead. */
5721-
remote_interrupt_as (ptid);
5756+
remote_interrupt_as ();
57225757
}
57235758
}
57245759

@@ -5730,14 +5765,27 @@ remote_interrupt (struct target_ops *self, ptid_t ptid)
57305765
if (remote_debug)
57315766
fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
57325767

5733-
if (target_is_non_stop_p ())
5768+
if (non_stop)
57345769
{
5735-
/* We don't currently have a way to ^C the remote target in
5736-
non-stop mode. Stop it (with no signal) instead. */
5770+
/* In non-stop mode, we always stop with no signal instead. */
57375771
remote_stop_ns (ptid);
57385772
}
57395773
else
5740-
remote_interrupt_as (ptid);
5774+
{
5775+
/* In all-stop, we emulate ^C-ing the remote target's
5776+
terminal. */
5777+
if (target_is_non_stop_p ())
5778+
{
5779+
if (!remote_interrupt_ns ())
5780+
{
5781+
/* No support for ^C-ing the remote target. Stop it
5782+
(with no signal) instead. */
5783+
remote_stop_ns (ptid);
5784+
}
5785+
}
5786+
else
5787+
remote_interrupt_as ();
5788+
}
57415789
}
57425790

57435791
/* Ask the user what to do when an interrupt is received. */
@@ -13643,6 +13691,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
1364313691
add_packet_config_cmd (&remote_protocol_packets[PACKET_exec_event_feature],
1364413692
"exec-event-feature", "exec-event-feature", 0);
1364513693

13694+
add_packet_config_cmd (&remote_protocol_packets[PACKET_vCtrlC],
13695+
"vCtrlC", "ctrl-c", 0);
13696+
1364613697
/* Assert that we've registered "set remote foo-packet" commands
1364713698
for all packet configs. */
1364813699
{

0 commit comments

Comments
 (0)