/* Remote target communications for serial-line targets in custom GDB protocol
- Copyright 1988, 1991-2000 Free Software Foundation, Inc.
+ Copyright 1988, 1991-2000, 2001 Free Software Foundation, Inc.
This file is part of GDB.
#include "bfd.h"
#include "symfile.h"
#include "target.h"
-#include "gdb_wait.h"
/*#include "terminal.h" */
#include "gdbcmd.h"
#include "objfiles.h"
#include "gdb-stabs.h"
#include "gdbthread.h"
#include "remote.h"
-
-#include "dcache.h"
+#include "regcache.h"
#include <ctype.h>
#include <sys/time.h>
static int remote_xfer_memory (CORE_ADDR memaddr, char *myaddr,
int len, int should_write,
+ struct mem_attrib *attrib,
struct target_ops *target);
static void remote_prepare_to_store (void);
config->title = title;
config->detect = CMD_AUTO_BOOLEAN_AUTO;
config->support = PACKET_SUPPORT_UNKNOWN;
- asprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
- name, title);
- asprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
- name, title);
+ xasprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
+ name, title);
+ xasprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
+ name, title);
/* set/show TITLE-packet {auto,on,off} */
- asprintf (&cmd_name, "%s-packet", title);
+ xasprintf (&cmd_name, "%s-packet", title);
set_cmd = add_set_auto_boolean_cmd (cmd_name, class_obscure,
&config->detect, set_doc,
set_remote_list);
if (legacy)
{
char *legacy_name;
- asprintf (&legacy_name, "%s-packet", name);
+ xasprintf (&legacy_name, "%s-packet", name);
add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
set_remote_list);
add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
config->support = PACKET_ENABLE;
break;
case PACKET_DISABLE:
- internal_error ("packet_ok: attempt to use a disabled packet");
+ internal_error (__FILE__, __LINE__,
+ "packet_ok: attempt to use a disabled packet");
break;
case PACKET_ENABLE:
break;
int n = 0; /* position in display_buf */
if (remote_desc == 0) /* paranoia */
- internal_error ("remote_threads_extra_info");
+ internal_error (__FILE__, __LINE__,
+ "remote_threads_extra_info");
if (use_threadextra_query)
{
static int
remote_start_remote (PTR dummy)
{
- immediate_quit = 1; /* Allow user to interrupt it */
+ immediate_quit++; /* Allow user to interrupt it */
/* Ack any packet which the remote side has already sent. */
SERIAL_WRITE (remote_desc, "+", 1);
get_offsets (); /* Get text, data & bss offsets */
putpkt ("?"); /* initiate a query from remote machine */
- immediate_quit = 0;
+ immediate_quit--;
return remote_start_remote_dummy (dummy);
}
/* Generic code for opening a connection to a remote target. */
-static DCACHE *remote_dcache;
-
static void
init_all_packet_configs (void)
{
unpush_target (target);
- if (!remote_dcache)
- remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
- else
- dcache_flush (remote_dcache);
-
remote_desc = SERIAL_OPEN (name);
if (!remote_desc)
perror_with_name (name);
unpush_target (target);
- remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
-
remote_desc = SERIAL_OPEN (name);
if (!remote_desc)
perror_with_name (name);
/* FIXME: cagney/1999-09-23: During the initial connection it is
assumed that the target is already ready and able to respond to
- requests. Unfortunatly remote_start_remote() eventually calls
+ requests. Unfortunately remote_start_remote() eventually calls
wait_for_inferior() with no timeout. wait_forever_enabled_p gets
around this. Eventually a mechanism that allows
wait_for_inferior() to expect/get timeouts will be
else
set_thread (pid, 0); /* run this thread */
- dcache_flush (remote_dcache);
-
last_sent_signal = siggnal;
last_sent_step = step;
else
set_thread (pid, 0); /* run this thread */
- dcache_flush (remote_dcache);
-
last_sent_signal = siggnal;
last_sent_step = step;
{
int i;
long regno;
- char regs[MAX_REGISTER_RAW_SIZE];
+ char* regs = (char*) alloca (MAX_REGISTER_RAW_SIZE);
/* Expedited reply, containing Signal, {regno, reg} repeat */
/* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
{
int i;
long regno;
- char regs[MAX_REGISTER_RAW_SIZE];
+ char* regs = (char*) alloca (MAX_REGISTER_RAW_SIZE);
/* Expedited reply, containing Signal, {regno, reg} repeat */
/* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
char *buf = alloca (PBUFSIZ);
int i;
char *p;
- char regs[REGISTER_BYTES];
+ char *regs = alloca (REGISTER_BYTES);
set_thread (inferior_pid, 1);
if (i != register_bytes_found)
{
register_bytes_found = i;
-#ifdef REGISTER_BYTES_OK
- if (!REGISTER_BYTES_OK (i))
+ if (REGISTER_BYTES_OK_P ()
+ && !REGISTER_BYTES_OK (i))
warning ("Remote reply is too short: %s", buf);
-#endif
}
supply_them:
{
supply_register (i, ®s[REGISTER_BYTE (i)]);
if (buf[REGISTER_BYTE (i) * 2] == 'x')
- register_valid[i] = -1; /* register value not available */
+ set_register_cached (i, -1);
}
}
sprintf (buf, "P%x=", regno);
p = buf + strlen (buf);
- regp = ®isters[REGISTER_BYTE (regno)];
+ regp = register_buffer (regno);
for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
{
*p++ = tohex ((regp[i] >> 4) & 0xf);
/* Store register REGNO, or all registers if REGNO == -1, from the contents
- of REGISTERS. FIXME: ignores errors. */
+ of the register cache buffer. FIXME: ignores errors. */
static void
remote_store_registers (int regno)
char *buf = alloca (PBUFSIZ);
int i;
char *p;
+ char *regs;
set_thread (inferior_pid, 1);
/* Command describes registers byte by byte,
each byte encoded as two hex characters. */
+ regs = register_buffer (-1);
p = buf + 1;
/* remote_prepare_to_store insures that register_bytes_found gets set. */
for (i = 0; i < register_bytes_found; i++)
{
- *p++ = tohex ((registers[i] >> 4) & 0xf);
- *p++ = tohex (registers[i] & 0xf);
+ *p++ = tohex ((regs[i] >> 4) & 0xf);
+ *p++ = tohex (regs[i] & 0xf);
}
*p = '\0';
todo = min (len, max_buf_size / 2);
break;
case PACKET_SUPPORT_UNKNOWN:
- internal_error ("remote_write_bytes: bad switch");
+ internal_error (__FILE__, __LINE__,
+ "remote_write_bytes: bad internal state");
+ default:
+ internal_error (__FILE__, __LINE__, "bad switch");
}
/* Append <memaddr> */
*p = '\0';
break;
case PACKET_SUPPORT_UNKNOWN:
- internal_error ("remote_write_bytes: bad switch");
+ internal_error (__FILE__, __LINE__,
+ "remote_write_bytes: bad internal state");
+ default:
+ internal_error (__FILE__, __LINE__, "bad switch");
}
putpkt_binary (buf, (int) (p - buf));
/* Read or write LEN bytes from inferior memory at MEMADDR,
transferring to or from debugger address BUFFER. Write to inferior if
SHOULD_WRITE is nonzero. Returns length of data written or read; 0
- for error. */
+ for error. TARGET is unused. */
/* ARGSUSED */
static int
-remote_xfer_memory (mem_addr, buffer, mem_len, should_write, target)
- CORE_ADDR mem_addr;
- char *buffer;
- int mem_len;
- int should_write;
- struct target_ops *target; /* ignored */
+remote_xfer_memory (CORE_ADDR mem_addr, char *buffer, int mem_len,
+ int should_write,
+ struct mem_attrib *attrib ATTRIBUTE_UNUSED,
+ struct target_ops *target)
{
CORE_ADDR targ_addr;
int targ_len;
+ int res;
+
REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
if (targ_len <= 0)
return 0;
- return dcache_xfer_memory (remote_dcache, targ_addr, buffer,
- targ_len, should_write);
+ if (should_write)
+ res = remote_write_bytes (targ_addr, buffer, targ_len);
+ else
+ res = remote_read_bytes (targ_addr, buffer, targ_len);
+
+ return res;
}
/* Enable after 4.12. */
void
-remote_search (len, data, mask, startaddr, increment, lorange, hirange
- addr_found, data_found)
- int len;
- char *data;
- char *mask;
- CORE_ADDR startaddr;
- int increment;
- CORE_ADDR lorange;
- CORE_ADDR hirange;
- CORE_ADDR *addr_found;
- char *data_found;
+remote_search (int len, char *data, char *mask, CORE_ADDR startaddr,
+ int increment, CORE_ADDR lorange, CORE_ADDR hirange,
+ CORE_ADDR *addr_found, char *data_found)
{
if (increment == -4 && len == 4)
{
break; /* Retransmit buffer */
case '$':
{
+ if (remote_debug)
+ fprintf_unfiltered (gdb_stdlog, "Packet instead of Ack, ignoring it\n");
/* It's probably an old response, and we're out of sync.
Just gobble up the packet and ignore it. */
- getpkt (junkbuf, sizeof_junkbuf, 0);
+ read_frame (junkbuf, sizeof_junkbuf);
continue; /* Now, go look for + */
}
default:
case '#':
{
unsigned char pktcsum;
+ int check_0 = 0;
+ int check_1 = 0;
buf[bc] = '\0';
- pktcsum = fromhex (readchar (remote_timeout)) << 4;
- pktcsum |= fromhex (readchar (remote_timeout));
+ check_0 = readchar (remote_timeout);
+ if (check_0 >= 0)
+ check_1 = readchar (remote_timeout);
+
+ if (check_0 == SERIAL_TIMEOUT || check_1 == SERIAL_TIMEOUT)
+ {
+ if (remote_debug)
+ fputs_filtered ("Timeout in checksum, retrying\n", gdb_stdlog);
+ return -1;
+ }
+ else if (check_0 < 0 || check_1 < 0)
+ {
+ if (remote_debug)
+ fputs_filtered ("Communication error in checksum\n", gdb_stdlog);
+ return -1;
+ }
+ pktcsum = (fromhex (check_0) << 4) | fromhex (check_1);
if (csum == pktcsum)
return bc;
return 4;
break;
default:
- internal_error ("hw_bp_to_z: bad watchpoint type %d", type);
+ internal_error (__FILE__, __LINE__,
+ "hw_bp_to_z: bad watchpoint type %d", type);
}
}
case PACKET_OK:
return 0;
}
- internal_error ("remote_insert_watchpoint: reached end of function");
+ internal_error (__FILE__, __LINE__,
+ "remote_insert_watchpoint: reached end of function");
}
/* FIXME: This function should be static and a member of the remote
case PACKET_OK:
return 0;
}
- internal_error ("remote_remove_watchpoint: reached end of function");
+ internal_error (__FILE__, __LINE__,
+ "remote_remove_watchpoint: reached end of function");
}
/* FIXME: This function should be static and a member of the remote
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
- *p = '\0';
+ sprintf (p, ",%x", len);
putpkt (buf);
getpkt (buf, PBUFSIZ, 0);
case PACKET_OK:
return 0;
}
- internal_error ("remote_remove_watchpoint: reached end of function");
+ internal_error (__FILE__, __LINE__,
+ "remote_remove_watchpoint: reached end of function");
}
/* FIXME: This function should be static and a member of the remote
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
- *p = '\0';
+ sprintf (p, ",%x", len);
putpkt(buf);
getpkt (buf, PBUFSIZ, 0);
case PACKET_OK:
return 0;
}
- internal_error ("remote_remove_watchpoint: reached end of function");
+ internal_error (__FILE__, __LINE__,
+ "remote_remove_watchpoint: reached end of function");
}
/* Some targets are only capable of doing downloads, and afterwards
/* be clever; compute the host_crc before waiting for target reply */
sectdata = xmalloc (size);
- old_chain = make_cleanup (free, sectdata);
+ old_chain = make_cleanup (xfree, sectdata);
bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
unpush_target (&remote_cisco_ops);
- if (!remote_dcache)
- remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
- else
- dcache_flush (remote_dcache);
-
remote_desc = SERIAL_OPEN (name);
if (!remote_desc)
perror_with_name (name);
remote_async (void (*callback) (enum inferior_event_type event_type, void *context), void *context)
{
if (current_target.to_async_mask_value == 0)
- internal_error ("Calling remote_async when async is masked");
+ internal_error (__FILE__, __LINE__,
+ "Calling remote_async when async is masked");
if (callback != NULL)
{
/* Cisco stuff */
tty_input = xmalloc (PBUFSIZ);
- remote_address_size = TARGET_PTR_BIT;
+ remote_address_size = TARGET_ADDR_BIT;
}
void
add_cmd ("remotewritesize", no_class, set_memory_write_packet_size,
"Set the maximum number of bytes per memory write packet (deprecated).\n",
&setlist);
- add_cmd ("remotewritesize", no_class, set_memory_write_packet_size,
+ add_cmd ("remotewritesize", no_class, show_memory_write_packet_size,
"Show the maximum number of bytes per memory write packet (deprecated).\n",
&showlist);
add_cmd ("memory-write-packet-size", no_class,