+ rs->buf[0] = 0;
+ if (remote_protocol_packets[PACKET_qSupported].support != PACKET_DISABLE)
+ {
+ putpkt ("qSupported");
+ getpkt (&rs->buf, &rs->buf_size, 0);
+
+ /* If an error occured, warn, but do not return - just reset the
+ buffer to empty and go on to disable features. */
+ if (packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSupported])
+ == PACKET_ERROR)
+ {
+ warning (_("Remote failure reply: %s"), rs->buf);
+ rs->buf[0] = 0;
+ }
+ }
+
+ memset (seen, 0, sizeof (seen));
+
+ next = rs->buf;
+ while (*next)
+ {
+ enum packet_support is_supported;
+ char *p, *end, *name_end, *value;
+
+ /* First separate out this item from the rest of the packet. If
+ there's another item after this, we overwrite the separator
+ (terminated strings are much easier to work with). */
+ p = next;
+ end = strchr (p, ';');
+ if (end == NULL)
+ {
+ end = p + strlen (p);
+ next = end;
+ }
+ else
+ {
+ if (end == p)
+ {
+ warning (_("empty item in \"qSupported\" response"));
+ continue;
+ }
+
+ *end = '\0';
+ next = end + 1;
+ }
+
+ name_end = strchr (p, '=');
+ if (name_end)
+ {
+ /* This is a name=value entry. */
+ is_supported = PACKET_ENABLE;
+ value = name_end + 1;
+ *name_end = '\0';
+ }
+ else
+ {
+ value = NULL;
+ switch (end[-1])
+ {
+ case '+':
+ is_supported = PACKET_ENABLE;
+ break;
+
+ case '-':
+ is_supported = PACKET_DISABLE;
+ break;
+
+ case '?':
+ is_supported = PACKET_SUPPORT_UNKNOWN;
+ break;
+
+ default:
+ warning (_("unrecognized item \"%s\" in \"qSupported\" response"), p);
+ continue;
+ }
+ end[-1] = '\0';
+ }
+
+ for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
+ if (strcmp (remote_protocol_features[i].name, p) == 0)
+ {
+ const struct protocol_feature *feature;
+
+ seen[i] = 1;
+ feature = &remote_protocol_features[i];
+ feature->func (feature, is_supported, value);
+ break;
+ }
+ }
+
+ /* If we increased the packet size, make sure to increase the global
+ buffer size also. We delay this until after parsing the entire
+ qSupported packet, because this is the same buffer we were
+ parsing. */
+ if (rs->buf_size < rs->explicit_packet_size)
+ {
+ rs->buf_size = rs->explicit_packet_size;
+ rs->buf = xrealloc (rs->buf, rs->buf_size);
+ }
+
+ /* Handle the defaults for unmentioned features. */
+ for (i = 0; i < ARRAY_SIZE (remote_protocol_features); i++)
+ if (!seen[i])
+ {
+ const struct protocol_feature *feature;
+
+ feature = &remote_protocol_features[i];
+ feature->func (feature, feature->default_support, NULL);
+ }
+}
+
+
+static void
+remote_open_1 (char *name, int from_tty, struct target_ops *target,
+ int extended_p, int async_p)
+{
+ struct remote_state *rs = get_remote_state ();
+ if (name == 0)
+ error (_("To open a remote debug connection, you need to specify what\n"
+ "serial device is attached to the remote system\n"
+ "(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.)."));
+
+ /* See FIXME above. */
+ if (!async_p)
+ wait_forever_enabled_p = 1;
+
+ target_preopen (from_tty);
+
+ unpush_target (target);
+
+ remote_fileio_reset ();
+ reopen_exec_file ();
+ reread_symbols ();
+
+ remote_desc = remote_serial_open (name);
+ if (!remote_desc)
+ perror_with_name (name);
+
+ if (baud_rate != -1)
+ {
+ if (serial_setbaudrate (remote_desc, baud_rate))
+ {
+ /* The requested speed could not be set. Error out to
+ top level after closing remote_desc. Take care to
+ set remote_desc to NULL to avoid closing remote_desc
+ more than once. */
+ serial_close (remote_desc);
+ remote_desc = NULL;
+ perror_with_name (name);
+ }
+ }
+
+ serial_raw (remote_desc);
+
+ /* If there is something sitting in the buffer we might take it as a
+ response to a command, which would be bad. */
+ serial_flush_input (remote_desc);
+
+ if (from_tty)
+ {
+ puts_filtered ("Remote debugging using ");
+ puts_filtered (name);
+ puts_filtered ("\n");
+ }
+ push_target (target); /* Switch to using remote target now. */
+
+ /* Reset the target state; these things will be queried either by
+ remote_query_supported or as they are needed. */
+ init_all_packet_configs ();
+ rs->explicit_packet_size = 0;
+
+ general_thread = -2;
+ continue_thread = -2;
+
+ /* Probe for ability to use "ThreadInfo" query, as required. */
+ use_threadinfo_query = 1;
+ use_threadextra_query = 1;
+
+ /* The first packet we send to the target is the optional "supported
+ packets" request. If the target can answer this, it will tell us
+ which later probes to skip. */
+ remote_query_supported ();
+
+ /* Without this, some commands which require an active target (such
+ as kill) won't work. This variable serves (at least) double duty
+ as both the pid of the target process (if it has such), and as a
+ flag indicating that a target is active. These functions should
+ be split out into seperate variables, especially since GDB will
+ someday have a notion of debugging several processes. */
+
+ inferior_ptid = pid_to_ptid (MAGIC_NULL_PID);