diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 174d63e5b1..75d0e7949d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2008-10-09 Pedro Alves + Daniel Jacobowitz + + * remote.c (remote_open_1): Move acknowledging any pending ack, + querying supported features, activating noack mode, finding the + target description, enabling extended remote, and checking remote + symbols from here ... + (remote_start_remote): ... to here. + (remote_open_1): Don't pop the target if it is already gone. + * target.c (unpush_target): Check for the dummy target. + 2008-10-09 Pedro Alves * ser-mingw.c: Include "command.h". diff --git a/gdb/remote.c b/gdb/remote.c index f648c36e07..aa754d2d99 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -211,6 +211,10 @@ static void show_remote_protocol_packet_cmd (struct ui_file *file, static char *write_ptid (char *buf, const char *endbuf, ptid_t ptid); static ptid_t read_ptid (char *buf, char **obuf); +static void remote_query_supported (void); + +static void remote_check_symbols (struct objfile *objfile); + void _initialize_remote (void); /* For "remote". */ @@ -2375,12 +2379,50 @@ struct start_remote_args static void remote_start_remote (struct ui_out *uiout, void *opaque) { - struct remote_state *rs = get_remote_state (); struct start_remote_args *args = opaque; + struct remote_state *rs = get_remote_state (); + struct packet_config *noack_config; char *wait_status = NULL; immediate_quit++; /* Allow user to interrupt it. */ + /* Ack any packet which the remote side has already sent. */ + serial_write (remote_desc, "+", 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 (); + + /* Next, we possibly activate noack mode. + + If the QStartNoAckMode packet configuration is set to AUTO, + enable noack mode if the stub reported a wish for it with + qSupported. + + If set to TRUE, then enable noack mode even if the stub didn't + report it in qSupported. If the stub doesn't reply OK, the + session ends with an error. + + If FALSE, then don't activate noack mode, regardless of what the + stub claimed should be the default with qSupported. */ + + noack_config = &remote_protocol_packets[PACKET_QStartNoAckMode]; + + if (noack_config->detect == AUTO_BOOLEAN_TRUE + || (noack_config->detect == AUTO_BOOLEAN_AUTO + && noack_config->support == PACKET_ENABLE)) + { + putpkt ("QStartNoAckMode"); + getpkt (&rs->buf, &rs->buf_size, 0); + if (packet_ok (rs->buf, noack_config) == PACKET_OK) + rs->noack_mode = 1; + } + + /* Next, if the target can specify a description, read it. We do + this before anything involving memory or registers. */ + target_find_description (); + /* Check whether the target is running now. */ putpkt ("?"); getpkt (&rs->buf, &rs->buf_size, 0); @@ -2439,6 +2481,20 @@ remote_start_remote (struct ui_out *uiout, void *opaque) immediate_quit--; start_remote (args->from_tty); /* Initialize gdb process mechanisms. */ + + if (args->extended_p) + { + /* Tell the remote that we are using the extended protocol. */ + putpkt ("!"); + getpkt (&rs->buf, &rs->buf_size, 0); + } + + /* If we connected to a live target, do some additional setup. */ + if (target_has_execution) + { + if (exec_bfd) /* No use without an exec file. */ + remote_check_symbols (symfile_objfile); + } } /* Open a connection to a remote debugger. @@ -2788,7 +2844,6 @@ static void remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended_p) { struct remote_state *rs = get_remote_state (); - struct packet_config *noack_config; if (name == 0) error (_("To open a remote debug connection, you need to specify what\n" @@ -2883,43 +2938,6 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended use_threadinfo_query = 1; use_threadextra_query = 1; - /* Ack any packet which the remote side has already sent. */ - serial_write (remote_desc, "+", 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 (); - - /* Next, we possibly activate noack mode. - - If the QStartNoAckMode packet configuration is set to AUTO, - enable noack mode if the stub reported a wish for it with - qSupported. - - If set to TRUE, then enable noack mode even if the stub didn't - report it in qSupported. If the stub doesn't reply OK, the - session ends with an error. - - If FALSE, then don't activate noack mode, regardless of what the - stub claimed should be the default with qSupported. */ - - noack_config = &remote_protocol_packets[PACKET_QStartNoAckMode]; - - if (noack_config->detect == AUTO_BOOLEAN_TRUE - || (noack_config->detect == AUTO_BOOLEAN_AUTO - && noack_config->support == PACKET_ENABLE)) - { - putpkt ("QStartNoAckMode"); - getpkt (&rs->buf, &rs->buf_size, 0); - if (packet_ok (rs->buf, noack_config) == PACKET_OK) - rs->noack_mode = 1; - } - - /* Next, if the target can specify a description, read it. We do - this before anything involving memory or registers. */ - target_find_description (); - if (target_async_permitted) { /* With this target we start out by owning the terminal. */ @@ -2964,7 +2982,10 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended ex = catch_exception (uiout, remote_start_remote, &args, RETURN_MASK_ALL); if (ex.reason < 0) { - pop_target (); + /* Pop the partially set up target - unless something else did + already before throwing the exception. */ + if (remote_desc != NULL) + pop_target (); if (target_async_permitted) wait_forever_enabled_p = 1; throw_exception (ex); @@ -2973,20 +2994,6 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, int extended if (target_async_permitted) wait_forever_enabled_p = 1; - - if (extended_p) - { - /* Tell the remote that we are using the extended protocol. */ - putpkt ("!"); - getpkt (&rs->buf, &rs->buf_size, 0); - } - - /* If we connected to a live target, do some additional setup. */ - if (target_has_execution) - { - if (exec_bfd) /* No use without an exec file. */ - remote_check_symbols (symfile_objfile); - } } /* This takes a program previously attached to and detaches it. After diff --git a/gdb/target.c b/gdb/target.c index a509c173db..7452d2ab61 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -746,6 +746,10 @@ unpush_target (struct target_ops *t) struct target_ops **cur; struct target_ops *tmp; + if (t->to_stratum == dummy_stratum) + internal_error (__FILE__, __LINE__, + "Attempt to unpush the dummy target"); + /* Look for the specified target. Note that we assume that a target can only occur once in the target stack. */