From 89245bc05692aaa107fa2884c032da21682edc72 Mon Sep 17 00:00:00 2001 From: Don Breazeal Date: Tue, 12 May 2015 09:52:41 -0700 Subject: Identify remote fork event support This patch implements a mechanism for GDB to determine whether fork events are supported in gdbserver. This is a preparatory patch for remote fork and exec event support. Two new RSP packets are defined to represent fork and vfork event support. These packets are used just like PACKET_multiprocess_feature to denote whether the corresponding event is supported. GDB sends fork-events+ and vfork-events+ to gdbserver to inquire about fork event support. If the response enables these packets, then GDB knows that gdbserver supports the corresponding events and will enable them. Target functions used to query for support are included along with each new packet. In order for gdbserver to know whether the events are supported at the point where the qSupported packet arrives, the code in nat/linux-ptrace.c had to be reorganized. Previously it would test for fork/exec event support, then enable the events using the pid of the inferior. When the qSupported packet arrives there may not be an inferior. So the mechanism was split into two parts: a function that checks whether the events are supported, called when gdbserver starts up, and another that enables the events when the inferior stops for the first time. Another gdbserver change was to add some global variables similar to multi_process, one per new packet. These are used to control whether the corresponding fork events are enabled. If GDB does not inquire about the event support in the qSupported packet, then gdbserver will not set these "report the event" flags. If the flags are not set, the events are ignored like they were in the past. Thus, gdbserver will never send fork event notification to an older GDB that doesn't recognize fork events. Tested on Ubuntu x64, native/remote/extended-remote, and as part of subsequent patches in the series. gdb/gdbserver/ChangeLog: * linux-low.c (linux_supports_fork_events): New function. (linux_supports_vfork_events): New function. (linux_target_ops): Initialize new structure members. (initialize_low): Call linux_check_ptrace_features. * lynx-low.c (lynx_target_ops): Initialize new structure members. * server.c (report_fork_events, report_vfork_events): New global flags. (handle_query): Add new features to qSupported packet and response. (captured_main): Initialize new global variables. * target.h (struct target_ops) : New member. : New member. (target_supports_fork_events): New macro. (target_supports_vfork_events): New macro. * win32-low.c (win32_target_ops): Initialize new structure members. gdb/ChangeLog: * nat/linux-ptrace.c (linux_check_ptrace_features): Change from static to extern. * nat/linux-ptrace.h (linux_check_ptrace_features): Declare. * remote.c (anonymous enum): : New enumeration constants. (remote_protocol_features): Add table entries for new packets. (remote_query_supported): Add new feature queries to qSupported packet. (_initialize_remote): Exempt new packets from the requirement to have 'set remote' commands. --- gdb/remote.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gdb/remote.c') diff --git a/gdb/remote.c b/gdb/remote.c index 02c8371..6dae920 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1342,6 +1342,12 @@ enum { /* Support for hwbreak+ feature. */ PACKET_hwbreak_feature, + /* Support for fork events. */ + PACKET_fork_event_feature, + + /* Support for vfork events. */ + PACKET_vfork_event_feature, + PACKET_MAX }; @@ -4051,6 +4057,10 @@ static const struct protocol_feature remote_protocol_features[] = { PACKET_Qbtrace_conf_bts_size }, { "swbreak", PACKET_DISABLE, remote_supported_packet, PACKET_swbreak_feature }, { "hwbreak", PACKET_DISABLE, remote_supported_packet, PACKET_hwbreak_feature }, + { "fork-events", PACKET_DISABLE, remote_supported_packet, + PACKET_fork_event_feature }, + { "vfork-events", PACKET_DISABLE, remote_supported_packet, + PACKET_vfork_event_feature }, }; static char *remote_support_xml; @@ -4129,6 +4139,16 @@ remote_query_supported (void) q = remote_query_supported_append (q, "qRelocInsn+"); + if (rs->extended) + { + if (packet_set_cmd_state (PACKET_fork_event_feature) + != AUTO_BOOLEAN_FALSE) + q = remote_query_supported_append (q, "fork-events+"); + if (packet_set_cmd_state (PACKET_vfork_event_feature) + != AUTO_BOOLEAN_FALSE) + q = remote_query_supported_append (q, "vfork-events+"); + } + q = reconcat (q, "qSupported:", q, (char *) NULL); putpkt (q); @@ -12434,6 +12454,12 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL, add_packet_config_cmd (&remote_protocol_packets[PACKET_hwbreak_feature], "hwbreak-feature", "hwbreak-feature", 0); + add_packet_config_cmd (&remote_protocol_packets[PACKET_fork_event_feature], + "fork-event-feature", "fork-event-feature", 0); + + add_packet_config_cmd (&remote_protocol_packets[PACKET_vfork_event_feature], + "vfork-event-feature", "vfork-event-feature", 0); + /* Assert that we've registered "set remote foo-packet" commands for all packet configs. */ { -- cgit v1.1