aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2008-10-09 03:24:51 +0000
committerPedro Alves <palves@redhat.com>2008-10-09 03:24:51 +0000
commitc8d104ad6940c4f094193620122d26d8d2ff4167 (patch)
tree1d37db3f95a3eb1c689ac2d722d88b312ef0bfd0 /gdb/remote.c
parentefdb2a86e46122879fab082916287486d5208b41 (diff)
downloadgdb-c8d104ad6940c4f094193620122d26d8d2ff4167.zip
gdb-c8d104ad6940c4f094193620122d26d8d2ff4167.tar.gz
gdb-c8d104ad6940c4f094193620122d26d8d2ff4167.tar.bz2
* 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.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c115
1 files changed, 61 insertions, 54 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index f648c36..aa754d2 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