X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fremote.c;h=a7736800edf1b323a4a0a96394a9fdacbd0b07a3;hb=84de6048cc4c90cb3fb9905bb2472956feb18c28;hp=20619857532db5875b795ad87f7bf931d4b07d2c;hpb=d01949b65b015c7b27aca340c2beb70ce590ac36;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/remote.c b/gdb/remote.c index 2061985753..a7736800ed 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1,6 +1,7 @@ /* Remote target communications for serial-line targets in custom GDB protocol - Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, - 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + + Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, + 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of GDB. @@ -210,15 +211,32 @@ void open_remote_target (char *, int, struct target_ops *, int); void _initialize_remote (void); -/* Description of the remote protocol. Strictly speeking, when the +/* Description of the remote protocol. Strictly speaking, when the target is open()ed, remote.c should create a per-target description of the remote protocol using that target's architecture. Unfortunatly, the target stack doesn't include local state. For the moment keep the information in the target's architecture object. Sigh.. */ +struct packet_reg +{ + long offset; /* Offset into G packet. */ + long regnum; /* GDB's internal register number. */ + LONGEST pnum; /* Remote protocol register number. */ + int in_g_packet; /* Always part of G packet. */ + /* long size in bytes; == REGISTER_RAW_SIZE (regnum); at present. */ + /* char *name; == REGISTER_NAME (regnum); at present. */ +}; + struct remote_state { + /* Description of the remote protocol registers. */ + long sizeof_g_packet; + + /* Description of the remote protocol registers indexed by REGNUM + (making an array of NUM_REGS + NUM_PSEUDO_REGS in size). */ + struct packet_reg *regs; + /* This is the size (in chars) of the first response to the ``g'' packet. It is used as a heuristic when determining the maximum size of memory-read and memory-write packets. A target will @@ -247,6 +265,23 @@ init_remote_state (struct gdbarch *gdbarch) int regnum; struct remote_state *rs = xmalloc (sizeof (struct remote_state)); + /* Start out by having the remote protocol mimic the existing + behavour - just copy in the description of the register cache. */ + rs->sizeof_g_packet = REGISTER_BYTES; /* OK use. */ + + /* Assume a 1:1 regnum<->pnum table. */ + rs->regs = xcalloc (NUM_REGS + NUM_PSEUDO_REGS, sizeof (struct packet_reg)); + for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) + { + struct packet_reg *r = &rs->regs[regnum]; + r->pnum = regnum; + r->regnum = regnum; + r->offset = REGISTER_BYTE (regnum); + r->in_g_packet = (regnum < NUM_REGS); + /* ...size = REGISTER_RAW_SIZE (regnum); */ + /* ...name = REGISTER_NAME (regnum); */ + } + /* Default maximum number of characters in a packet body. Many remote stubs have a hardwired buffer size of 400 bytes (c.f. BUFMAX in m68k-stub.c and i386-stub.c). BUFMAX-1 is used @@ -256,14 +291,14 @@ init_remote_state (struct gdbarch *gdbarch) already a full buffer (As of 1999-12-04 that was most stubs. */ rs->remote_packet_size = 400 - 1; - /* Should REGISTER_BYTES needs more space than the default, adjust - the size accordingly. Remember that each byte is encoded as two - characters. 32 is the overhead for the packet header / - footer. NOTE: cagney/1999-10-26: I suspect that 8 + /* Should rs->sizeof_g_packet needs more space than the + default, adjust the size accordingly. Remember that each byte is + encoded as two characters. 32 is the overhead for the packet + header / footer. NOTE: cagney/1999-10-26: I suspect that 8 (``$NN:G...#NN'') is a better guess, the below has been padded a little. */ - if (REGISTER_BYTES > ((rs->remote_packet_size - 32) / 2)) - rs->remote_packet_size = (REGISTER_BYTES * 2 + 32); + if (rs->sizeof_g_packet > ((rs->remote_packet_size - 32) / 2)) + rs->remote_packet_size = (rs->sizeof_g_packet * 2 + 32); /* This one is filled in when a ``g'' packet is received. */ rs->actual_register_packet_size = 0; @@ -274,8 +309,35 @@ init_remote_state (struct gdbarch *gdbarch) static void free_remote_state (struct gdbarch *gdbarch, void *pointer) { - struct remote_state *state = pointer; - xfree (state); + struct remote_state *data = pointer; + xfree (data->regs); + xfree (data); +} + +static struct packet_reg * +packet_reg_from_regnum (struct remote_state *rs, long regnum) +{ + if (regnum < 0 && regnum >= NUM_REGS + NUM_PSEUDO_REGS) + return NULL; + else + { + struct packet_reg *r = &rs->regs[regnum]; + gdb_assert (r->regnum == regnum); + return r; + } +} + +static struct packet_reg * +packet_reg_from_pnum (struct remote_state *rs, LONGEST pnum) +{ + int i; + for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++) + { + struct packet_reg *r = &rs->regs[i]; + if (r->pnum == pnum) + return r; + } + return NULL; } /* */ @@ -336,12 +398,12 @@ static int remote_async_terminal_ours_p; /* User configurable variables for the number of characters in a - memory read/write packet. MIN ((rs->remote_packet_size), g-packet-size) is the - default. Some targets need smaller values (fifo overruns, et.al.) - and some users need larger values (speed up transfers). The - variables ``preferred_*'' (the user request), ``current_*'' (what - was actually set) and ``forced_*'' (Positive - a soft limit, - negative - a hard limit). */ + memory read/write packet. MIN ((rs->remote_packet_size), + rs->sizeof_g_packet) is the default. Some targets need smaller + values (fifo overruns, et.al.) and some users need larger values + (speed up transfers). The variables ``preferred_*'' (the user + request), ``current_*'' (what was actually set) and ``forced_*'' + (Positive - a soft limit, negative - a hard limit). */ struct memory_packet_config { @@ -613,7 +675,7 @@ add_packet_config_cmd (struct packet_config *config, set_cmd = add_set_auto_boolean_cmd (cmd_name, class_obscure, &config->detect, set_doc, set_remote_list); - set_cmd->function.sfunc = set_func; + set_cmd_sfunc (set_cmd, set_func); show_cmd = add_cmd (cmd_name, class_obscure, show_func, show_doc, show_remote_list); /* set/show remote NAME-packet {auto,on,off} -- legacy */ @@ -940,14 +1002,9 @@ record_currthread (int currthread) if (!in_thread_list (pid_to_ptid (currthread))) { add_thread (pid_to_ptid (currthread)); -#ifdef UI_OUT ui_out_text (uiout, "[New "); ui_out_text (uiout, target_pid_to_str (pid_to_ptid (currthread))); ui_out_text (uiout, "]\n"); -#else - printf_filtered ("[New %s]\n", - target_pid_to_str (pid_to_ptid (currthread))); -#endif } } @@ -2171,9 +2228,9 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target, { 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.)."); + 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 */ wait_forever_enabled_p = 1; @@ -2272,9 +2329,9 @@ remote_async_open_1 (char *name, int from_tty, struct target_ops *target, { 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.)."); + 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.)."); target_preopen (from_tty); @@ -2820,7 +2877,7 @@ interrupt_query (void) Give up (and stop debugging it)? ")) { target_mourn_inferior (); - return_to_top_level (RETURN_QUIT); + throw_exception (RETURN_QUIT); } target_terminal_inferior (); @@ -2927,7 +2984,6 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status) case 'T': /* Status with PC, SP, FP, ... */ { int i; - long regno; char* regs = (char*) alloca (MAX_REGISTER_RAW_SIZE); /* Expedited reply, containing Signal, {regno, reg} repeat */ @@ -2944,8 +3000,8 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status) char *p_temp; int fieldsize; - /* Read the register number */ - regno = strtol ((const char *) p, &p_temp, 16); + /* Read the ``P'' register number. */ + LONGEST pnum = strtol ((const char *) p, &p_temp, 16); p1 = (unsigned char *) p_temp; if (p1 == p) /* No register number present here */ @@ -2964,6 +3020,7 @@ Packet: '%s'\n", } else { + struct packet_reg *reg = packet_reg_from_pnum (rs, pnum); p = p1; if (*p++ != ':') @@ -2971,16 +3028,16 @@ Packet: '%s'\n", Packet: '%s'\n", p, buf); - if (regno >= NUM_REGS) - warning ("Remote sent bad register number %ld: %s\n\ + if (reg == NULL) + warning ("Remote sent bad register number %s: %s\n\ Packet: '%s'\n", - regno, p, buf); + phex_nz (pnum, 0), p, buf); - fieldsize = hex2bin (p, regs, REGISTER_RAW_SIZE (regno)); + fieldsize = hex2bin (p, regs, REGISTER_RAW_SIZE (reg->regnum)); p += 2 * fieldsize; - if (fieldsize < REGISTER_RAW_SIZE (regno)) + if (fieldsize < REGISTER_RAW_SIZE (reg->regnum)) warning ("Remote reply is too short: %s", buf); - supply_register (regno, regs); + supply_register (reg->regnum, regs); } if (*p++ != ';') @@ -3147,7 +3204,6 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status) case 'T': /* Status with PC, SP, FP, ... */ { int i; - long regno; char* regs = (char*) alloca (MAX_REGISTER_RAW_SIZE); /* Expedited reply, containing Signal, {regno, reg} repeat */ @@ -3165,7 +3221,7 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status) int fieldsize; /* Read the register number */ - regno = strtol ((const char *) p, &p_temp, 16); + long pnum = strtol ((const char *) p, &p_temp, 16); p1 = (unsigned char *) p_temp; if (p1 == p) /* No register number present here */ @@ -3184,23 +3240,23 @@ Packet: '%s'\n", } else { + struct packet_reg *reg = packet_reg_from_pnum (rs, pnum); p = p1; - if (*p++ != ':') warning ("Malformed packet(b) (missing colon): %s\n\ Packet: '%s'\n", p, buf); - if (regno >= NUM_REGS) + if (reg == NULL) warning ("Remote sent bad register number %ld: %s\n\ Packet: '%s'\n", - regno, p, buf); + pnum, p, buf); - fieldsize = hex2bin (p, regs, REGISTER_RAW_SIZE (regno)); + fieldsize = hex2bin (p, regs, REGISTER_RAW_SIZE (reg->regnum)); p += 2 * fieldsize; - if (fieldsize < REGISTER_RAW_SIZE (regno)) + if (fieldsize < REGISTER_RAW_SIZE (reg->regnum)) warning ("Remote reply is too short: %s", buf); - supply_register (regno, regs); + supply_register (reg->regnum, regs); } if (*p++ != ';') @@ -3337,20 +3393,30 @@ got_status: static int register_bytes_found; /* Read the remote registers into the block REGS. */ -/* Currently we just read all the registers, so we don't use regno. */ +/* Currently we just read all the registers, so we don't use regnum. */ /* ARGSUSED */ static void -remote_fetch_registers (int regno) +remote_fetch_registers (int regnum) { struct remote_state *rs = get_remote_state (); char *buf = alloca (rs->remote_packet_size); int i; char *p; - char *regs = alloca (REGISTER_BYTES); + char *regs = alloca (rs->sizeof_g_packet); set_thread (PIDGET (inferior_ptid), 1); + if (regnum >= 0) + { + struct packet_reg *reg = packet_reg_from_regnum (rs, regnum); + gdb_assert (reg != NULL); + if (!reg->in_g_packet) + internal_error (__FILE__, __LINE__, + "Attempt to fetch a non G-packet register when this " + "remote.c does not support the p-packet."); + } + sprintf (buf, "g"); remote_send (buf, (rs->remote_packet_size)); @@ -3361,7 +3427,7 @@ remote_fetch_registers (int regno) (rs->actual_register_packet_size) = strlen (buf); /* Unimplemented registers read as all bits zero. */ - memset (regs, 0, REGISTER_BYTES); + memset (regs, 0, rs->sizeof_g_packet); /* We can get out of synch in various cases. If the first character in the buffer is not a hex character, assume that has happened @@ -3381,7 +3447,7 @@ remote_fetch_registers (int regno) register cacheing/storage mechanism. */ p = buf; - for (i = 0; i < REGISTER_BYTES; i++) + for (i = 0; i < rs->sizeof_g_packet; i++) { if (p[0] == 0) break; @@ -3407,13 +3473,20 @@ remote_fetch_registers (int regno) warning ("Remote reply is too short: %s", buf); } -supply_them: - for (i = 0; i < NUM_REGS; i++) - { - supply_register (i, ®s[REGISTER_BYTE (i)]); - if (buf[REGISTER_BYTE (i) * 2] == 'x') - set_register_cached (i, -1); - } + supply_them: + { + int i; + for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++) + { + struct packet_reg *r = &rs->regs[i]; + if (r->in_g_packet) + { + supply_register (r->regnum, regs + r->offset); + if (buf[r->offset * 2] == 'x') + set_register_cached (i, -1); + } + } + } } /* Prepare to store registers. Since we may send them all (using a @@ -3428,63 +3501,67 @@ remote_prepare_to_store (void) { case PACKET_DISABLE: case PACKET_SUPPORT_UNKNOWN: - read_register_bytes (0, (char *) NULL, REGISTER_BYTES); + /* NOTE: This isn't rs->sizeof_g_packet because here, we are + forcing the register cache to read its and not the target + registers. */ + read_register_bytes (0, (char *) NULL, REGISTER_BYTES); /* OK use. */ break; case PACKET_ENABLE: break; } } -/* Helper: Attempt to store REGNO using the P packet. Return fail IFF +/* Helper: Attempt to store REGNUM using the P packet. Return fail IFF packet was not recognized. */ static int -store_register_using_P (int regno) +store_register_using_P (int regnum) { struct remote_state *rs = get_remote_state (); + struct packet_reg *reg = packet_reg_from_regnum (rs, regnum); /* Try storing a single register. */ char *buf = alloca (rs->remote_packet_size); - char *regp; + char *regp = alloca (MAX_REGISTER_RAW_SIZE); char *p; int i; - sprintf (buf, "P%x=", regno); + sprintf (buf, "P%s=", phex_nz (reg->pnum, 0)); p = buf + strlen (buf); - regp = register_buffer (regno); - bin2hex (regp, p, REGISTER_RAW_SIZE (regno)); - remote_send (buf, (rs->remote_packet_size)); + regcache_collect (reg->regnum, regp); + bin2hex (regp, p, REGISTER_RAW_SIZE (reg->regnum)); + remote_send (buf, rs->remote_packet_size); return buf[0] != '\0'; } -/* Store register REGNO, or all registers if REGNO == -1, from the contents +/* Store register REGNUM, or all registers if REGNUM == -1, from the contents of the register cache buffer. FIXME: ignores errors. */ static void -remote_store_registers (int regno) +remote_store_registers (int regnum) { struct remote_state *rs = get_remote_state (); - char *buf = alloca (rs->remote_packet_size); + char *buf; + char *regs; int i; char *p; - char *regs; set_thread (PIDGET (inferior_ptid), 1); - if (regno >= 0) + if (regnum >= 0) { switch (remote_protocol_P.support) { case PACKET_DISABLE: break; case PACKET_ENABLE: - if (store_register_using_P (regno)) + if (store_register_using_P (regnum)) return; else error ("Protocol error: P packet not recognized by stub"); case PACKET_SUPPORT_UNKNOWN: - if (store_register_using_P (regno)) + if (store_register_using_P (regnum)) { /* The stub recognized the 'P' packet. Remember this. */ remote_protocol_P.support = PACKET_ENABLE; @@ -3501,13 +3578,25 @@ remote_store_registers (int regno) } } - buf[0] = 'G'; + /* Extract all the registers in the regcache copying them into a + local buffer. */ + { + int i; + regs = alloca (rs->sizeof_g_packet); + memset (regs, rs->sizeof_g_packet, 0); + for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++) + { + struct packet_reg *r = &rs->regs[i]; + if (r->in_g_packet) + regcache_collect (r->regnum, regs + r->offset); + } + } /* Command describes registers byte by byte, each byte encoded as two hex characters. */ - - regs = register_buffer (-1); - p = buf + 1; + buf = alloca (rs->remote_packet_size); + p = buf; + *p++ = 'G'; /* remote_prepare_to_store insures that register_bytes_found gets set. */ bin2hex (regs, p, register_bytes_found); remote_send (buf, (rs->remote_packet_size)); @@ -3850,8 +3939,7 @@ remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len) /* ARGSUSED */ static int remote_xfer_memory (CORE_ADDR mem_addr, char *buffer, int mem_len, - int should_write, - struct mem_attrib *attrib ATTRIBUTE_UNUSED, + int should_write, struct mem_attrib *attrib, struct target_ops *target) { CORE_ADDR targ_addr; @@ -4588,7 +4676,7 @@ remote_insert_breakpoint (CORE_ADDR addr, char *contents_cache) if (val == 0) { - if (TARGET_BYTE_ORDER == BIG_ENDIAN) + if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) val = target_write_memory (addr, (char *) big_break_insn, sizeof big_break_insn); else @@ -4925,8 +5013,8 @@ compare_sections_command (char *args, int from_tty) getpkt (buf, (rs->remote_packet_size), 0); if (buf[0] == 'E') - error ("target memory fault, section %s, range 0x%08x -- 0x%08x", - sectname, lma, lma + size); + error ("target memory fault, section %s, range 0x%s -- 0x%s", + sectname, paddr (lma), paddr (lma + size)); if (buf[0] != 'C') error ("remote target does not support this operation"); @@ -5365,9 +5453,8 @@ static void remote_cisco_open (char *name, int from_tty) { if (name == 0) - error ( - "To open a remote debug connection, you need to specify what \n\ -device is attached to the remote system (e.g. host:port)."); + error ("To open a remote debug connection, you need to specify what \n" + "device is attached to the remote system (e.g. host:port)."); /* See FIXME above */ wait_forever_enabled_p = 1; @@ -5630,7 +5717,7 @@ minitelnet (void) if (query ("Interrupt GDB? ")) { printf_filtered ("Interrupted by user.\n"); - return_to_top_level (RETURN_QUIT); + throw_exception (RETURN_QUIT); } quit_count = 0; } @@ -5877,7 +5964,6 @@ _initialize_remote (void) /* Old tacky stuff. NOTE: This comes after the remote protocol so that the remote protocol has been initialized. */ - register_gdbarch_swap (&tty_input, sizeof (&tty_input), NULL); register_gdbarch_swap (&remote_address_size, sizeof (&remote_address_size), NULL); register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data); @@ -6013,6 +6099,10 @@ in a memory packet.\n", show_remote_protocol_e_packet_cmd, &remote_set_cmdlist, &remote_show_cmdlist, 0); + /* Disable by default. The ``e'' packet has nasty interactions with + the threading code - it relies on global state. */ + remote_protocol_e.detect = CMD_AUTO_BOOLEAN_FALSE; + update_packet_config (&remote_protocol_e); add_packet_config_cmd (&remote_protocol_E, "E", "step-over-range-w-signal", @@ -6020,6 +6110,10 @@ in a memory packet.\n", show_remote_protocol_E_packet_cmd, &remote_set_cmdlist, &remote_show_cmdlist, 0); + /* Disable by default. The ``e'' packet has nasty interactions with + the threading code - it relies on global state. */ + remote_protocol_E.detect = CMD_AUTO_BOOLEAN_FALSE; + update_packet_config (&remote_protocol_E); add_packet_config_cmd (&remote_protocol_P, "P", "set-register", @@ -6068,7 +6162,7 @@ in a memory packet.\n", &remote_Z_packet_detect, "\ Set use of remote protocol `Z' packets", &remote_set_cmdlist); - tmpcmd->function.sfunc = set_remote_protocol_Z_packet_cmd; + set_cmd_sfunc (tmpcmd, set_remote_protocol_Z_packet_cmd); add_cmd ("Z-packet", class_obscure, show_remote_protocol_Z_packet_cmd, "Show use of remote protocol `Z' packets ", &remote_show_cmdlist);