#include "defs.h"
#include "gdb_string.h"
#include <ctype.h>
#include <fcntl.h>
#include "inferior.h"
#include "bfd.h"
#include "symfile.h"
#include "exceptions.h"
#include "target.h"
#include "gdbcmd.h"
#include "objfiles.h"
#include "gdb-stabs.h"
#include "gdbthread.h"
#include "remote.h"
#include "regcache.h"
#include "value.h"
#include "gdb_assert.h"
#include "observer.h"
#include "solib.h"
#include <ctype.h>
#include <sys/time.h>
#include "event-loop.h"
#include "event-top.h"
#include "inf-loop.h"
#include <signal.h>
#include "serial.h"
#include "gdbcore.h"
#include "remote-fileio.h"
static void cleanup_sigint_signal_handler (void *dummy);
static void initialize_sigint_signal_handler (void);
static int getpkt_sane (char *buf, long sizeof_buf, int forever);
static void handle_remote_sigint (int);
static void handle_remote_sigint_twice (int);
static void async_remote_interrupt (gdb_client_data);
void async_remote_interrupt_twice (gdb_client_data);
static void build_remote_gdbarch_data (void);
static void remote_files_info (struct target_ops *ignore);
static void remote_prepare_to_store (void);
static void remote_fetch_registers (int regno);
static void remote_resume (ptid_t ptid, int step,
enum target_signal siggnal);
static void remote_async_resume (ptid_t ptid, int step,
enum target_signal siggnal);
static void remote_open (char *name, int from_tty);
static void remote_async_open (char *name, int from_tty);
static void extended_remote_open (char *name, int from_tty);
static void extended_remote_async_open (char *name, int from_tty);
static void remote_open_1 (char *, int, struct target_ops *, int extended_p,
int async_p);
static void remote_close (int quitting);
static void remote_store_registers (int regno);
static void remote_mourn (void);
static void remote_async_mourn (void);
static void extended_remote_restart (void);
static void extended_remote_mourn (void);
static void remote_mourn_1 (struct target_ops *);
static void remote_send (char *buf, long sizeof_buf);
static int readchar (int timeout);
static ptid_t remote_wait (ptid_t ptid,
struct target_waitstatus *status);
static ptid_t remote_async_wait (ptid_t ptid,
struct target_waitstatus *status);
static void remote_kill (void);
static void remote_async_kill (void);
static int tohex (int nib);
static void remote_detach (char *args, int from_tty);
static void remote_interrupt (int signo);
static void remote_interrupt_twice (int signo);
static void interrupt_query (void);
static void set_thread (int, int);
static int remote_thread_alive (ptid_t);
static void get_offsets (void);
static long read_frame (char *buf, long sizeof_buf);
static int remote_insert_breakpoint (CORE_ADDR, bfd_byte *);
static int remote_remove_breakpoint (CORE_ADDR, bfd_byte *);
static int hexnumlen (ULONGEST num);
static void init_remote_ops (void);
static void init_extended_remote_ops (void);
static void remote_stop (void);
static int ishex (int ch, int *val);
static int stubhex (int ch);
static int hexnumstr (char *, ULONGEST);
static int hexnumnstr (char *, ULONGEST, int);
static CORE_ADDR remote_address_masked (CORE_ADDR);
static void print_packet (char *);
static unsigned long crc32 (unsigned char *, int, unsigned int);
static void compare_sections_command (char *, int);
static void packet_command (char *, int);
static int stub_unpack_int (char *buff, int fieldlength);
static ptid_t remote_current_thread (ptid_t oldptid);
static void remote_find_new_threads (void);
static void record_currthread (int currthread);
static int fromhex (int a);
static int hex2bin (const char *hex, char *bin, int count);
static int bin2hex (const char *bin, char *hex, int count);
static int putpkt_binary (char *buf, int cnt);
static void check_binary_download (CORE_ADDR addr);
struct packet_config;
static void show_packet_config_cmd (struct packet_config *config);
static void update_packet_config (struct packet_config *config);
void _initialize_remote (void);
struct packet_reg
{
long offset;
long regnum;
LONGEST pnum;
int in_g_packet;
};
struct remote_state
{
long sizeof_g_packet;
struct packet_reg *regs;
long actual_register_packet_size;
long remote_packet_size;
};
static struct gdbarch_data *remote_gdbarch_data_handle;
static struct remote_state *
get_remote_state (void)
{
return gdbarch_data (current_gdbarch, remote_gdbarch_data_handle);
}
static void *
init_remote_state (struct gdbarch *gdbarch)
{
int regnum;
struct remote_state *rs = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_state);
rs->sizeof_g_packet = 0;
rs->regs = GDBARCH_OBSTACK_CALLOC (gdbarch, NUM_REGS + NUM_PSEUDO_REGS,
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 = DEPRECATED_REGISTER_BYTE (regnum);
r->in_g_packet = (regnum < NUM_REGS);
if (regnum < NUM_REGS)
rs->sizeof_g_packet += register_size (current_gdbarch, regnum);
}
rs->remote_packet_size = 400 - 1;
if (rs->sizeof_g_packet > ((rs->remote_packet_size - 32) / 2))
rs->remote_packet_size = (rs->sizeof_g_packet * 2 + 32);
rs->actual_register_packet_size = 0;
return rs;
}
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;
}
static CORE_ADDR remote_watch_data_address;
static int remote_stopped_by_watchpoint_p;
struct target_ops remote_ops;
static struct target_ops extended_remote_ops;
static struct target_ops remote_async_ops;
static struct target_ops extended_async_remote_ops;
static int wait_forever_enabled_p = 1;
static int remote_break;
static struct serial *remote_desc = NULL;
static int remote_address_size;
static int remote_async_terminal_ours_p;
struct memory_packet_config
{
char *name;
long size;
int fixed_p;
};
static long
get_memory_packet_size (struct memory_packet_config *config)
{
struct remote_state *rs = get_remote_state ();
#ifndef MAX_REMOTE_PACKET_SIZE
#define MAX_REMOTE_PACKET_SIZE 16384
#endif
#ifndef MIN_REMOTE_PACKET_SIZE
#define MIN_REMOTE_PACKET_SIZE 20
#endif
long what_they_get;
if (config->fixed_p)
{
if (config->size <= 0)
what_they_get = MAX_REMOTE_PACKET_SIZE;
else
what_they_get = config->size;
}
else
{
what_they_get = (rs->remote_packet_size);
if (config->size > 0
&& what_they_get > config->size)
what_they_get = config->size;
if ((rs->actual_register_packet_size) > 0
&& what_they_get > (rs->actual_register_packet_size))
what_they_get = (rs->actual_register_packet_size);
}
if (what_they_get > MAX_REMOTE_PACKET_SIZE)
what_they_get = MAX_REMOTE_PACKET_SIZE;
if (what_they_get < MIN_REMOTE_PACKET_SIZE)
what_they_get = MIN_REMOTE_PACKET_SIZE;
return what_they_get;
}
static void
set_memory_packet_size (char *args, struct memory_packet_config *config)
{
int fixed_p = config->fixed_p;
long size = config->size;
if (args == NULL)
error (_("Argument required (integer, `fixed' or `limited')."));
else if (strcmp (args, "hard") == 0
|| strcmp (args, "fixed") == 0)
fixed_p = 1;
else if (strcmp (args, "soft") == 0
|| strcmp (args, "limit") == 0)
fixed_p = 0;
else
{
char *end;
size = strtoul (args, &end, 0);
if (args == end)
error (_("Invalid %s (bad syntax)."), config->name);
#if 0
if (size > MAX_REMOTE_PACKET_SIZE)
error (_("Invalid %s (too large)."), config->name);
#endif
}
if (fixed_p && !config->fixed_p)
{
if (! query (_("The target may not be able to correctly handle a %s\n"
"of %ld bytes. Change the packet size? "),
config->name, size))
error (_("Packet size not changed."));
}
config->fixed_p = fixed_p;
config->size = size;
}
static void
show_memory_packet_size (struct memory_packet_config *config)
{
printf_filtered (_("The %s is %ld. "), config->name, config->size);
if (config->fixed_p)
printf_filtered (_("Packets are fixed at %ld bytes.\n"),
get_memory_packet_size (config));
else
printf_filtered (_("Packets are limited to %ld bytes.\n"),
get_memory_packet_size (config));
}
static struct memory_packet_config memory_write_packet_config =
{
"memory-write-packet-size",
};
static void
set_memory_write_packet_size (char *args, int from_tty)
{
set_memory_packet_size (args, &memory_write_packet_config);
}
static void
show_memory_write_packet_size (char *args, int from_tty)
{
show_memory_packet_size (&memory_write_packet_config);
}
static long
get_memory_write_packet_size (void)
{
return get_memory_packet_size (&memory_write_packet_config);
}
static struct memory_packet_config memory_read_packet_config =
{
"memory-read-packet-size",
};
static void
set_memory_read_packet_size (char *args, int from_tty)
{
set_memory_packet_size (args, &memory_read_packet_config);
}
static void
show_memory_read_packet_size (char *args, int from_tty)
{
show_memory_packet_size (&memory_read_packet_config);
}
static long
get_memory_read_packet_size (void)
{
struct remote_state *rs = get_remote_state ();
long size = get_memory_packet_size (&memory_read_packet_config);
if (size > (rs->remote_packet_size))
size = (rs->remote_packet_size);
return size;
}
enum packet_support
{
PACKET_SUPPORT_UNKNOWN = 0,
PACKET_ENABLE,
PACKET_DISABLE
};
struct packet_config
{
char *name;
char *title;
enum auto_boolean detect;
enum packet_support support;
};
enum packet_result
{
PACKET_ERROR,
PACKET_OK,
PACKET_UNKNOWN
};
static void
update_packet_config (struct packet_config *config)
{
switch (config->detect)
{
case AUTO_BOOLEAN_TRUE:
config->support = PACKET_ENABLE;
break;
case AUTO_BOOLEAN_FALSE:
config->support = PACKET_DISABLE;
break;
case AUTO_BOOLEAN_AUTO:
config->support = PACKET_SUPPORT_UNKNOWN;
break;
}
}
static void
show_packet_config_cmd (struct packet_config *config)
{
char *support = "internal-error";
switch (config->support)
{
case PACKET_ENABLE:
support = "enabled";
break;
case PACKET_DISABLE:
support = "disabled";
break;
case PACKET_SUPPORT_UNKNOWN:
support = "unknown";
break;
}
switch (config->detect)
{
case AUTO_BOOLEAN_AUTO:
printf_filtered (_("Support for remote protocol `%s' (%s) packet is auto-detected, currently %s.\n"),
config->name, config->title, support);
break;
case AUTO_BOOLEAN_TRUE:
case AUTO_BOOLEAN_FALSE:
printf_filtered (_("Support for remote protocol `%s' (%s) packet is currently %s.\n"),
config->name, config->title, support);
break;
}
}
static void
add_packet_config_cmd (struct packet_config *config,
char *name,
char *title,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_remote_list,
struct cmd_list_element **show_remote_list,
int legacy)
{
char *set_doc;
char *show_doc;
char *cmd_name;
config->name = name;
config->title = title;
config->detect = AUTO_BOOLEAN_AUTO;
config->support = PACKET_SUPPORT_UNKNOWN;
set_doc = xstrprintf ("Set use of remote protocol `%s' (%s) packet",
name, title);
show_doc = xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
name, title);
cmd_name = xstrprintf ("%s-packet", title);
add_setshow_auto_boolean_cmd (cmd_name, class_obscure,
&config->detect, set_doc, show_doc, NULL,
set_func, show_func,
set_remote_list, show_remote_list);
if (legacy)
{
char *legacy_name;
legacy_name = xstrprintf ("%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,
show_remote_list);
}
}
static enum packet_result
packet_ok (const char *buf, struct packet_config *config)
{
if (buf[0] != '\0')
{
switch (config->support)
{
case PACKET_SUPPORT_UNKNOWN:
if (remote_debug)
fprintf_unfiltered (gdb_stdlog,
"Packet %s (%s) is supported\n",
config->name, config->title);
config->support = PACKET_ENABLE;
break;
case PACKET_DISABLE:
internal_error (__FILE__, __LINE__,
_("packet_ok: attempt to use a disabled packet"));
break;
case PACKET_ENABLE:
break;
}
if (buf[0] == 'O' && buf[1] == 'K' && buf[2] == '\0')
return PACKET_OK;
if (buf[0] == 'E'
&& isxdigit (buf[1]) && isxdigit (buf[2])
&& buf[3] == '\0')
return PACKET_ERROR;
return PACKET_OK;
}
else
{
switch (config->support)
{
case PACKET_ENABLE:
if (config->detect == AUTO_BOOLEAN_AUTO)
error (_("Protocol error: %s (%s) conflicting enabled responses."),
config->name, config->title);
else
error (_("Enabled packet %s (%s) not recognized by stub"),
config->name, config->title);
break;
case PACKET_SUPPORT_UNKNOWN:
if (remote_debug)
fprintf_unfiltered (gdb_stdlog,
"Packet %s (%s) is NOT supported\n",
config->name, config->title);
config->support = PACKET_DISABLE;
break;
case PACKET_DISABLE:
break;
}
return PACKET_UNKNOWN;
}
}
static struct packet_config remote_protocol_vcont;
static void
set_remote_protocol_vcont_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_vcont);
}
static void
show_remote_protocol_vcont_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_vcont);
}
static struct packet_config remote_protocol_qSymbol;
static void
set_remote_protocol_qSymbol_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_qSymbol);
}
static void
show_remote_protocol_qSymbol_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_qSymbol);
}
static struct packet_config remote_protocol_P;
static void
set_remote_protocol_P_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_P);
}
static void
show_remote_protocol_P_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_P);
}
enum Z_packet_type
{
Z_PACKET_SOFTWARE_BP,
Z_PACKET_HARDWARE_BP,
Z_PACKET_WRITE_WP,
Z_PACKET_READ_WP,
Z_PACKET_ACCESS_WP,
NR_Z_PACKET_TYPES
};
static struct packet_config remote_protocol_Z[NR_Z_PACKET_TYPES];
static void
set_remote_protocol_Z_software_bp_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP]);
}
static void
show_remote_protocol_Z_software_bp_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP]);
}
static void
set_remote_protocol_Z_hardware_bp_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_Z[Z_PACKET_HARDWARE_BP]);
}
static void
show_remote_protocol_Z_hardware_bp_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_HARDWARE_BP]);
}
static void
set_remote_protocol_Z_write_wp_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_Z[Z_PACKET_WRITE_WP]);
}
static void
show_remote_protocol_Z_write_wp_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_WRITE_WP]);
}
static void
set_remote_protocol_Z_read_wp_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_Z[Z_PACKET_READ_WP]);
}
static void
show_remote_protocol_Z_read_wp_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_READ_WP]);
}
static void
set_remote_protocol_Z_access_wp_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_Z[Z_PACKET_ACCESS_WP]);
}
static void
show_remote_protocol_Z_access_wp_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_Z[Z_PACKET_ACCESS_WP]);
}
static enum auto_boolean remote_Z_packet_detect;
static void
set_remote_protocol_Z_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
int i;
for (i = 0; i < NR_Z_PACKET_TYPES; i++)
{
remote_protocol_Z[i].detect = remote_Z_packet_detect;
update_packet_config (&remote_protocol_Z[i]);
}
}
static void
show_remote_protocol_Z_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
int i;
for (i = 0; i < NR_Z_PACKET_TYPES; i++)
{
show_packet_config_cmd (&remote_protocol_Z[i]);
}
}
static struct packet_config remote_protocol_binary_download;
static int use_threadinfo_query;
static int use_threadextra_query;
static void
set_remote_protocol_binary_download_cmd (char *args,
int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_binary_download);
}
static void
show_remote_protocol_binary_download_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_binary_download);
}
static struct packet_config remote_protocol_qPart_auxv;
static void
set_remote_protocol_qPart_auxv_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_qPart_auxv);
}
static void
show_remote_protocol_qPart_auxv_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_qPart_auxv);
}
static struct packet_config remote_protocol_qGetTLSAddr;
static void
set_remote_protocol_qGetTLSAddr_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_qGetTLSAddr);
}
static void
show_remote_protocol_qGetTLSAddr_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_qGetTLSAddr);
}
static struct packet_config remote_protocol_p;
static void
set_remote_protocol_p_packet_cmd (char *args, int from_tty,
struct cmd_list_element *c)
{
update_packet_config (&remote_protocol_p);
}
static void
show_remote_protocol_p_packet_cmd (struct ui_file *file, int from_tty,
struct cmd_list_element *c,
const char *value)
{
show_packet_config_cmd (&remote_protocol_p);
}
static void *sigint_remote_twice_token;
static void *sigint_remote_token;
void (*deprecated_target_resume_hook) (void);
void (*deprecated_target_wait_loop_hook) (void);
static int general_thread;
static int continue_thread;
static void
record_currthread (int currthread)
{
general_thread = currthread;
if (!in_thread_list (pid_to_ptid (currthread)))
{
add_thread (pid_to_ptid (currthread));
ui_out_text (uiout, "[New ");
ui_out_text (uiout, target_pid_to_str (pid_to_ptid (currthread)));
ui_out_text (uiout, "]\n");
}
}
#define MAGIC_NULL_PID 42000
static void
set_thread (int th, int gen)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
int state = gen ? general_thread : continue_thread;
if (state == th)
return;
buf[0] = 'H';
buf[1] = gen ? 'g' : 'c';
if (th == MAGIC_NULL_PID)
{
buf[2] = '0';
buf[3] = '\0';
}
else if (th < 0)
xsnprintf (&buf[2], rs->remote_packet_size - 2, "-%x", -th);
else
xsnprintf (&buf[2], rs->remote_packet_size - 2, "%x", th);
putpkt (buf);
getpkt (buf, (rs->remote_packet_size), 0);
if (gen)
general_thread = th;
else
continue_thread = th;
}
static int
remote_thread_alive (ptid_t ptid)
{
int tid = PIDGET (ptid);
char buf[16];
if (tid < 0)
xsnprintf (buf, sizeof (buf), "T-%08x", -tid);
else
xsnprintf (buf, sizeof (buf), "T%08x", tid);
putpkt (buf);
getpkt (buf, sizeof (buf), 0);
return (buf[0] == 'O' && buf[1] == 'K');
}
#define OPAQUETHREADBYTES 8
typedef unsigned char threadref[OPAQUETHREADBYTES];
typedef int gdb_threadref;
struct gdb_ext_thread_info
{
threadref threadid;
int active;
char display[256];
char shortname[32];
char more_display[256];
};
#define TAG_THREADID 1
#define TAG_EXISTS 2
#define TAG_DISPLAY 4
#define TAG_THREADNAME 8
#define TAG_MOREDISPLAY 16
#define BUF_THREAD_ID_SIZE (OPAQUETHREADBYTES * 2)
char *unpack_varlen_hex (char *buff, ULONGEST *result);
static char *unpack_nibble (char *buf, int *val);
static char *pack_nibble (char *buf, int nibble);
static char *pack_hex_byte (char *pkt, int byte);
static char *unpack_byte (char *buf, int *value);
static char *pack_int (char *buf, int value);
static char *unpack_int (char *buf, int *value);
static char *unpack_string (char *src, char *dest, int length);
static char *pack_threadid (char *pkt, threadref *id);
static char *unpack_threadid (char *inbuf, threadref *id);
void int_to_threadref (threadref *id, int value);
static int threadref_to_int (threadref *ref);
static void copy_threadref (threadref *dest, threadref *src);
static int threadmatch (threadref *dest, threadref *src);
static char *pack_threadinfo_request (char *pkt, int mode,
threadref *id);
static int remote_unpack_thread_info_response (char *pkt,
threadref *expectedref,
struct gdb_ext_thread_info
*info);
static int remote_get_threadinfo (threadref *threadid,
int fieldset,
struct gdb_ext_thread_info *info);
static char *pack_threadlist_request (char *pkt, int startflag,
int threadcount,
threadref *nextthread);
static int parse_threadlist_response (char *pkt,
int result_limit,
threadref *original_echo,
threadref *resultlist,
int *doneflag);
static int remote_get_threadlist (int startflag,
threadref *nextthread,
int result_limit,
int *done,
int *result_count,
threadref *threadlist);
typedef int (*rmt_thread_action) (threadref *ref, void *context);
static int remote_threadlist_iterator (rmt_thread_action stepfunction,
void *context, int looplimit);
static int remote_newthread_step (threadref *ref, void *context);
static const char hexchars[] = "0123456789abcdef";
static int
ishex (int ch, int *val)
{
if ((ch >= 'a') && (ch <= 'f'))
{
*val = ch - 'a' + 10;
return 1;
}
if ((ch >= 'A') && (ch <= 'F'))
{
*val = ch - 'A' + 10;
return 1;
}
if ((ch >= '0') && (ch <= '9'))
{
*val = ch - '0';
return 1;
}
return 0;
}
static int
stubhex (int ch)
{
if (ch >= 'a' && ch <= 'f')
return ch - 'a' + 10;
if (ch >= '0' && ch <= '9')
return ch - '0';
if (ch >= 'A' && ch <= 'F')
return ch - 'A' + 10;
return -1;
}
static int
stub_unpack_int (char *buff, int fieldlength)
{
int nibble;
int retval = 0;
while (fieldlength)
{
nibble = stubhex (*buff++);
retval |= nibble;
fieldlength--;
if (fieldlength)
retval = retval << 4;
}
return retval;
}
char *
unpack_varlen_hex (char *buff,
ULONGEST *result)
{
int nibble;
int retval = 0;
while (ishex (*buff, &nibble))
{
buff++;
retval = retval << 4;
retval |= nibble & 0x0f;
}
*result = retval;
return buff;
}
static char *
unpack_nibble (char *buf, int *val)
{
ishex (*buf++, val);
return buf;
}
static char *
pack_nibble (char *buf, int nibble)
{
*buf++ = hexchars[(nibble & 0x0f)];
return buf;
}
static char *
pack_hex_byte (char *pkt, int byte)
{
*pkt++ = hexchars[(byte >> 4) & 0xf];
*pkt++ = hexchars[(byte & 0xf)];
return pkt;
}
static char *
unpack_byte (char *buf, int *value)
{
*value = stub_unpack_int (buf, 2);
return buf + 2;
}
static char *
pack_int (char *buf, int value)
{
buf = pack_hex_byte (buf, (value >> 24) & 0xff);
buf = pack_hex_byte (buf, (value >> 16) & 0xff);
buf = pack_hex_byte (buf, (value >> 8) & 0x0ff);
buf = pack_hex_byte (buf, (value & 0xff));
return buf;
}
static char *
unpack_int (char *buf, int *value)
{
*value = stub_unpack_int (buf, 8);
return buf + 8;
}
#if 0
static char *pack_string (char *pkt, char *string);
static char *
pack_string (char *pkt, char *string)
{
char ch;
int len;
len = strlen (string);
if (len > 200)
len = 200;
pkt = pack_hex_byte (pkt, len);
while (len-- > 0)
{
ch = *string++;
if ((ch == '\0') || (ch == '#'))
ch = '*';
*pkt++ = ch;
}
return pkt;
}
#endif
static char *
unpack_string (char *src, char *dest, int length)
{
while (length--)
*dest++ = *src++;
*dest = '\0';
return src;
}
static char *
pack_threadid (char *pkt, threadref *id)
{
char *limit;
unsigned char *altid;
altid = (unsigned char *) id;
limit = pkt + BUF_THREAD_ID_SIZE;
while (pkt < limit)
pkt = pack_hex_byte (pkt, *altid++);
return pkt;
}
static char *
unpack_threadid (char *inbuf, threadref *id)
{
char *altref;
char *limit = inbuf + BUF_THREAD_ID_SIZE;
int x, y;
altref = (char *) id;
while (inbuf < limit)
{
x = stubhex (*inbuf++);
y = stubhex (*inbuf++);
*altref++ = (x << 4) | y;
}
return inbuf;
}
void
int_to_threadref (threadref *id, int value)
{
unsigned char *scan;
scan = (unsigned char *) id;
{
int i = 4;
while (i--)
*scan++ = 0;
}
*scan++ = (value >> 24) & 0xff;
*scan++ = (value >> 16) & 0xff;
*scan++ = (value >> 8) & 0xff;
*scan++ = (value & 0xff);
}
static int
threadref_to_int (threadref *ref)
{
int i, value = 0;
unsigned char *scan;
scan = (char *) ref;
scan += 4;
i = 4;
while (i-- > 0)
value = (value << 8) | ((*scan++) & 0xff);
return value;
}
static void
copy_threadref (threadref *dest, threadref *src)
{
int i;
unsigned char *csrc, *cdest;
csrc = (unsigned char *) src;
cdest = (unsigned char *) dest;
i = 8;
while (i--)
*cdest++ = *csrc++;
}
static int
threadmatch (threadref *dest, threadref *src)
{
#if 0
unsigned char *srcp, *destp;
int i, result;
srcp = (char *) src;
destp = (char *) dest;
result = 1;
while (i-- > 0)
result &= (*srcp++ == *destp++) ? 1 : 0;
return result;
#endif
return 1;
}
static char *
pack_threadinfo_request (char *pkt, int mode, threadref *id)
{
*pkt++ = 'q';
*pkt++ = 'P';
pkt = pack_int (pkt, mode);
pkt = pack_threadid (pkt, id);
*pkt = '\0';
return pkt;
}
#define TAG_THREADID 1
#define TAG_EXISTS 2
#define TAG_DISPLAY 4
#define TAG_THREADNAME 8
#define TAG_MOREDISPLAY 16
static int
remote_unpack_thread_info_response (char *pkt, threadref *expectedref,
struct gdb_ext_thread_info *info)
{
struct remote_state *rs = get_remote_state ();
int mask, length;
unsigned int tag;
threadref ref;
char *limit = pkt + (rs->remote_packet_size);
int retval = 1;
info->active = 0;
info->display[0] = '\0';
info->shortname[0] = '\0';
info->more_display[0] = '\0';
pkt = unpack_int (pkt, &mask);
pkt = unpack_threadid (pkt, &ref);
if (mask == 0)
warning (_("Incomplete response to threadinfo request."));
if (!threadmatch (&ref, expectedref))
{
warning (_("ERROR RMT Thread info mismatch."));
return 0;
}
copy_threadref (&info->threadid, &ref);
while ((pkt < limit) && mask && *pkt)
{
pkt = unpack_int (pkt, &tag);
pkt = unpack_byte (pkt, &length);
if (!(tag & mask))
{
warning (_("ERROR RMT: threadinfo tag mismatch."));
retval = 0;
break;
}
if (tag == TAG_THREADID)
{
if (length != 16)
{
warning (_("ERROR RMT: length of threadid is not 16."));
retval = 0;
break;
}
pkt = unpack_threadid (pkt, &ref);
mask = mask & ~TAG_THREADID;
continue;
}
if (tag == TAG_EXISTS)
{
info->active = stub_unpack_int (pkt, length);
pkt += length;
mask = mask & ~(TAG_EXISTS);
if (length > 8)
{
warning (_("ERROR RMT: 'exists' length too long."));
retval = 0;
break;
}
continue;
}
if (tag == TAG_THREADNAME)
{
pkt = unpack_string (pkt, &info->shortname[0], length);
mask = mask & ~TAG_THREADNAME;
continue;
}
if (tag == TAG_DISPLAY)
{
pkt = unpack_string (pkt, &info->display[0], length);
mask = mask & ~TAG_DISPLAY;
continue;
}
if (tag == TAG_MOREDISPLAY)
{
pkt = unpack_string (pkt, &info->more_display[0], length);
mask = mask & ~TAG_MOREDISPLAY;
continue;
}
warning (_("ERROR RMT: unknown thread info tag."));
break;
}
return retval;
}
static int
remote_get_threadinfo (threadref *threadid, int fieldset,
struct gdb_ext_thread_info *info)
{
struct remote_state *rs = get_remote_state ();
int result;
char *threadinfo_pkt = alloca (rs->remote_packet_size);
pack_threadinfo_request (threadinfo_pkt, fieldset, threadid);
putpkt (threadinfo_pkt);
getpkt (threadinfo_pkt, (rs->remote_packet_size), 0);
result = remote_unpack_thread_info_response (threadinfo_pkt + 2,
threadid, info);
return result;
}
static char *
pack_threadlist_request (char *pkt, int startflag, int threadcount,
threadref *nextthread)
{
*pkt++ = 'q';
*pkt++ = 'L';
pkt = pack_nibble (pkt, startflag);
pkt = pack_hex_byte (pkt, threadcount);
pkt = pack_threadid (pkt, nextthread);
*pkt = '\0';
return pkt;
}
static int
parse_threadlist_response (char *pkt, int result_limit,
threadref *original_echo, threadref *resultlist,
int *doneflag)
{
struct remote_state *rs = get_remote_state ();
char *limit;
int count, resultcount, done;
resultcount = 0;
limit = pkt + ((rs->remote_packet_size) - BUF_THREAD_ID_SIZE);
pkt = unpack_byte (pkt, &count);
pkt = unpack_nibble (pkt, &done);
pkt = unpack_threadid (pkt, original_echo);
while ((count-- > 0) && (pkt < limit))
{
pkt = unpack_threadid (pkt, resultlist++);
if (resultcount++ >= result_limit)
break;
}
if (doneflag)
*doneflag = done;
return resultcount;
}
static int
remote_get_threadlist (int startflag, threadref *nextthread, int result_limit,
int *done, int *result_count, threadref *threadlist)
{
struct remote_state *rs = get_remote_state ();
static threadref echo_nextthread;
char *threadlist_packet = alloca (rs->remote_packet_size);
char *t_response = alloca (rs->remote_packet_size);
int result = 1;
if ((((result_limit + 1) * BUF_THREAD_ID_SIZE) + 10) >= (rs->remote_packet_size))
result_limit = ((rs->remote_packet_size) / BUF_THREAD_ID_SIZE) - 2;
pack_threadlist_request (threadlist_packet,
startflag, result_limit, nextthread);
putpkt (threadlist_packet);
getpkt (t_response, (rs->remote_packet_size), 0);
*result_count =
parse_threadlist_response (t_response + 2, result_limit, &echo_nextthread,
threadlist, done);
if (!threadmatch (&echo_nextthread, nextthread))
{
warning (_("HMM: threadlist did not echo arg thread, dropping it."));
return 0;
}
if (*result_count <= 0)
{
if (*done != 1)
{
warning (_("RMT ERROR : failed to get remote thread list."));
result = 0;
}
return result;
}
if (*result_count > result_limit)
{
*result_count = 0;
warning (_("RMT ERROR: threadlist response longer than requested."));
return 0;
}
return result;
}
#define MAXTHREADLISTRESULTS 32
static int
remote_threadlist_iterator (rmt_thread_action stepfunction, void *context,
int looplimit)
{
int done, i, result_count;
int startflag = 1;
int result = 1;
int loopcount = 0;
static threadref nextthread;
static threadref resultthreadlist[MAXTHREADLISTRESULTS];
done = 0;
while (!done)
{
if (loopcount++ > looplimit)
{
result = 0;
warning (_("Remote fetch threadlist -infinite loop-."));
break;
}
if (!remote_get_threadlist (startflag, &nextthread, MAXTHREADLISTRESULTS,
&done, &result_count, resultthreadlist))
{
result = 0;
break;
}
startflag = 0;
if (result_count >= 1)
copy_threadref (&nextthread, &resultthreadlist[result_count - 1]);
i = 0;
while (result_count--)
if (!(result = (*stepfunction) (&resultthreadlist[i++], context)))
break;
}
return result;
}
static int
remote_newthread_step (threadref *ref, void *context)
{
ptid_t ptid;
ptid = pid_to_ptid (threadref_to_int (ref));
if (!in_thread_list (ptid))
add_thread (ptid);
return 1;
}
#define CRAZY_MAX_THREADS 1000
static ptid_t
remote_current_thread (ptid_t oldpid)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
putpkt ("qC");
getpkt (buf, (rs->remote_packet_size), 0);
if (buf[0] == 'Q' && buf[1] == 'C')
return pid_to_ptid (strtoul (&buf[2], NULL, 16));
else
return oldpid;
}
static void
remote_find_new_threads (void)
{
remote_threadlist_iterator (remote_newthread_step, 0,
CRAZY_MAX_THREADS);
if (PIDGET (inferior_ptid) == MAGIC_NULL_PID)
inferior_ptid = remote_current_thread (inferior_ptid);
}
static void
remote_threads_info (void)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
char *bufp;
int tid;
if (remote_desc == 0)
error (_("Command can only be used when connected to the remote target."));
if (use_threadinfo_query)
{
putpkt ("qfThreadInfo");
bufp = buf;
getpkt (bufp, (rs->remote_packet_size), 0);
if (bufp[0] != '\0')
{
while (*bufp++ == 'm')
{
do
{
tid = strtoul (bufp, &bufp, 16);
if (tid != 0 && !in_thread_list (pid_to_ptid (tid)))
add_thread (pid_to_ptid (tid));
}
while (*bufp++ == ',');
putpkt ("qsThreadInfo");
bufp = buf;
getpkt (bufp, (rs->remote_packet_size), 0);
}
return;
}
}
use_threadinfo_query = 0;
remote_find_new_threads ();
return;
}
static char *
remote_threads_extra_info (struct thread_info *tp)
{
struct remote_state *rs = get_remote_state ();
int result;
int set;
threadref id;
struct gdb_ext_thread_info threadinfo;
static char display_buf[100];
char *bufp = alloca (rs->remote_packet_size);
int n = 0;
if (remote_desc == 0)
internal_error (__FILE__, __LINE__,
_("remote_threads_extra_info"));
if (use_threadextra_query)
{
xsnprintf (bufp, rs->remote_packet_size, "qThreadExtraInfo,%x",
PIDGET (tp->ptid));
putpkt (bufp);
getpkt (bufp, (rs->remote_packet_size), 0);
if (bufp[0] != 0)
{
n = min (strlen (bufp) / 2, sizeof (display_buf));
result = hex2bin (bufp, display_buf, n);
display_buf [result] = '\0';
return display_buf;
}
}
use_threadextra_query = 0;
set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
| TAG_MOREDISPLAY | TAG_DISPLAY;
int_to_threadref (&id, PIDGET (tp->ptid));
if (remote_get_threadinfo (&id, set, &threadinfo))
if (threadinfo.active)
{
if (*threadinfo.shortname)
n += xsnprintf (&display_buf[0], sizeof (display_buf) - n,
" Name: %s,", threadinfo.shortname);
if (*threadinfo.display)
n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
" State: %s,", threadinfo.display);
if (*threadinfo.more_display)
n += xsnprintf (&display_buf[n], sizeof (display_buf) - n,
" Priority: %s", threadinfo.more_display);
if (n > 0)
{
if (',' == display_buf[n-1])
display_buf[n-1] = ' ';
return display_buf;
}
}
return NULL;
}
static void
extended_remote_restart (void)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
xsnprintf (buf, rs->remote_packet_size, "R%x", 0);
putpkt (buf);
putpkt ("?");
getpkt (buf, (rs->remote_packet_size), 0);
}
static void
remote_close (int quitting)
{
if (remote_desc)
serial_close (remote_desc);
remote_desc = NULL;
}
static void
get_offsets (void)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
char *ptr;
int lose;
CORE_ADDR text_addr, data_addr, bss_addr;
struct section_offsets *offs;
putpkt ("qOffsets");
getpkt (buf, (rs->remote_packet_size), 0);
if (buf[0] == '\000')
return;
if (buf[0] == 'E')
{
warning (_("Remote failure reply: %s"), buf);
return;
}
text_addr = data_addr = bss_addr = 0;
ptr = buf;
lose = 0;
if (strncmp (ptr, "Text=", 5) == 0)
{
ptr += 5;
while (*ptr && *ptr != ';')
text_addr = (text_addr << 4) + fromhex (*ptr++);
}
else
lose = 1;
if (!lose && strncmp (ptr, ";Data=", 6) == 0)
{
ptr += 6;
while (*ptr && *ptr != ';')
data_addr = (data_addr << 4) + fromhex (*ptr++);
}
else
lose = 1;
if (!lose && strncmp (ptr, ";Bss=", 5) == 0)
{
ptr += 5;
while (*ptr && *ptr != ';')
bss_addr = (bss_addr << 4) + fromhex (*ptr++);
}
else
lose = 1;
if (lose)
error (_("Malformed response to offset query, %s"), buf);
if (symfile_objfile == NULL)
return;
offs = ((struct section_offsets *)
alloca (SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections)));
memcpy (offs, symfile_objfile->section_offsets,
SIZEOF_N_SECTION_OFFSETS (symfile_objfile->num_sections));
offs->offsets[SECT_OFF_TEXT (symfile_objfile)] = text_addr;
offs->offsets[SECT_OFF_DATA (symfile_objfile)] = data_addr;
offs->offsets[SECT_OFF_BSS (symfile_objfile)] = data_addr;
objfile_relocate (symfile_objfile, offs);
}
static int
remote_start_remote_dummy (struct ui_out *uiout, void *dummy)
{
start_remote ();
return 1;
}
static void
remote_start_remote (struct ui_out *uiout, void *dummy)
{
immediate_quit++;
serial_write (remote_desc, "+", 1);
set_thread (-1, 0);
inferior_ptid = remote_current_thread (inferior_ptid);
get_offsets ();
putpkt ("?");
immediate_quit--;
remote_start_remote_dummy (uiout, dummy);
}
static void
remote_open (char *name, int from_tty)
{
remote_open_1 (name, from_tty, &remote_ops, 0, 0);
}
static void
remote_async_open (char *name, int from_tty)
{
remote_open_1 (name, from_tty, &remote_async_ops, 0, 1);
}
static void
extended_remote_open (char *name, int from_tty)
{
remote_open_1 (name, from_tty, &extended_remote_ops, 1 ,
0 );
}
static void
extended_remote_async_open (char *name, int from_tty)
{
remote_open_1 (name, from_tty, &extended_async_remote_ops,
1 , 1 );
}
static void
init_all_packet_configs (void)
{
int i;
update_packet_config (&remote_protocol_P);
update_packet_config (&remote_protocol_p);
update_packet_config (&remote_protocol_qSymbol);
update_packet_config (&remote_protocol_vcont);
for (i = 0; i < NR_Z_PACKET_TYPES; i++)
update_packet_config (&remote_protocol_Z[i]);
update_packet_config (&remote_protocol_binary_download);
update_packet_config (&remote_protocol_qPart_auxv);
update_packet_config (&remote_protocol_qGetTLSAddr);
}
static void
remote_check_symbols (struct objfile *objfile)
{
struct remote_state *rs = get_remote_state ();
char *msg, *reply, *tmp;
struct minimal_symbol *sym;
int end;
if (remote_protocol_qSymbol.support == PACKET_DISABLE)
return;
msg = alloca (rs->remote_packet_size);
reply = alloca (rs->remote_packet_size);
putpkt ("qSymbol::");
getpkt (reply, (rs->remote_packet_size), 0);
packet_ok (reply, &remote_protocol_qSymbol);
while (strncmp (reply, "qSymbol:", 8) == 0)
{
tmp = &reply[8];
end = hex2bin (tmp, msg, strlen (tmp) / 2);
msg[end] = '\0';
sym = lookup_minimal_symbol (msg, NULL, NULL);
if (sym == NULL)
xsnprintf (msg, rs->remote_packet_size, "qSymbol::%s", &reply[8]);
else
xsnprintf (msg, rs->remote_packet_size, "qSymbol:%s:%s",
paddr_nz (SYMBOL_VALUE_ADDRESS (sym)),
&reply[8]);
putpkt (msg);
getpkt (reply, (rs->remote_packet_size), 0);
}
}
static struct serial *
remote_serial_open (char *name)
{
static int udp_warning = 0;
if (!udp_warning && strncmp (name, "udp:", 4) == 0)
{
warning (_("\
The remote protocol may be unreliable over UDP.\n\
Some events may be lost, rendering further debugging impossible."));
udp_warning = 1;
}
return serial_open (name);
}
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.)."));
if (!async_p)
wait_forever_enabled_p = 1;
reopen_exec_file ();
reread_symbols ();
target_preopen (from_tty);
unpush_target (target);
remote_desc = remote_serial_open (name);
if (!remote_desc)
perror_with_name (name);
if (baud_rate != -1)
{
if (serial_setbaudrate (remote_desc, baud_rate))
{
serial_close (remote_desc);
remote_desc = NULL;
perror_with_name (name);
}
}
serial_raw (remote_desc);
serial_flush_input (remote_desc);
if (from_tty)
{
puts_filtered ("Remote debugging using ");
puts_filtered (name);
puts_filtered ("\n");
}
push_target (target);
init_all_packet_configs ();
general_thread = -2;
continue_thread = -2;
use_threadinfo_query = 1;
use_threadextra_query = 1;
inferior_ptid = pid_to_ptid (MAGIC_NULL_PID);
if (async_p)
{
remote_async_terminal_ours_p = 1;
wait_forever_enabled_p = 0;
}
no_shared_libraries (NULL, 0);
{
struct gdb_exception ex
= catch_exception (uiout, remote_start_remote, NULL, RETURN_MASK_ALL);
if (ex.reason < 0)
{
pop_target ();
if (async_p)
wait_forever_enabled_p = 1;
throw_exception (ex);
}
}
if (async_p)
wait_forever_enabled_p = 1;
if (extended_p)
{
char *buf = alloca (rs->remote_packet_size);
putpkt ("!");
getpkt (buf, (rs->remote_packet_size), 0);
}
if (exec_bfd)
{
#ifdef SOLIB_CREATE_INFERIOR_HOOK
SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
#else
solib_create_inferior_hook ();
#endif
remote_check_symbols (symfile_objfile);
}
observer_notify_inferior_created (¤t_target, from_tty);
}
static void
remote_detach (char *args, int from_tty)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
if (args)
error (_("Argument given to \"detach\" when remotely debugging."));
strcpy (buf, "D");
remote_send (buf, (rs->remote_packet_size));
if (target_is_async_p ())
serial_async (remote_desc, NULL, 0);
target_mourn_inferior ();
if (from_tty)
puts_filtered ("Ending remote debugging.\n");
}
static void
remote_disconnect (char *args, int from_tty)
{
if (args)
error (_("Argument given to \"detach\" when remotely debugging."));
if (target_is_async_p ())
serial_async (remote_desc, NULL, 0);
target_mourn_inferior ();
if (from_tty)
puts_filtered ("Ending remote debugging.\n");
}
static int
fromhex (int a)
{
if (a >= '0' && a <= '9')
return a - '0';
else if (a >= 'a' && a <= 'f')
return a - 'a' + 10;
else if (a >= 'A' && a <= 'F')
return a - 'A' + 10;
else
error (_("Reply contains invalid hex digit %d"), a);
}
static int
hex2bin (const char *hex, char *bin, int count)
{
int i;
for (i = 0; i < count; i++)
{
if (hex[0] == 0 || hex[1] == 0)
{
return i;
}
*bin++ = fromhex (hex[0]) * 16 + fromhex (hex[1]);
hex += 2;
}
return i;
}
static int
tohex (int nib)
{
if (nib < 10)
return '0' + nib;
else
return 'a' + nib - 10;
}
static int
bin2hex (const char *bin, char *hex, int count)
{
int i;
if (count == 0)
count = strlen (bin);
for (i = 0; i < count; i++)
{
*hex++ = tohex ((*bin >> 4) & 0xf);
*hex++ = tohex (*bin++ & 0xf);
}
*hex = 0;
return i;
}
static void
remote_vcont_probe (struct remote_state *rs, char *buf)
{
strcpy (buf, "vCont?");
putpkt (buf);
getpkt (buf, rs->remote_packet_size, 0);
if (strncmp (buf, "vCont", 5) == 0)
{
char *p = &buf[5];
int support_s, support_S, support_c, support_C;
support_s = 0;
support_S = 0;
support_c = 0;
support_C = 0;
while (p && *p == ';')
{
p++;
if (*p == 's' && (*(p + 1) == ';' || *(p + 1) == 0))
support_s = 1;
else if (*p == 'S' && (*(p + 1) == ';' || *(p + 1) == 0))
support_S = 1;
else if (*p == 'c' && (*(p + 1) == ';' || *(p + 1) == 0))
support_c = 1;
else if (*p == 'C' && (*(p + 1) == ';' || *(p + 1) == 0))
support_C = 1;
p = strchr (p, ';');
}
if (!support_s || !support_S || !support_c || !support_C)
buf[0] = 0;
}
packet_ok (buf, &remote_protocol_vcont);
}
static int
remote_vcont_resume (ptid_t ptid, int step, enum target_signal siggnal)
{
struct remote_state *rs = get_remote_state ();
int pid = PIDGET (ptid);
char *buf = NULL, *outbuf;
struct cleanup *old_cleanup;
buf = xmalloc (rs->remote_packet_size);
old_cleanup = make_cleanup (xfree, buf);
if (remote_protocol_vcont.support == PACKET_SUPPORT_UNKNOWN)
remote_vcont_probe (rs, buf);
if (remote_protocol_vcont.support == PACKET_DISABLE)
{
do_cleanups (old_cleanup);
return 0;
}
if (PIDGET (inferior_ptid) == MAGIC_NULL_PID)
{
if (step && siggnal != TARGET_SIGNAL_0)
outbuf = xstrprintf ("vCont;S%02x", siggnal);
else if (step)
outbuf = xstrprintf ("vCont;s");
else if (siggnal != TARGET_SIGNAL_0)
outbuf = xstrprintf ("vCont;C%02x", siggnal);
else
outbuf = xstrprintf ("vCont;c");
}
else if (pid == -1)
{
if (step && siggnal != TARGET_SIGNAL_0)
outbuf = xstrprintf ("vCont;S%02x:%x;c", siggnal,
PIDGET (inferior_ptid));
else if (step)
outbuf = xstrprintf ("vCont;s:%x;c", PIDGET (inferior_ptid));
else if (siggnal != TARGET_SIGNAL_0)
outbuf = xstrprintf ("vCont;C%02x:%x;c", siggnal,
PIDGET (inferior_ptid));
else
outbuf = xstrprintf ("vCont;c");
}
else
{
if (step && siggnal != TARGET_SIGNAL_0)
outbuf = xstrprintf ("vCont;S%02x:%x", siggnal, pid);
else if (step)
outbuf = xstrprintf ("vCont;s:%x", pid);
else if (siggnal != TARGET_SIGNAL_0)
outbuf = xstrprintf ("vCont;C%02x:%x", siggnal, pid);
else
outbuf = xstrprintf ("vCont;c:%x", pid);
}
gdb_assert (outbuf && strlen (outbuf) < rs->remote_packet_size);
make_cleanup (xfree, outbuf);
putpkt (outbuf);
do_cleanups (old_cleanup);
return 1;
}
static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
static int last_sent_step;
static void
remote_resume (ptid_t ptid, int step, enum target_signal siggnal)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
int pid = PIDGET (ptid);
last_sent_signal = siggnal;
last_sent_step = step;
if (deprecated_target_resume_hook)
(*deprecated_target_resume_hook) ();
if (remote_vcont_resume (ptid, step, siggnal))
return;
if (pid == -1)
set_thread (0, 0);
else
set_thread (pid, 0);
if (siggnal != TARGET_SIGNAL_0)
{
buf[0] = step ? 'S' : 'C';
buf[1] = tohex (((int) siggnal >> 4) & 0xf);
buf[2] = tohex (((int) siggnal) & 0xf);
buf[3] = '\0';
}
else
strcpy (buf, step ? "s" : "c");
putpkt (buf);
}
static void
remote_async_resume (ptid_t ptid, int step, enum target_signal siggnal)
{
remote_resume (ptid, step, siggnal);
if (target_can_async_p ())
target_async (inferior_event_handler, 0);
if (target_is_async_p ())
target_executing = 1;
}
static void
initialize_sigint_signal_handler (void)
{
sigint_remote_token =
create_async_signal_handler (async_remote_interrupt, NULL);
signal (SIGINT, handle_remote_sigint);
}
static void
handle_remote_sigint (int sig)
{
signal (sig, handle_remote_sigint_twice);
sigint_remote_twice_token =
create_async_signal_handler (async_remote_interrupt_twice, NULL);
mark_async_signal_handler_wrapper (sigint_remote_token);
}
static void
handle_remote_sigint_twice (int sig)
{
signal (sig, handle_sigint);
sigint_remote_twice_token =
create_async_signal_handler (inferior_event_handler_wrapper, NULL);
mark_async_signal_handler_wrapper (sigint_remote_twice_token);
}
static void
async_remote_interrupt (gdb_client_data arg)
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
target_stop ();
}
void
async_remote_interrupt_twice (gdb_client_data arg)
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "remote_interrupt_twice called\n");
if (target_executing)
{
interrupt_query ();
signal (SIGINT, handle_remote_sigint);
}
}
static void
cleanup_sigint_signal_handler (void *dummy)
{
signal (SIGINT, handle_sigint);
if (sigint_remote_twice_token)
delete_async_signal_handler ((struct async_signal_handler **)
&sigint_remote_twice_token);
if (sigint_remote_token)
delete_async_signal_handler ((struct async_signal_handler **)
&sigint_remote_token);
}
static void (*ofunc) (int);
static void
remote_interrupt (int signo)
{
signal (signo, remote_interrupt_twice);
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
target_stop ();
}
static void
remote_interrupt_twice (int signo)
{
signal (signo, ofunc);
interrupt_query ();
signal (signo, remote_interrupt);
}
static void
remote_stop (void)
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
if (remote_break)
serial_send_break (remote_desc);
else
serial_write (remote_desc, "\003", 1);
}
static void
interrupt_query (void)
{
target_terminal_ours ();
if (query ("Interrupted while waiting for the program.\n\
Give up (and stop debugging it)? "))
{
target_mourn_inferior ();
deprecated_throw_reason (RETURN_QUIT);
}
target_terminal_inferior ();
}
static void
remote_async_terminal_inferior (void)
{
if (!sync_execution)
return;
if (!remote_async_terminal_ours_p)
return;
delete_file_handler (input_fd);
remote_async_terminal_ours_p = 0;
initialize_sigint_signal_handler ();
}
static void
remote_async_terminal_ours (void)
{
if (!sync_execution)
return;
if (remote_async_terminal_ours_p)
return;
cleanup_sigint_signal_handler (NULL);
add_file_handler (input_fd, stdin_event_handler, 0);
remote_async_terminal_ours_p = 1;
}
int kill_kludge;
void
remote_console_output (char *msg)
{
char *p;
for (p = msg; p[0] && p[1]; p += 2)
{
char tb[2];
char c = fromhex (p[0]) * 16 + fromhex (p[1]);
tb[0] = c;
tb[1] = 0;
fputs_unfiltered (tb, gdb_stdtarg);
}
gdb_flush (gdb_stdtarg);
}
static ptid_t
remote_wait (ptid_t ptid, struct target_waitstatus *status)
{
struct remote_state *rs = get_remote_state ();
unsigned char *buf = alloca (rs->remote_packet_size);
ULONGEST thread_num = -1;
ULONGEST addr;
status->kind = TARGET_WAITKIND_EXITED;
status->value.integer = 0;
while (1)
{
unsigned char *p;
ofunc = signal (SIGINT, remote_interrupt);
getpkt (buf, (rs->remote_packet_size), 1);
signal (SIGINT, ofunc);
if (deprecated_target_wait_loop_hook)
(*deprecated_target_wait_loop_hook) ();
remote_stopped_by_watchpoint_p = 0;
switch (buf[0])
{
case 'E':
warning (_("Remote failure reply: %s"), buf);
continue;
case 'F':
remote_fileio_request (buf);
continue;
case 'T':
{
char regs[MAX_REGISTER_SIZE];
p = &buf[3];
while (*p)
{
unsigned char *p1;
char *p_temp;
int fieldsize;
LONGEST pnum = 0;
if (strncmp (p, "awatch", strlen("awatch")) != 0)
{
pnum = strtol (p, &p_temp, 16);
p1 = (unsigned char *) p_temp;
}
else
p1 = p;
if (p1 == p)
{
p1 = (unsigned char *) strchr (p, ':');
if (p1 == NULL)
warning (_("Malformed packet(a) (missing colon): %s\n\
Packet: '%s'\n"),
p, buf);
if (strncmp (p, "thread", p1 - p) == 0)
{
p_temp = unpack_varlen_hex (++p1, &thread_num);
record_currthread (thread_num);
p = (unsigned char *) p_temp;
}
else if ((strncmp (p, "watch", p1 - p) == 0)
|| (strncmp (p, "rwatch", p1 - p) == 0)
|| (strncmp (p, "awatch", p1 - p) == 0))
{
remote_stopped_by_watchpoint_p = 1;
p = unpack_varlen_hex (++p1, &addr);
remote_watch_data_address = (CORE_ADDR)addr;
}
else
{
p_temp = strchr (p1 + 1, ';');
if (p_temp)
p = (unsigned char *) p_temp;
}
}
else
{
struct packet_reg *reg = packet_reg_from_pnum (rs, pnum);
p = p1;
if (*p++ != ':')
error (_("Malformed packet(b) (missing colon): %s\n\
Packet: '%s'\n"),
p, buf);
if (reg == NULL)
error (_("Remote sent bad register number %s: %s\n\
Packet: '%s'\n"),
phex_nz (pnum, 0), p, buf);
fieldsize = hex2bin (p, regs,
register_size (current_gdbarch,
reg->regnum));
p += 2 * fieldsize;
if (fieldsize < register_size (current_gdbarch,
reg->regnum))
warning (_("Remote reply is too short: %s"), buf);
regcache_raw_supply (current_regcache,
reg->regnum, regs);
}
if (*p++ != ';')
error (_("Remote register badly formatted: %s\nhere: %s"),
buf, p);
}
}
case 'S':
status->kind = TARGET_WAITKIND_STOPPED;
status->value.sig = (enum target_signal)
(((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
if (buf[3] == 'p')
{
thread_num = strtol ((const char *) &buf[4], NULL, 16);
record_currthread (thread_num);
}
goto got_status;
case 'W':
{
status->kind = TARGET_WAITKIND_EXITED;
status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
goto got_status;
}
case 'X':
status->kind = TARGET_WAITKIND_SIGNALLED;
status->value.sig = (enum target_signal)
(((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
kill_kludge = 1;
goto got_status;
case 'O':
remote_console_output (buf + 1);
continue;
case '\0':
if (last_sent_signal != TARGET_SIGNAL_0)
{
target_terminal_ours_for_output ();
printf_filtered
("Can't send signals to this remote system. %s not sent.\n",
target_signal_to_name (last_sent_signal));
last_sent_signal = TARGET_SIGNAL_0;
target_terminal_inferior ();
strcpy ((char *) buf, last_sent_step ? "s" : "c");
putpkt ((char *) buf);
continue;
}
default:
warning (_("Invalid remote reply: %s"), buf);
continue;
}
}
got_status:
if (thread_num != -1)
{
return pid_to_ptid (thread_num);
}
return inferior_ptid;
}
static ptid_t
remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
{
struct remote_state *rs = get_remote_state ();
unsigned char *buf = alloca (rs->remote_packet_size);
ULONGEST thread_num = -1;
ULONGEST addr;
status->kind = TARGET_WAITKIND_EXITED;
status->value.integer = 0;
remote_stopped_by_watchpoint_p = 0;
while (1)
{
unsigned char *p;
if (!target_is_async_p ())
ofunc = signal (SIGINT, remote_interrupt);
getpkt (buf, (rs->remote_packet_size), wait_forever_enabled_p);
if (!target_is_async_p ())
signal (SIGINT, ofunc);
if (deprecated_target_wait_loop_hook)
(*deprecated_target_wait_loop_hook) ();
switch (buf[0])
{
case 'E':
warning (_("Remote failure reply: %s"), buf);
continue;
case 'F':
remote_fileio_request (buf);
continue;
case 'T':
{
char regs[MAX_REGISTER_SIZE];
p = &buf[3];
while (*p)
{
unsigned char *p1;
char *p_temp;
int fieldsize;
long pnum = 0;
if (!strncmp (p, "awatch", strlen ("awatch")) != 0)
{
pnum = strtol (p, &p_temp, 16);
p1 = (unsigned char *) p_temp;
}
else
p1 = p;
if (p1 == p)
{
p1 = (unsigned char *) strchr (p, ':');
if (p1 == NULL)
error (_("Malformed packet(a) (missing colon): %s\n\
Packet: '%s'\n"),
p, buf);
if (strncmp (p, "thread", p1 - p) == 0)
{
p_temp = unpack_varlen_hex (++p1, &thread_num);
record_currthread (thread_num);
p = (unsigned char *) p_temp;
}
else if ((strncmp (p, "watch", p1 - p) == 0)
|| (strncmp (p, "rwatch", p1 - p) == 0)
|| (strncmp (p, "awatch", p1 - p) == 0))
{
remote_stopped_by_watchpoint_p = 1;
p = unpack_varlen_hex (++p1, &addr);
remote_watch_data_address = (CORE_ADDR)addr;
}
else
{
p_temp = (unsigned char *) strchr (p1 + 1, ';');
if (p_temp)
p = p_temp;
}
}
else
{
struct packet_reg *reg = packet_reg_from_pnum (rs, pnum);
p = p1;
if (*p++ != ':')
error (_("Malformed packet(b) (missing colon): %s\n\
Packet: '%s'\n"),
p, buf);
if (reg == NULL)
error (_("Remote sent bad register number %ld: %s\n\
Packet: '%s'\n"),
pnum, p, buf);
fieldsize = hex2bin (p, regs,
register_size (current_gdbarch,
reg->regnum));
p += 2 * fieldsize;
if (fieldsize < register_size (current_gdbarch,
reg->regnum))
warning (_("Remote reply is too short: %s"), buf);
regcache_raw_supply (current_regcache, reg->regnum, regs);
}
if (*p++ != ';')
error (_("Remote register badly formatted: %s\nhere: %s"),
buf, p);
}
}
case 'S':
status->kind = TARGET_WAITKIND_STOPPED;
status->value.sig = (enum target_signal)
(((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
if (buf[3] == 'p')
{
thread_num = strtol ((const char *) &buf[4], NULL, 16);
record_currthread (thread_num);
}
goto got_status;
case 'W':
{
status->kind = TARGET_WAITKIND_EXITED;
status->value.integer = (fromhex (buf[1]) << 4) + fromhex (buf[2]);
goto got_status;
}
case 'X':
status->kind = TARGET_WAITKIND_SIGNALLED;
status->value.sig = (enum target_signal)
(((fromhex (buf[1])) << 4) + (fromhex (buf[2])));
kill_kludge = 1;
goto got_status;
case 'O':
remote_console_output (buf + 1);
status->kind = TARGET_WAITKIND_IGNORE;
goto got_status;
case '\0':
if (last_sent_signal != TARGET_SIGNAL_0)
{
target_terminal_ours_for_output ();
printf_filtered
("Can't send signals to this remote system. %s not sent.\n",
target_signal_to_name (last_sent_signal));
last_sent_signal = TARGET_SIGNAL_0;
target_terminal_inferior ();
strcpy ((char *) buf, last_sent_step ? "s" : "c");
putpkt ((char *) buf);
continue;
}
default:
warning (_("Invalid remote reply: %s"), buf);
continue;
}
}
got_status:
if (thread_num != -1)
{
return pid_to_ptid (thread_num);
}
return inferior_ptid;
}
static int register_bytes_found;
static int
fetch_register_using_p (int regnum)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size), *p;
char regp[MAX_REGISTER_SIZE];
int i;
p = buf;
*p++ = 'p';
p += hexnumstr (p, regnum);
*p++ = '\0';
remote_send (buf, rs->remote_packet_size);
if (buf[0] == '\0' || buf[0] == 'E')
return 0;
if (buf[0] == 'x')
{
regcache_raw_supply (current_regcache, regnum, NULL);
set_register_cached (regnum, -1);
return 1;
}
p = buf;
i = 0;
while (p[0] != 0)
{
if (p[1] == 0)
{
error (_("fetch_register_using_p: early buf termination"));
return 0;
}
regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]);
p += 2;
}
regcache_raw_supply (current_regcache, regnum, regp);
return 1;
}
static void
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 (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."));
}
switch (remote_protocol_p.support)
{
case PACKET_DISABLE:
break;
case PACKET_ENABLE:
if (fetch_register_using_p (regnum))
return;
else
error (_("Protocol error: p packet not recognized by stub"));
case PACKET_SUPPORT_UNKNOWN:
if (fetch_register_using_p (regnum))
{
remote_protocol_p.support = PACKET_ENABLE;
return;
}
else
{
remote_protocol_p.support = PACKET_DISABLE;
break;
}
}
sprintf (buf, "g");
remote_send (buf, (rs->remote_packet_size));
if ((rs->actual_register_packet_size) == 0)
(rs->actual_register_packet_size) = strlen (buf);
memset (regs, 0, rs->sizeof_g_packet);
while ((buf[0] < '0' || buf[0] > '9')
&& (buf[0] < 'A' || buf[0] > 'F')
&& (buf[0] < 'a' || buf[0] > 'f')
&& buf[0] != 'x')
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog,
"Bad register packet; fetching a new packet\n");
getpkt (buf, (rs->remote_packet_size), 0);
}
p = buf;
for (i = 0; i < rs->sizeof_g_packet; i++)
{
if (p[0] == 0)
break;
if (p[1] == 0)
{
warning (_("Remote reply is of odd length: %s"), buf);
goto supply_them;
}
if (p[0] == 'x' && p[1] == 'x')
regs[i] = 0;
else
regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
p += 2;
}
if (i != register_bytes_found)
{
register_bytes_found = i;
if (REGISTER_BYTES_OK_P ()
&& !REGISTER_BYTES_OK (i))
warning (_("Remote reply is too short: %s"), buf);
}
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)
{
if (r->offset * 2 >= strlen (buf))
regcache_raw_supply (current_regcache, r->regnum, NULL);
else if (buf[r->offset * 2] == 'x')
{
gdb_assert (r->offset * 2 < strlen (buf));
regcache_raw_supply (current_regcache, r->regnum, NULL);
set_register_cached (i, -1);
}
else
regcache_raw_supply (current_regcache, r->regnum,
regs + r->offset);
}
}
}
}
static void
remote_prepare_to_store (void)
{
struct remote_state *rs = get_remote_state ();
int i;
char buf[MAX_REGISTER_SIZE];
switch (remote_protocol_P.support)
{
case PACKET_DISABLE:
case PACKET_SUPPORT_UNKNOWN:
for (i = 0; i < NUM_REGS; i++)
if (rs->regs[i].in_g_packet)
regcache_raw_read (current_regcache, rs->regs[i].regnum, buf);
break;
case PACKET_ENABLE:
break;
}
}
static int
store_register_using_P (int regnum)
{
struct remote_state *rs = get_remote_state ();
struct packet_reg *reg = packet_reg_from_regnum (rs, regnum);
char *buf = alloca (rs->remote_packet_size);
char regp[MAX_REGISTER_SIZE];
char *p;
xsnprintf (buf, rs->remote_packet_size, "P%s=", phex_nz (reg->pnum, 0));
p = buf + strlen (buf);
regcache_raw_collect (current_regcache, reg->regnum, regp);
bin2hex (regp, p, register_size (current_gdbarch, reg->regnum));
remote_send (buf, rs->remote_packet_size);
return buf[0] != '\0';
}
static void
remote_store_registers (int regnum)
{
struct remote_state *rs = get_remote_state ();
char *buf;
char *regs;
char *p;
set_thread (PIDGET (inferior_ptid), 1);
if (regnum >= 0)
{
switch (remote_protocol_P.support)
{
case PACKET_DISABLE:
break;
case PACKET_ENABLE:
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 (regnum))
{
remote_protocol_P.support = PACKET_ENABLE;
return;
}
else
{
remote_protocol_P.support = PACKET_DISABLE;
break;
}
}
}
{
int i;
regs = alloca (rs->sizeof_g_packet);
memset (regs, 0, rs->sizeof_g_packet);
for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
{
struct packet_reg *r = &rs->regs[i];
if (r->in_g_packet)
regcache_raw_collect (current_regcache, r->regnum, regs + r->offset);
}
}
buf = alloca (rs->remote_packet_size);
p = buf;
*p++ = 'G';
bin2hex (regs, p, register_bytes_found);
remote_send (buf, (rs->remote_packet_size));
}
static int
hexnumlen (ULONGEST num)
{
int i;
for (i = 0; num != 0; i++)
num >>= 4;
return max (i, 1);
}
static int
hexnumstr (char *buf, ULONGEST num)
{
int len = hexnumlen (num);
return hexnumnstr (buf, num, len);
}
static int
hexnumnstr (char *buf, ULONGEST num, int width)
{
int i;
buf[width] = '\0';
for (i = width - 1; i >= 0; i--)
{
buf[i] = "0123456789abcdef"[(num & 0xf)];
num >>= 4;
}
return width;
}
static CORE_ADDR
remote_address_masked (CORE_ADDR addr)
{
if (remote_address_size > 0
&& remote_address_size < (sizeof (ULONGEST) * 8))
{
ULONGEST mask = 1;
mask = (mask << remote_address_size) - 1;
addr &= mask;
}
return addr;
}
static void
check_binary_download (CORE_ADDR addr)
{
struct remote_state *rs = get_remote_state ();
switch (remote_protocol_binary_download.support)
{
case PACKET_DISABLE:
break;
case PACKET_ENABLE:
break;
case PACKET_SUPPORT_UNKNOWN:
{
char *buf = alloca (rs->remote_packet_size);
char *p;
p = buf;
*p++ = 'X';
p += hexnumstr (p, (ULONGEST) addr);
*p++ = ',';
p += hexnumstr (p, (ULONGEST) 0);
*p++ = ':';
*p = '\0';
putpkt_binary (buf, (int) (p - buf));
getpkt (buf, (rs->remote_packet_size), 0);
if (buf[0] == '\0')
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog,
"binary downloading NOT suppported by target\n");
remote_protocol_binary_download.support = PACKET_DISABLE;
}
else
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog,
"binary downloading suppported by target\n");
remote_protocol_binary_download.support = PACKET_ENABLE;
}
break;
}
}
}
int
remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
{
unsigned char *buf;
unsigned char *p;
unsigned char *plen;
long sizeof_buf;
int plenlen;
int todo;
int nr_bytes;
int payload_size;
unsigned char *payload_start;
check_binary_download (memaddr);
payload_size = get_memory_write_packet_size ();
sizeof_buf = payload_size + 1;
buf = alloca (sizeof_buf);
payload_size -= strlen ("$M,:#NN");
payload_size -= hexnumlen (memaddr);
p = buf;
switch (remote_protocol_binary_download.support)
{
case PACKET_ENABLE:
*p++ = 'X';
todo = min (len, payload_size);
payload_size -= hexnumlen (todo);
todo = min (todo, payload_size);
break;
case PACKET_DISABLE:
*p++ = 'M';
todo = min (len, payload_size / 2);
payload_size -= hexnumlen (todo);
todo = min (todo, payload_size / 2);
break;
case PACKET_SUPPORT_UNKNOWN:
internal_error (__FILE__, __LINE__,
_("remote_write_bytes: bad internal state"));
default:
internal_error (__FILE__, __LINE__, _("bad switch"));
}
if (todo <= 0)
internal_error (__FILE__, __LINE__,
_("minumum packet size too small to write data"));
memaddr = remote_address_masked (memaddr);
p += hexnumstr (p, (ULONGEST) memaddr);
*p++ = ',';
plen = p;
plenlen = hexnumstr (p, (ULONGEST) todo);
p += plenlen;
*p++ = ':';
*p = '\0';
payload_start = p;
switch (remote_protocol_binary_download.support)
{
case PACKET_ENABLE:
for (nr_bytes = 0;
(nr_bytes < todo) && (p - payload_start) < payload_size;
nr_bytes++)
{
switch (myaddr[nr_bytes] & 0xff)
{
case '$':
case '#':
case 0x7d:
*p++ = 0x7d;
*p++ = (myaddr[nr_bytes] & 0xff) ^ 0x20;
break;
default:
*p++ = myaddr[nr_bytes] & 0xff;
break;
}
}
if (nr_bytes < todo)
{
plen += hexnumnstr (plen, (ULONGEST) nr_bytes, plenlen);
*plen = ':';
}
break;
case PACKET_DISABLE:
nr_bytes = bin2hex (myaddr, p, todo);
p += 2 * nr_bytes;
break;
case PACKET_SUPPORT_UNKNOWN:
internal_error (__FILE__, __LINE__,
_("remote_write_bytes: bad internal state"));
default:
internal_error (__FILE__, __LINE__, _("bad switch"));
}
putpkt_binary (buf, (int) (p - buf));
getpkt (buf, sizeof_buf, 0);
if (buf[0] == 'E')
{
errno = EIO;
return 0;
}
return nr_bytes;
}
int
remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
{
char *buf;
int max_buf_size;
long sizeof_buf;
int origlen;
max_buf_size = get_memory_read_packet_size ();
sizeof_buf = max_buf_size + 1;
buf = alloca (sizeof_buf);
origlen = len;
while (len > 0)
{
char *p;
int todo;
int i;
todo = min (len, max_buf_size / 2);
memaddr = remote_address_masked (memaddr);
p = buf;
*p++ = 'm';
p += hexnumstr (p, (ULONGEST) memaddr);
*p++ = ',';
p += hexnumstr (p, (ULONGEST) todo);
*p = '\0';
putpkt (buf);
getpkt (buf, sizeof_buf, 0);
if (buf[0] == 'E'
&& isxdigit (buf[1]) && isxdigit (buf[2])
&& buf[3] == '\0')
{
errno = EIO;
return 0;
}
p = buf;
if ((i = hex2bin (p, myaddr, todo)) < todo)
{
return i + (origlen - len);
}
myaddr += todo;
memaddr += todo;
len -= todo;
}
return origlen;
}
static int
remote_xfer_memory (CORE_ADDR mem_addr, gdb_byte *buffer, int mem_len,
int should_write, struct mem_attrib *attrib,
struct target_ops *target)
{
CORE_ADDR targ_addr;
int targ_len;
int res;
gdbarch_remote_translate_xfer_address (current_gdbarch,
current_regcache,
mem_addr, mem_len,
&targ_addr, &targ_len);
if (targ_len <= 0)
return 0;
if (should_write)
res = remote_write_bytes (targ_addr, buffer, targ_len);
else
res = remote_read_bytes (targ_addr, buffer, targ_len);
return res;
}
static void
remote_files_info (struct target_ops *ignore)
{
puts_filtered ("Debugging a target over a serial line.\n");
}
static int
readchar (int timeout)
{
int ch;
ch = serial_readchar (remote_desc, timeout);
if (ch >= 0)
return (ch & 0x7f);
switch ((enum serial_rc) ch)
{
case SERIAL_EOF:
target_mourn_inferior ();
error (_("Remote connection closed"));
case SERIAL_ERROR:
perror_with_name (_("Remote communication error"));
case SERIAL_TIMEOUT:
break;
}
return ch;
}
static void
remote_send (char *buf,
long sizeof_buf)
{
putpkt (buf);
getpkt (buf, sizeof_buf, 0);
if (buf[0] == 'E')
error (_("Remote failure reply: %s"), buf);
}
static void
print_packet (char *buf)
{
puts_filtered ("\"");
fputstr_filtered (buf, '"', gdb_stdout);
puts_filtered ("\"");
}
int
putpkt (char *buf)
{
return putpkt_binary (buf, strlen (buf));
}
static int
putpkt_binary (char *buf, int cnt)
{
struct remote_state *rs = get_remote_state ();
int i;
unsigned char csum = 0;
char *buf2 = alloca (cnt + 6);
long sizeof_junkbuf = (rs->remote_packet_size);
char *junkbuf = alloca (sizeof_junkbuf);
int ch;
int tcount = 0;
char *p;
p = buf2;
*p++ = '$';
for (i = 0; i < cnt; i++)
{
csum += buf[i];
*p++ = buf[i];
}
*p++ = '#';
*p++ = tohex ((csum >> 4) & 0xf);
*p++ = tohex (csum & 0xf);
while (1)
{
int started_error_output = 0;
if (remote_debug)
{
*p = '\0';
fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
fprintf_unfiltered (gdb_stdlog, "...");
gdb_flush (gdb_stdlog);
}
if (serial_write (remote_desc, buf2, p - buf2))
perror_with_name (_("putpkt: write failed"));
while (1)
{
ch = readchar (remote_timeout);
if (remote_debug)
{
switch (ch)
{
case '+':
case '-':
case SERIAL_TIMEOUT:
case '$':
if (started_error_output)
{
putchar_unfiltered ('\n');
started_error_output = 0;
}
}
}
switch (ch)
{
case '+':
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "Ack\n");
return 1;
case '-':
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "Nak\n");
case SERIAL_TIMEOUT:
tcount++;
if (tcount > 3)
return 0;
break;
case '$':
{
if (remote_debug)
fprintf_unfiltered (gdb_stdlog,
"Packet instead of Ack, ignoring it\n");
read_frame (junkbuf, sizeof_junkbuf);
serial_write (remote_desc, "+", 1);
continue;
}
default:
if (remote_debug)
{
if (!started_error_output)
{
started_error_output = 1;
fprintf_unfiltered (gdb_stdlog, "putpkt: Junk: ");
}
fputc_unfiltered (ch & 0177, gdb_stdlog);
}
continue;
}
break;
}
#if 0
if (quit_flag)
{
quit_flag = 0;
interrupt_query ();
}
#endif
}
}
static long
read_frame (char *buf,
long sizeof_buf)
{
unsigned char csum;
long bc;
int c;
csum = 0;
bc = 0;
while (1)
{
c = readchar (remote_timeout);
switch (c)
{
case SERIAL_TIMEOUT:
if (remote_debug)
fputs_filtered ("Timeout in mid-packet, retrying\n", gdb_stdlog);
return -1;
case '$':
if (remote_debug)
fputs_filtered ("Saw new packet start in middle of old one\n",
gdb_stdlog);
return -1;
case '#':
{
unsigned char pktcsum;
int check_0 = 0;
int check_1 = 0;
buf[bc] = '\0';
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;
if (remote_debug)
{
fprintf_filtered (gdb_stdlog,
"Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
pktcsum, csum);
fputs_filtered (buf, gdb_stdlog);
fputs_filtered ("\n", gdb_stdlog);
}
return -1;
}
case '*':
{
int repeat;
csum += c;
c = readchar (remote_timeout);
csum += c;
repeat = c - ' ' + 3;
if (repeat > 0 && repeat <= 255
&& bc > 0
&& bc + repeat - 1 < sizeof_buf - 1)
{
memset (&buf[bc], buf[bc - 1], repeat);
bc += repeat;
continue;
}
buf[bc] = '\0';
printf_filtered (_("Repeat count %d too large for buffer: "),
repeat);
puts_filtered (buf);
puts_filtered ("\n");
return -1;
}
default:
if (bc < sizeof_buf - 1)
{
buf[bc++] = c;
csum += c;
continue;
}
buf[bc] = '\0';
puts_filtered ("Remote packet too long: ");
puts_filtered (buf);
puts_filtered ("\n");
return -1;
}
}
}
void
getpkt (char *buf,
long sizeof_buf,
int forever)
{
int timed_out;
timed_out = getpkt_sane (buf, sizeof_buf, forever);
}
static int
getpkt_sane (char *buf,
long sizeof_buf,
int forever)
{
int c;
int tries;
int timeout;
int val;
strcpy (buf, "timeout");
if (forever)
{
timeout = watchdog > 0 ? watchdog : -1;
}
else
timeout = remote_timeout;
#define MAX_TRIES 3
for (tries = 1; tries <= MAX_TRIES; tries++)
{
do
{
c = readchar (timeout);
if (c == SERIAL_TIMEOUT)
{
if (forever)
{
QUIT;
target_mourn_inferior ();
error (_("Watchdog has expired. Target detached."));
}
if (remote_debug)
fputs_filtered ("Timed out.\n", gdb_stdlog);
goto retry;
}
}
while (c != '$');
val = read_frame (buf, sizeof_buf);
if (val >= 0)
{
if (remote_debug)
{
fprintf_unfiltered (gdb_stdlog, "Packet received: ");
fputstr_unfiltered (buf, 0, gdb_stdlog);
fprintf_unfiltered (gdb_stdlog, "\n");
}
serial_write (remote_desc, "+", 1);
return 0;
}
retry:
serial_write (remote_desc, "-", 1);
}
printf_unfiltered (_("Ignoring packet error, continuing...\n"));
serial_write (remote_desc, "+", 1);
return 1;
}
static void
remote_kill (void)
{
if (kill_kludge)
{
kill_kludge = 0;
target_mourn_inferior ();
return;
}
catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
target_mourn_inferior ();
}
static void
remote_async_kill (void)
{
if (target_is_async_p ())
serial_async (remote_desc, NULL, 0);
if (kill_kludge)
{
kill_kludge = 0;
target_mourn_inferior ();
return;
}
catch_errors ((catch_errors_ftype *) putpkt, "k", "", RETURN_MASK_ERROR);
target_mourn_inferior ();
}
static void
remote_mourn (void)
{
remote_mourn_1 (&remote_ops);
}
static void
remote_async_mourn (void)
{
remote_mourn_1 (&remote_async_ops);
}
static void
extended_remote_mourn (void)
{
#if 0
remote_mourn_1 (&extended_remote_ops);
#endif
}
static void
remote_mourn_1 (struct target_ops *target)
{
unpush_target (target);
generic_mourn_inferior ();
}
static void
extended_remote_create_inferior (char *exec_file, char *args,
char **env, int from_tty)
{
remove_breakpoints ();
extended_remote_restart ();
insert_breakpoints ();
clear_proceed_status ();
proceed (-1, TARGET_SIGNAL_0, 0);
}
static void
extended_remote_async_create_inferior (char *exec_file, char *args,
char **env, int from_tty)
{
remove_breakpoints ();
if (target_can_async_p ())
target_async (inferior_event_handler, 0);
extended_remote_restart ();
insert_breakpoints ();
clear_proceed_status ();
proceed (-1, TARGET_SIGNAL_0, 0);
}
#if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
#define DEPRECATED_REMOTE_BREAKPOINT
#endif
#ifdef DEPRECATED_REMOTE_BREAKPOINT
#if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
#define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
#define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
#endif
static unsigned char big_break_insn[] = DEPRECATED_BIG_REMOTE_BREAKPOINT;
static unsigned char little_break_insn[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT;
#endif
static int
remote_insert_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
{
struct remote_state *rs = get_remote_state ();
#ifdef DEPRECATED_REMOTE_BREAKPOINT
int val;
#endif
int bp_size;
if (remote_protocol_Z[Z_PACKET_SOFTWARE_BP].support != PACKET_DISABLE)
{
char *buf = alloca (rs->remote_packet_size);
char *p = buf;
addr = remote_address_masked (addr);
*(p++) = 'Z';
*(p++) = '0';
*(p++) = ',';
p += hexnumstr (p, (ULONGEST) addr);
BREAKPOINT_FROM_PC (&addr, &bp_size);
sprintf (p, ",%d", bp_size);
putpkt (buf);
getpkt (buf, (rs->remote_packet_size), 0);
switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_SOFTWARE_BP]))
{
case PACKET_ERROR:
return -1;
case PACKET_OK:
return 0;
case PACKET_UNKNOWN:
break;
}
}
#ifdef DEPRECATED_REMOTE_BREAKPOINT
val = target_read_memory (addr, contents_cache, sizeof big_break_insn);
if (val == 0)
{
if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
val = target_write_memory (addr, (char *) big_break_insn,
sizeof big_break_insn);
else
val = target_write_memory (addr, (char *) little_break_insn,
sizeof little_break_insn);
}
return val;
#else
return memory_insert_breakpoint (addr, contents_cache);
#endif
}
static int
remote_remove_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
{
struct remote_state *rs = get_remote_state ();
int bp_size;
if (remote_protocol_Z[Z_PACKET_SOFTWARE_BP].support != PACKET_DISABLE)
{
char *buf = alloca (rs->remote_packet_size);
char *p = buf;
*(p++) = 'z';
*(p++) = '0';
*(p++) = ',';
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
BREAKPOINT_FROM_PC (&addr, &bp_size);
sprintf (p, ",%d", bp_size);
putpkt (buf);
getpkt (buf, (rs->remote_packet_size), 0);
return (buf[0] == 'E');
}
#ifdef DEPRECATED_REMOTE_BREAKPOINT
return target_write_memory (addr, contents_cache, sizeof big_break_insn);
#else
return memory_remove_breakpoint (addr, contents_cache);
#endif
}
static int
watchpoint_to_Z_packet (int type)
{
switch (type)
{
case hw_write:
return 2;
break;
case hw_read:
return 3;
break;
case hw_access:
return 4;
break;
default:
internal_error (__FILE__, __LINE__,
_("hw_bp_to_z: bad watchpoint type %d"), type);
}
}
static int
remote_insert_watchpoint (CORE_ADDR addr, int len, int type)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
char *p;
enum Z_packet_type packet = watchpoint_to_Z_packet (type);
if (remote_protocol_Z[packet].support == PACKET_DISABLE)
error (_("Can't set hardware watchpoints without the '%s' (%s) packet."),
remote_protocol_Z[packet].name,
remote_protocol_Z[packet].title);
sprintf (buf, "Z%x,", packet);
p = strchr (buf, '\0');
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
putpkt (buf);
getpkt (buf, (rs->remote_packet_size), 0);
switch (packet_ok (buf, &remote_protocol_Z[packet]))
{
case PACKET_ERROR:
case PACKET_UNKNOWN:
return -1;
case PACKET_OK:
return 0;
}
internal_error (__FILE__, __LINE__,
_("remote_insert_watchpoint: reached end of function"));
}
static int
remote_remove_watchpoint (CORE_ADDR addr, int len, int type)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
char *p;
enum Z_packet_type packet = watchpoint_to_Z_packet (type);
if (remote_protocol_Z[packet].support == PACKET_DISABLE)
error (_("Can't clear hardware watchpoints without the '%s' (%s) packet."),
remote_protocol_Z[packet].name,
remote_protocol_Z[packet].title);
sprintf (buf, "z%x,", packet);
p = strchr (buf, '\0');
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
putpkt (buf);
getpkt (buf, (rs->remote_packet_size), 0);
switch (packet_ok (buf, &remote_protocol_Z[packet]))
{
case PACKET_ERROR:
case PACKET_UNKNOWN:
return -1;
case PACKET_OK:
return 0;
}
internal_error (__FILE__, __LINE__,
_("remote_remove_watchpoint: reached end of function"));
}
int remote_hw_watchpoint_limit = -1;
int remote_hw_breakpoint_limit = -1;
static int
remote_check_watch_resources (int type, int cnt, int ot)
{
if (type == bp_hardware_breakpoint)
{
if (remote_hw_breakpoint_limit == 0)
return 0;
else if (remote_hw_breakpoint_limit < 0)
return 1;
else if (cnt <= remote_hw_breakpoint_limit)
return 1;
}
else
{
if (remote_hw_watchpoint_limit == 0)
return 0;
else if (remote_hw_watchpoint_limit < 0)
return 1;
else if (ot)
return -1;
else if (cnt <= remote_hw_watchpoint_limit)
return 1;
}
return -1;
}
static int
remote_stopped_by_watchpoint (void)
{
return remote_stopped_by_watchpoint_p;
}
extern int stepped_after_stopped_by_watchpoint;
static int
remote_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
{
int rc = 0;
if (remote_stopped_by_watchpoint ()
|| stepped_after_stopped_by_watchpoint)
{
*addr_p = remote_watch_data_address;
rc = 1;
}
return rc;
}
static int
remote_insert_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow)
{
int len = 0;
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
char *p = buf;
BREAKPOINT_FROM_PC (&addr, &len);
if (remote_protocol_Z[Z_PACKET_HARDWARE_BP].support == PACKET_DISABLE)
error (_("Can't set hardware breakpoint without the '%s' (%s) packet."),
remote_protocol_Z[Z_PACKET_HARDWARE_BP].name,
remote_protocol_Z[Z_PACKET_HARDWARE_BP].title);
*(p++) = 'Z';
*(p++) = '1';
*(p++) = ',';
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
putpkt (buf);
getpkt (buf, (rs->remote_packet_size), 0);
switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
{
case PACKET_ERROR:
case PACKET_UNKNOWN:
return -1;
case PACKET_OK:
return 0;
}
internal_error (__FILE__, __LINE__,
_("remote_insert_hw_breakpoint: reached end of function"));
}
static int
remote_remove_hw_breakpoint (CORE_ADDR addr, gdb_byte *shadow)
{
int len;
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
char *p = buf;
BREAKPOINT_FROM_PC (&addr, &len);
if (remote_protocol_Z[Z_PACKET_HARDWARE_BP].support == PACKET_DISABLE)
error (_("Can't clear hardware breakpoint without the '%s' (%s) packet."),
remote_protocol_Z[Z_PACKET_HARDWARE_BP].name,
remote_protocol_Z[Z_PACKET_HARDWARE_BP].title);
*(p++) = 'z';
*(p++) = '1';
*(p++) = ',';
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
sprintf (p, ",%x", len);
putpkt(buf);
getpkt (buf, (rs->remote_packet_size), 0);
switch (packet_ok (buf, &remote_protocol_Z[Z_PACKET_HARDWARE_BP]))
{
case PACKET_ERROR:
case PACKET_UNKNOWN:
return -1;
case PACKET_OK:
return 0;
}
internal_error (__FILE__, __LINE__,
_("remote_remove_hw_breakpoint: reached end of function"));
}
void
push_remote_target (char *name, int from_tty)
{
printf_filtered (_("Switching to remote protocol\n"));
remote_open (name, from_tty);
}
static unsigned long crc32_table[256] =
{0, 0};
static unsigned long
crc32 (unsigned char *buf, int len, unsigned int crc)
{
if (!crc32_table[1])
{
int i, j;
unsigned int c;
for (i = 0; i < 256; i++)
{
for (c = i << 24, j = 8; j > 0; --j)
c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1);
crc32_table[i] = c;
}
}
while (len--)
{
crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255];
buf++;
}
return crc;
}
static void
compare_sections_command (char *args, int from_tty)
{
struct remote_state *rs = get_remote_state ();
asection *s;
unsigned long host_crc, target_crc;
extern bfd *exec_bfd;
struct cleanup *old_chain;
char *tmp;
char *sectdata;
const char *sectname;
char *buf = alloca (rs->remote_packet_size);
bfd_size_type size;
bfd_vma lma;
int matched = 0;
int mismatched = 0;
if (!exec_bfd)
error (_("command cannot be used without an exec file"));
if (!current_target.to_shortname ||
strcmp (current_target.to_shortname, "remote") != 0)
error (_("command can only be used with remote target"));
for (s = exec_bfd->sections; s; s = s->next)
{
if (!(s->flags & SEC_LOAD))
continue;
size = bfd_get_section_size (s);
if (size == 0)
continue;
sectname = bfd_get_section_name (exec_bfd, s);
if (args && strcmp (args, sectname) != 0)
continue;
matched = 1;
lma = s->lma;
xsnprintf (buf, rs->remote_packet_size, "qCRC:%lx,%lx",
(long) lma, (long) size);
putpkt (buf);
sectdata = xmalloc (size);
old_chain = make_cleanup (xfree, sectdata);
bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
getpkt (buf, (rs->remote_packet_size), 0);
if (buf[0] == 'E')
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"));
for (target_crc = 0, tmp = &buf[1]; *tmp; tmp++)
target_crc = target_crc * 16 + fromhex (*tmp);
printf_filtered ("Section %s, range 0x%s -- 0x%s: ",
sectname, paddr (lma), paddr (lma + size));
if (host_crc == target_crc)
printf_filtered ("matched.\n");
else
{
printf_filtered ("MIS-MATCHED!\n");
mismatched++;
}
do_cleanups (old_chain);
}
if (mismatched > 0)
warning (_("One or more sections of the remote executable does not match\n\
the loaded file\n"));
if (args && !matched)
printf_filtered (_("No loaded section named '%s'.\n"), args);
}
static LONGEST
remote_xfer_partial (struct target_ops *ops, enum target_object object,
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
{
struct remote_state *rs = get_remote_state ();
int i;
char *buf2 = alloca (rs->remote_packet_size);
char *p2 = &buf2[0];
char query_type;
if (object == TARGET_OBJECT_MEMORY)
{
int xfered;
errno = 0;
if (writebuf != NULL)
{
void *buffer = xmalloc (len);
struct cleanup *cleanup = make_cleanup (xfree, buffer);
memcpy (buffer, writebuf, len);
xfered = remote_xfer_memory (offset, buffer, len, 1, NULL, ops);
do_cleanups (cleanup);
}
else
xfered = remote_xfer_memory (offset, readbuf, len, 0, NULL, ops);
if (xfered > 0)
return xfered;
else if (xfered == 0 && errno == 0)
return 0;
else
return -1;
}
if (writebuf != NULL || readbuf == NULL)
return -1;
switch (object)
{
case TARGET_OBJECT_KOD:
query_type = 'K';
break;
case TARGET_OBJECT_AVR:
query_type = 'R';
break;
case TARGET_OBJECT_AUXV:
if (remote_protocol_qPart_auxv.support != PACKET_DISABLE)
{
unsigned int total = 0;
while (len > 0)
{
LONGEST n = min ((rs->remote_packet_size - 2) / 2, len);
snprintf (buf2, rs->remote_packet_size,
"qPart:auxv:read::%s,%s",
phex_nz (offset, sizeof offset),
phex_nz (n, sizeof n));
i = putpkt (buf2);
if (i < 0)
return total > 0 ? total : i;
buf2[0] = '\0';
getpkt (buf2, rs->remote_packet_size, 0);
if (packet_ok (buf2, &remote_protocol_qPart_auxv) != PACKET_OK)
return total > 0 ? total : -1;
if (buf2[0] == 'O' && buf2[1] == 'K' && buf2[2] == '\0')
break;
i = hex2bin (buf2, readbuf, len);
if (i > 0)
{
readbuf = (void *) ((char *) readbuf + i);
offset += i;
len -= i;
total += i;
}
}
return total;
}
return -1;
default:
return -1;
}
if (offset == 0 && len == 0)
return (rs->remote_packet_size);
if (len < (rs->remote_packet_size))
return -1;
len = rs->remote_packet_size;
if (!remote_desc)
error (_("remote query is only available after target open"));
gdb_assert (annex != NULL);
gdb_assert (readbuf != NULL);
*p2++ = 'q';
*p2++ = query_type;
i = 0;
while (annex[i] && (i < ((rs->remote_packet_size) - 8)))
{
gdb_assert (isprint (annex[i]) && annex[i] != '$' && annex[i] != '#');
*p2++ = annex[i];
i++;
}
*p2 = '\0';
gdb_assert (annex[i] == '\0');
i = putpkt (buf2);
if (i < 0)
return i;
getpkt (readbuf, len, 0);
return strlen (readbuf);
}
static void
remote_rcmd (char *command,
struct ui_file *outbuf)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
char *p = buf;
if (!remote_desc)
error (_("remote rcmd is only available after target open"));
if (command == NULL)
command = "";
strcpy (buf, "qRcmd,");
p = strchr (buf, '\0');
if ((strlen (buf) + strlen (command) * 2 + 8) > (rs->remote_packet_size))
error (_("\"monitor\" command ``%s'' is too long."), command);
bin2hex (command, p, 0);
if (putpkt (buf) < 0)
error (_("Communication problem with target."));
while (1)
{
buf[0] = '\0';
getpkt (buf, (rs->remote_packet_size), 0);
if (buf[0] == '\0')
error (_("Target does not support this command."));
if (buf[0] == 'O' && buf[1] != 'K')
{
remote_console_output (buf + 1);
continue;
}
if (strcmp (buf, "OK") == 0)
break;
if (strlen (buf) == 3 && buf[0] == 'E'
&& isdigit (buf[1]) && isdigit (buf[2]))
{
error (_("Protocol error with Rcmd"));
}
for (p = buf; p[0] != '\0' && p[1] != '\0'; p += 2)
{
char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
fputc_unfiltered (c, outbuf);
}
break;
}
}
static void
packet_command (char *args, int from_tty)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
if (!remote_desc)
error (_("command can only be used with remote target"));
if (!args)
error (_("remote-packet command requires packet text as argument"));
puts_filtered ("sending: ");
print_packet (args);
puts_filtered ("\n");
putpkt (args);
getpkt (buf, (rs->remote_packet_size), 0);
puts_filtered ("received: ");
print_packet (buf);
puts_filtered ("\n");
}
#if 0
static void display_thread_info (struct gdb_ext_thread_info *info);
static void threadset_test_cmd (char *cmd, int tty);
static void threadalive_test (char *cmd, int tty);
static void threadlist_test_cmd (char *cmd, int tty);
int get_and_display_threadinfo (threadref *ref);
static void threadinfo_test_cmd (char *cmd, int tty);
static int thread_display_step (threadref *ref, void *context);
static void threadlist_update_test_cmd (char *cmd, int tty);
static void init_remote_threadtests (void);
#define SAMPLE_THREAD 0x05060708
static void
threadset_test_cmd (char *cmd, int tty)
{
int sample_thread = SAMPLE_THREAD;
printf_filtered (_("Remote threadset test\n"));
set_thread (sample_thread, 1);
}
static void
threadalive_test (char *cmd, int tty)
{
int sample_thread = SAMPLE_THREAD;
if (remote_thread_alive (pid_to_ptid (sample_thread)))
printf_filtered ("PASS: Thread alive test\n");
else
printf_filtered ("FAIL: Thread alive test\n");
}
void output_threadid (char *title, threadref *ref);
void
output_threadid (char *title, threadref *ref)
{
char hexid[20];
pack_threadid (&hexid[0], ref);
hexid[16] = 0;
printf_filtered ("%s %s\n", title, (&hexid[0]));
}
static void
threadlist_test_cmd (char *cmd, int tty)
{
int startflag = 1;
threadref nextthread;
int done, result_count;
threadref threadlist[3];
printf_filtered ("Remote Threadlist test\n");
if (!remote_get_threadlist (startflag, &nextthread, 3, &done,
&result_count, &threadlist[0]))
printf_filtered ("FAIL: threadlist test\n");
else
{
threadref *scan = threadlist;
threadref *limit = scan + result_count;
while (scan < limit)
output_threadid (" thread ", scan++);
}
}
void
display_thread_info (struct gdb_ext_thread_info *info)
{
output_threadid ("Threadid: ", &info->threadid);
printf_filtered ("Name: %s\n ", info->shortname);
printf_filtered ("State: %s\n", info->display);
printf_filtered ("other: %s\n\n", info->more_display);
}
int
get_and_display_threadinfo (threadref *ref)
{
int result;
int set;
struct gdb_ext_thread_info threadinfo;
set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
| TAG_MOREDISPLAY | TAG_DISPLAY;
if (0 != (result = remote_get_threadinfo (ref, set, &threadinfo)))
display_thread_info (&threadinfo);
return result;
}
static void
threadinfo_test_cmd (char *cmd, int tty)
{
int athread = SAMPLE_THREAD;
threadref thread;
int set;
int_to_threadref (&thread, athread);
printf_filtered ("Remote Threadinfo test\n");
if (!get_and_display_threadinfo (&thread))
printf_filtered ("FAIL cannot get thread info\n");
}
static int
thread_display_step (threadref *ref, void *context)
{
return get_and_display_threadinfo (ref);
}
static void
threadlist_update_test_cmd (char *cmd, int tty)
{
printf_filtered ("Remote Threadlist update test\n");
remote_threadlist_iterator (thread_display_step, 0, CRAZY_MAX_THREADS);
}
static void
init_remote_threadtests (void)
{
add_com ("tlist", class_obscure, threadlist_test_cmd, _("\
Fetch and print the remote list of thread identifiers, one pkt only"));
add_com ("tinfo", class_obscure, threadinfo_test_cmd,
_("Fetch and display info about one thread"));
add_com ("tset", class_obscure, threadset_test_cmd,
_("Test setting to a different thread"));
add_com ("tupd", class_obscure, threadlist_update_test_cmd,
_("Iterate through updating all remote thread info"));
add_com ("talive", class_obscure, threadalive_test,
_(" Remote thread alive test "));
}
#endif
static char *
remote_pid_to_str (ptid_t ptid)
{
static char buf[32];
xsnprintf (buf, sizeof buf, "thread %d", ptid_get_pid (ptid));
return buf;
}
static CORE_ADDR
remote_get_thread_local_address (ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
{
if (remote_protocol_qGetTLSAddr.support != PACKET_DISABLE)
{
struct remote_state *rs = get_remote_state ();
char *buf = alloca (rs->remote_packet_size);
char *p = buf;
enum packet_result result;
strcpy (p, "qGetTLSAddr:");
p += strlen (p);
p += hexnumstr (p, PIDGET (ptid));
*p++ = ',';
p += hexnumstr (p, offset);
*p++ = ',';
p += hexnumstr (p, lm);
*p++ = '\0';
putpkt (buf);
getpkt (buf, rs->remote_packet_size, 0);
result = packet_ok (buf, &remote_protocol_qGetTLSAddr);
if (result == PACKET_OK)
{
ULONGEST result;
unpack_varlen_hex (buf, &result);
return result;
}
else if (result == PACKET_UNKNOWN)
throw_error (TLS_GENERIC_ERROR,
_("Remote target doesn't support qGetTLSAddr packet"));
else
throw_error (TLS_GENERIC_ERROR,
_("Remote target failed to process qGetTLSAddr request"));
}
else
throw_error (TLS_GENERIC_ERROR,
_("TLS not supported or disabled on this target"));
return 0;
}
static void
init_remote_ops (void)
{
remote_ops.to_shortname = "remote";
remote_ops.to_longname = "Remote serial target in gdb-specific protocol";
remote_ops.to_doc =
"Use a remote computer via a serial line, using a gdb-specific protocol.\n\
Specify the serial device it is connected to\n\
(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
remote_ops.to_open = remote_open;
remote_ops.to_close = remote_close;
remote_ops.to_detach = remote_detach;
remote_ops.to_disconnect = remote_disconnect;
remote_ops.to_resume = remote_resume;
remote_ops.to_wait = remote_wait;
remote_ops.to_fetch_registers = remote_fetch_registers;
remote_ops.to_store_registers = remote_store_registers;
remote_ops.to_prepare_to_store = remote_prepare_to_store;
remote_ops.deprecated_xfer_memory = remote_xfer_memory;
remote_ops.to_files_info = remote_files_info;
remote_ops.to_insert_breakpoint = remote_insert_breakpoint;
remote_ops.to_remove_breakpoint = remote_remove_breakpoint;
remote_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint;
remote_ops.to_stopped_data_address = remote_stopped_data_address;
remote_ops.to_can_use_hw_breakpoint = remote_check_watch_resources;
remote_ops.to_insert_hw_breakpoint = remote_insert_hw_breakpoint;
remote_ops.to_remove_hw_breakpoint = remote_remove_hw_breakpoint;
remote_ops.to_insert_watchpoint = remote_insert_watchpoint;
remote_ops.to_remove_watchpoint = remote_remove_watchpoint;
remote_ops.to_kill = remote_kill;
remote_ops.to_load = generic_load;
remote_ops.to_mourn_inferior = remote_mourn;
remote_ops.to_thread_alive = remote_thread_alive;
remote_ops.to_find_new_threads = remote_threads_info;
remote_ops.to_pid_to_str = remote_pid_to_str;
remote_ops.to_extra_thread_info = remote_threads_extra_info;
remote_ops.to_stop = remote_stop;
remote_ops.to_xfer_partial = remote_xfer_partial;
remote_ops.to_rcmd = remote_rcmd;
remote_ops.to_get_thread_local_address = remote_get_thread_local_address;
remote_ops.to_stratum = process_stratum;
remote_ops.to_has_all_memory = 1;
remote_ops.to_has_memory = 1;
remote_ops.to_has_stack = 1;
remote_ops.to_has_registers = 1;
remote_ops.to_has_execution = 1;
remote_ops.to_has_thread_control = tc_schedlock;
remote_ops.to_async_mask_value = 0;
remote_ops.to_magic = OPS_MAGIC;
}
static void
init_extended_remote_ops (void)
{
extended_remote_ops = remote_ops;
extended_remote_ops.to_shortname = "extended-remote";
extended_remote_ops.to_longname =
"Extended remote serial target in gdb-specific protocol";
extended_remote_ops.to_doc =
"Use a remote computer via a serial line, using a gdb-specific protocol.\n\
Specify the serial device it is connected to (e.g. /dev/ttya).",
extended_remote_ops.to_open = extended_remote_open;
extended_remote_ops.to_create_inferior = extended_remote_create_inferior;
extended_remote_ops.to_mourn_inferior = extended_remote_mourn;
}
static int
remote_can_async_p (void)
{
return (current_target.to_async_mask_value) && serial_can_async_p (remote_desc);
}
static int
remote_is_async_p (void)
{
return (current_target.to_async_mask_value) && serial_is_async_p (remote_desc);
}
static void (*async_client_callback) (enum inferior_event_type event_type,
void *context);
static void *async_client_context;
static serial_event_ftype remote_async_serial_handler;
static void
remote_async_serial_handler (struct serial *scb, void *context)
{
async_client_callback (INF_REG_EVENT, async_client_context);
}
static void
remote_async (void (*callback) (enum inferior_event_type event_type,
void *context), void *context)
{
if (current_target.to_async_mask_value == 0)
internal_error (__FILE__, __LINE__,
_("Calling remote_async when async is masked"));
if (callback != NULL)
{
serial_async (remote_desc, remote_async_serial_handler, NULL);
async_client_callback = callback;
async_client_context = context;
}
else
serial_async (remote_desc, NULL, NULL);
}
static void
init_remote_async_ops (void)
{
remote_async_ops.to_shortname = "async";
remote_async_ops.to_longname =
"Remote serial target in async version of the gdb-specific protocol";
remote_async_ops.to_doc =
"Use a remote computer via a serial line, using a gdb-specific protocol.\n\
Specify the serial device it is connected to (e.g. /dev/ttya).";
remote_async_ops.to_open = remote_async_open;
remote_async_ops.to_close = remote_close;
remote_async_ops.to_detach = remote_detach;
remote_async_ops.to_disconnect = remote_disconnect;
remote_async_ops.to_resume = remote_async_resume;
remote_async_ops.to_wait = remote_async_wait;
remote_async_ops.to_fetch_registers = remote_fetch_registers;
remote_async_ops.to_store_registers = remote_store_registers;
remote_async_ops.to_prepare_to_store = remote_prepare_to_store;
remote_async_ops.deprecated_xfer_memory = remote_xfer_memory;
remote_async_ops.to_files_info = remote_files_info;
remote_async_ops.to_insert_breakpoint = remote_insert_breakpoint;
remote_async_ops.to_remove_breakpoint = remote_remove_breakpoint;
remote_async_ops.to_can_use_hw_breakpoint = remote_check_watch_resources;
remote_async_ops.to_insert_hw_breakpoint = remote_insert_hw_breakpoint;
remote_async_ops.to_remove_hw_breakpoint = remote_remove_hw_breakpoint;
remote_async_ops.to_insert_watchpoint = remote_insert_watchpoint;
remote_async_ops.to_remove_watchpoint = remote_remove_watchpoint;
remote_async_ops.to_stopped_by_watchpoint = remote_stopped_by_watchpoint;
remote_async_ops.to_stopped_data_address = remote_stopped_data_address;
remote_async_ops.to_terminal_inferior = remote_async_terminal_inferior;
remote_async_ops.to_terminal_ours = remote_async_terminal_ours;
remote_async_ops.to_kill = remote_async_kill;
remote_async_ops.to_load = generic_load;
remote_async_ops.to_mourn_inferior = remote_async_mourn;
remote_async_ops.to_thread_alive = remote_thread_alive;
remote_async_ops.to_find_new_threads = remote_threads_info;
remote_async_ops.to_pid_to_str = remote_pid_to_str;
remote_async_ops.to_extra_thread_info = remote_threads_extra_info;
remote_async_ops.to_stop = remote_stop;
remote_async_ops.to_xfer_partial = remote_xfer_partial;
remote_async_ops.to_rcmd = remote_rcmd;
remote_async_ops.to_stratum = process_stratum;
remote_async_ops.to_has_all_memory = 1;
remote_async_ops.to_has_memory = 1;
remote_async_ops.to_has_stack = 1;
remote_async_ops.to_has_registers = 1;
remote_async_ops.to_has_execution = 1;
remote_async_ops.to_has_thread_control = tc_schedlock;
remote_async_ops.to_can_async_p = remote_can_async_p;
remote_async_ops.to_is_async_p = remote_is_async_p;
remote_async_ops.to_async = remote_async;
remote_async_ops.to_async_mask_value = 1;
remote_async_ops.to_magic = OPS_MAGIC;
}
static void
init_extended_async_remote_ops (void)
{
extended_async_remote_ops = remote_async_ops;
extended_async_remote_ops.to_shortname = "extended-async";
extended_async_remote_ops.to_longname =
"Extended remote serial target in async gdb-specific protocol";
extended_async_remote_ops.to_doc =
"Use a remote computer via a serial line, using an async gdb-specific protocol.\n\
Specify the serial device it is connected to (e.g. /dev/ttya).",
extended_async_remote_ops.to_open = extended_remote_async_open;
extended_async_remote_ops.to_create_inferior = extended_remote_async_create_inferior;
extended_async_remote_ops.to_mourn_inferior = extended_remote_mourn;
}
static void
set_remote_cmd (char *args, int from_tty)
{
}
static void
show_remote_cmd (char *args, int from_tty)
{
show_remote_protocol_Z_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
show_remote_protocol_P_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
show_remote_protocol_p_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
show_remote_protocol_qSymbol_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
show_remote_protocol_vcont_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
show_remote_protocol_binary_download_cmd (gdb_stdout, from_tty, NULL, NULL);
show_remote_protocol_qPart_auxv_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
show_remote_protocol_qGetTLSAddr_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
}
static void
build_remote_gdbarch_data (void)
{
remote_address_size = TARGET_ADDR_BIT;
}
static void (*remote_new_objfile_chain) (struct objfile *);
static void
remote_new_objfile (struct objfile *objfile)
{
if (remote_desc != 0)
{
remote_check_symbols (objfile);
}
if (remote_new_objfile_chain != 0 &&
remote_desc == 0)
remote_new_objfile_chain (objfile);
}
void
_initialize_remote (void)
{
static struct cmd_list_element *remote_set_cmdlist;
static struct cmd_list_element *remote_show_cmdlist;
remote_gdbarch_data_handle =
gdbarch_data_register_post_init (init_remote_state);
DEPRECATED_REGISTER_GDBARCH_SWAP (remote_address_size);
deprecated_register_gdbarch_swap (NULL, 0, build_remote_gdbarch_data);
init_remote_ops ();
add_target (&remote_ops);
init_extended_remote_ops ();
add_target (&extended_remote_ops);
init_remote_async_ops ();
add_target (&remote_async_ops);
init_extended_async_remote_ops ();
add_target (&extended_async_remote_ops);
remote_new_objfile_chain = deprecated_target_new_objfile_hook;
deprecated_target_new_objfile_hook = remote_new_objfile;
#if 0
init_remote_threadtests ();
#endif
add_prefix_cmd ("remote", class_maintenance, set_remote_cmd, _("\
Remote protocol specific variables\n\
Configure various remote-protocol specific variables such as\n\
the packets being used"),
&remote_set_cmdlist, "set remote ",
0 , &setlist);
add_prefix_cmd ("remote", class_maintenance, show_remote_cmd, _("\
Remote protocol specific variables\n\
Configure various remote-protocol specific variables such as\n\
the packets being used"),
&remote_show_cmdlist, "show remote ",
0 , &showlist);
add_cmd ("compare-sections", class_obscure, compare_sections_command, _("\
Compare section data on target to the exec file.\n\
Argument is a single section name (default: all loaded sections)."),
&cmdlist);
add_cmd ("packet", class_maintenance, packet_command, _("\
Send an arbitrary packet to a remote target.\n\
maintenance packet TEXT\n\
If GDB is talking to an inferior via the GDB serial protocol, then\n\
this command sends the string TEXT to the inferior, and displays the\n\
response packet. GDB supplies the initial `$' character, and the\n\
terminating `#' character and checksum."),
&maintenancelist);
add_setshow_boolean_cmd ("remotebreak", no_class, &remote_break, _("\
Set whether to send break if interrupted."), _("\
Show whether to send break if interrupted."), _("\
If set, a break, instead of a cntrl-c, is sent to the remote target."),
NULL, NULL,
&setlist, &showlist);
add_cmd ("remotewritesize", no_class, set_memory_write_packet_size, _("\
Set the maximum number of bytes per memory write packet (deprecated)."),
&setlist);
add_cmd ("remotewritesize", no_class, show_memory_write_packet_size, _("\
Show the maximum number of bytes per memory write packet (deprecated)."),
&showlist);
add_cmd ("memory-write-packet-size", no_class,
set_memory_write_packet_size, _("\
Set the maximum number of bytes per memory-write packet.\n\
Specify the number of bytes in a packet or 0 (zero) for the\n\
default packet size. The actual limit is further reduced\n\
dependent on the target. Specify ``fixed'' to disable the\n\
further restriction and ``limit'' to enable that restriction."),
&remote_set_cmdlist);
add_cmd ("memory-read-packet-size", no_class,
set_memory_read_packet_size, _("\
Set the maximum number of bytes per memory-read packet.\n\
Specify the number of bytes in a packet or 0 (zero) for the\n\
default packet size. The actual limit is further reduced\n\
dependent on the target. Specify ``fixed'' to disable the\n\
further restriction and ``limit'' to enable that restriction."),
&remote_set_cmdlist);
add_cmd ("memory-write-packet-size", no_class,
show_memory_write_packet_size,
_("Show the maximum number of bytes per memory-write packet."),
&remote_show_cmdlist);
add_cmd ("memory-read-packet-size", no_class,
show_memory_read_packet_size,
_("Show the maximum number of bytes per memory-read packet."),
&remote_show_cmdlist);
add_setshow_zinteger_cmd ("hardware-watchpoint-limit", no_class,
&remote_hw_watchpoint_limit, _("\
Set the maximum number of target hardware watchpoints."), _("\
Show the maximum number of target hardware watchpoints."), _("\
Specify a negative limit for unlimited."),
NULL, NULL,
&remote_set_cmdlist, &remote_show_cmdlist);
add_setshow_zinteger_cmd ("hardware-breakpoint-limit", no_class,
&remote_hw_breakpoint_limit, _("\
Set the maximum number of target hardware breakpoints."), _("\
Show the maximum number of target hardware breakpoints."), _("\
Specify a negative limit for unlimited."),
NULL, NULL,
&remote_set_cmdlist, &remote_show_cmdlist);
add_setshow_integer_cmd ("remoteaddresssize", class_obscure,
&remote_address_size, _("\
Set the maximum size of the address (in bits) in a memory packet."), _("\
Show the maximum size of the address (in bits) in a memory packet."), NULL,
NULL,
NULL,
&setlist, &showlist);
add_packet_config_cmd (&remote_protocol_binary_download,
"X", "binary-download",
set_remote_protocol_binary_download_cmd,
show_remote_protocol_binary_download_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
1);
add_packet_config_cmd (&remote_protocol_vcont,
"vCont", "verbose-resume",
set_remote_protocol_vcont_packet_cmd,
show_remote_protocol_vcont_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_packet_config_cmd (&remote_protocol_qSymbol,
"qSymbol", "symbol-lookup",
set_remote_protocol_qSymbol_packet_cmd,
show_remote_protocol_qSymbol_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_packet_config_cmd (&remote_protocol_P,
"P", "set-register",
set_remote_protocol_P_packet_cmd,
show_remote_protocol_P_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
1);
add_packet_config_cmd (&remote_protocol_p,
"p", "fetch-register",
set_remote_protocol_p_packet_cmd,
show_remote_protocol_p_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
1);
add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_SOFTWARE_BP],
"Z0", "software-breakpoint",
set_remote_protocol_Z_software_bp_packet_cmd,
show_remote_protocol_Z_software_bp_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_HARDWARE_BP],
"Z1", "hardware-breakpoint",
set_remote_protocol_Z_hardware_bp_packet_cmd,
show_remote_protocol_Z_hardware_bp_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_WRITE_WP],
"Z2", "write-watchpoint",
set_remote_protocol_Z_write_wp_packet_cmd,
show_remote_protocol_Z_write_wp_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_READ_WP],
"Z3", "read-watchpoint",
set_remote_protocol_Z_read_wp_packet_cmd,
show_remote_protocol_Z_read_wp_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_packet_config_cmd (&remote_protocol_Z[Z_PACKET_ACCESS_WP],
"Z4", "access-watchpoint",
set_remote_protocol_Z_access_wp_packet_cmd,
show_remote_protocol_Z_access_wp_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_packet_config_cmd (&remote_protocol_qPart_auxv,
"qPart_auxv", "read-aux-vector",
set_remote_protocol_qPart_auxv_packet_cmd,
show_remote_protocol_qPart_auxv_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_packet_config_cmd (&remote_protocol_qGetTLSAddr,
"qGetTLSAddr", "get-thread-local-storage-address",
set_remote_protocol_qGetTLSAddr_packet_cmd,
show_remote_protocol_qGetTLSAddr_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist,
0);
add_setshow_auto_boolean_cmd ("Z-packet", class_obscure,
&remote_Z_packet_detect, _("\
Set use of remote protocol `Z' packets"), _("\
Show use of remote protocol `Z' packets "), _("\
When set, GDB will attempt to use the remote breakpoint and watchpoint\n\
packets."),
set_remote_protocol_Z_packet_cmd,
show_remote_protocol_Z_packet_cmd,
&remote_set_cmdlist, &remote_show_cmdlist);
initialize_remote_fileio (remote_set_cmdlist, remote_show_cmdlist);
}