45 #include <sys/types.h>
56 #include "readline/readline.h"
68 static int from_hex (
int a);
87 static struct serial *monitor_desc = NULL;
117 #define TARGET_BUF_SIZE 2048
137 va_start (args, fmt);
155 len = strlen (oldstr);
157 for (i = 0; i <
len; i++)
168 sprintf (newstr,
"\\x%02x", ch & 0xff);
212 CORE_ADDR memaddr,
int len,
char *
string,
int final_char)
214 int real_len = (len == 0 &&
string != (
char *) 0) ? strlen (
string) :
len;
215 char *safe_string = alloca ((real_len * 4) + 1);
220 error (
_(
"%s (%s): %s: %s%c"),
222 message, safe_string, final_char);
224 error (
_(
"%s (%s): %s: %s"),
226 message, safe_string);
254 for (p = pattern; *p; p++)
260 for (i = 1; *p >=
'0' && *p <=
'9' && i < (
int)
sizeof (format) - 2;
263 format[i] = fmt = *p;
264 format[i + 1] =
'\0';
270 strcpy (sndbuf,
"%");
274 strcpy (sndbuf,
phex_nz (arg_addr, addr_bit / 8));
277 arg_string = va_arg (args,
char *);
278 sprintf (sndbuf, format, arg_string);
281 arg_int = va_arg (args,
long);
282 sprintf (sndbuf, format, arg_int);
285 sndbuf += strlen (sndbuf);
304 va_start (args, pattern);
308 len = strlen (sndbuf);
309 if (len + 1 >
sizeof sndbuf)
311 _(
"failed internal consistency check"));
315 char *safe_string = (
char *) alloca ((strlen (sndbuf) * 4) + 1);
334 va_start (args, pattern);
338 len = strlen (sndbuf);
339 if (len + 1 >
sizeof sndbuf)
341 _(
"failed internal consistency check"));
345 char *safe_string = (
char *) alloca ((len * 4) + 1);
398 error (
_(
"Timeout reading from remote system."));
413 last_random, last_nl, last_cr, last_crnl
442 if ((c ==
'\r' && state == last_nl)
443 || (c ==
'\n' && state == last_cr))
470 error (
_(
"GDB serial timeout has expired. Target detached."));
474 error (
_(
"Timeout reading from remote system."));
490 int obuflen = buflen;
495 char *safe_string = (
char *) alloca ((strlen (
string) * 4) + 1);
524 if (*p ==
'\003' || c == *p)
534 return obuflen - buflen;
565 for (i = (p -
string) - 1; i >= 0; i--)
571 if (! memcmp (
string, p - i, i))
605 if (p - mybuf >= buflen)
611 memcpy (mybuf, mybuf + buflen / 2, buflen / 2);
612 p = mybuf + buflen / 2;
617 retval = re_search (pat, mybuf, p - mybuf, 0, p - mybuf, NULL);
657 while (isspace (ch));
661 for (i = 7; i >= 1; i--)
666 val = (val << 4) | from_hex (ch);
680 compiled_pattern->fastmap = fastmap;
682 tmp = re_set_syntax (RE_SYNTAX_EMACS);
683 val = re_compile_pattern (pattern,
689 error (
_(
"compile_pattern: Can't compile pattern string `%s': %s!"),
693 re_compile_fastmap (compiled_pattern);
707 error (
_(
"Magic number of monitor_ops struct wrong."));
709 targ_ops = mon_ops->
target;
713 error (
_(
"Use `target %s DEVICE-NAME' to use a serial port, or\n\
714 `target %s HOST-NAME:PORT-NUMBER' to use a network connection."), name, name);
726 getmem_resp_delim_fastmap);
730 setmem_resp_delim_fastmap);
734 setreg_resp_delim_fastmap);
740 dev_name = xstrdup (args);
765 current_monitor = mon_ops;
770 if (current_monitor->
stop)
781 for (p = mon_ops->
init; *p != NULL; p++)
848 if (breakaddr != NULL)
884 while (p && *p !=
'\0')
886 if (*p ==
'\r' || *p ==
'\n')
897 if (!isxdigit (*p) && *p !=
'x')
907 if (val == 0 && valstr == p)
908 error (
_(
"monitor_supply_register (%d): bad value from monitor: %s."),
961 int regnamelen, vallen;
966 struct re_registers register_strings;
968 memset (®ister_strings, 0,
sizeof (
struct re_registers));
971 ®ister_strings) == -1)
974 regnamelen = register_strings.end[1] - register_strings.start[1];
975 regname = buf + register_strings.start[1];
976 vallen = register_strings.end[2] - register_strings.start[2];
977 val = buf + register_strings.start[2];
982 buf += register_strings.end[0];
983 len -= register_strings.end[0];
1007 signal (signo,
ofunc);
1021 if (
query (
_(
"Interrupted while waiting for the program.\n\
1022 Give up (and stop debugging it)? ")))
1034 timeout = *(
int *) old_timeout;
1035 signal (SIGINT,
ofunc);
1036 in_monitor_wait = 0;
1052 *ext_resp_len = resp_len;
1056 "monitor_wait: excessive "
1057 "response from monitor: %s.", buf);
1059 while (resp_len < 0);
1068 for (i = 0; i < resp_len - 1; i++)
1096 in_monitor_wait = 1;
1116 "monitor_wait: excessive "
1117 "response from monitor: %s.", buf);
1119 while (resp_len < 0);
1128 for (i = 0; i < resp_len - 1; i++)
1134 signal (SIGINT,
ofunc);
1136 timeout = old_timeout;
1153 status->
value.
sig = GDB_SIGNAL_TRAP;
1157 in_monitor_wait = 0;
1177 if (current_monitor->
regname != NULL)
1178 name = current_monitor->
regname (regno);
1180 name = current_monitor->
regnames[regno];
1181 monitor_debug (
"MON fetchreg %d '%s'\n", regno, name ? name :
"(null name)");
1183 if (!name || (*name ==
'\0'))
1204 && (regno & 1) != 0 && regno < 32)
1219 if ((c ==
'0') && ((c =
readchar (timeout)) ==
'x'))
1222 error (
_(
"Bad value returned from monitor "
1223 "while fetching register %x."),
1299 (*(current_monitor->
dumpregs)) (regcache);
1309 _(
"failed internal consistency check"));
1344 if (current_monitor->
regname != NULL)
1345 name = current_monitor->
regname (regno);
1347 name = current_monitor->
regnames[regno];
1349 if (!name || (*name ==
'\0'))
1431 unsigned int val, hostval;
1442 if (current_monitor->
fill)
1444 for (i = 0; i <
len; i++)
1453 (memaddr + i) - 1, 0);
1465 if ((memaddr & 0x7) == 0 && len >= 8 && current_monitor->
setmem.
cmdll)
1472 if ((memaddr & 0x3) == 0 && len >= 4 && current_monitor->
setmem.
cmdl)
1477 else if ((memaddr & 0x1) == 0 && len >= 2 && current_monitor->
setmem.
cmdw)
1492 hostval = *(
unsigned int *) myaddr;
1570 *(a + i) = *(a + j);
1576 static char *hexlate =
"0123456789abcdef";
1588 static unsigned char disbuf[8];
1589 unsigned char *
scan, *limit;
1590 unsigned char c, nib;
1596 unsigned long long *dp;
1598 dp = (
unsigned long long *) scan;
1602 while (scan < limit)
1613 *outbuff++ = hexlate[nib];
1615 *outbuff++ = hexlate[nib];
1629 static char hexstage[20];
1635 llptr = (
long long *) myaddr;
1682 if ((len > 8) && (((len & 0x07)) == 0) && current_monitor->
setmem.
cmdll)
1699 char membuf[
sizeof (
int) * 2 + 1];
1708 if ((memaddr & 0x7) == 0 && len >= 8 && current_monitor->
getmem.
cmdll)
1715 if ((memaddr & 0x3) == 0 && len >= 4 && current_monitor->
getmem.
cmdl)
1720 else if ((memaddr & 0x1) == 0 && len >= 2 && current_monitor->
getmem.
cmdw)
1756 if ((c ==
'0') && ((c =
readchar (timeout)) ==
'x'))
1760 "bad response from monitor",
1761 memaddr, 0, NULL, 0);
1767 for (i = 0; i < len * 2; i++)
1780 "bad response from monitor",
1781 memaddr, i, membuf, 0);
1807 val = strtoul (membuf, &p, 16);
1809 if (val == 0 && membuf == p)
1811 "bad value from monitor",
1812 memaddr, 0, membuf, 0);
1837 monitor_debug (
"Zero length call to monitor_read_memory\n");
1851 len =
min (len, 16);
1858 ? memaddr : memaddr & ~0x0f;
1861 if (((memaddr ^ (memaddr + len - 1)) & ~0xf) != 0)
1862 len = ((memaddr + len) & ~0xf) - memaddr;
1885 "excessive response from monitor",
1886 memaddr, resp_len, buf, 0);
1907 struct re_registers resp_strings;
1912 memset (&resp_strings, 0,
sizeof (
struct re_registers));
1919 "bad response from monitor",
1920 memaddr, resp_len, buf, 0);
1922 p += resp_strings.end[0];
1927 "bad response from monitor",
1928 memaddr, resp_len, buf, 0);
1942 while (!(c ==
'\000' || c ==
'\n' || c ==
'\r') && i > 0)
1946 if ((dumpaddr >= memaddr) && (i > 0))
1962 error (
_(
"Failed to read via monitor"));
1970 for (i = len; i > 0; i--)
1979 if (*p ==
'\000' || *p ==
'\n' || *p ==
'\r')
1981 "badly terminated response from monitor",
1982 memaddr, resp_len, buf, 0);
1986 val = strtoul (p, &p1, 16);
1988 if (val == 0 && p == p1)
1990 "bad value from monitor",
1991 memaddr, resp_len, buf, 0);
2013 if (writebuf != NULL)
2038 const char *annex,
gdb_byte *readbuf,
2062 char *args,
char **env,
int from_tty)
2064 if (args && (*args !=
'\000'))
2065 error (
_(
"Args are not supported by the monitor."));
2098 error (
_(
"No set_break defined for this monitor"));
2110 if (breakaddr[i] == 0)
2112 breakaddr[i] = addr;
2119 error (
_(
"Too many breakpoints (> %d) for monitor."),
2134 error (
_(
"No clr_break defined for this monitor"));
2138 if (breakaddr[i] == addr)
2153 "Can't find breakpoint associated with %s\n",
2168 return (
readchar (timeout) ==
'+');
2203 filename = tilde_expand (argv[0]);
2207 if (argv[1] != NULL)
2211 load_offset =
strtoulst (argv[1], &endptr, 0);
2215 if (argv[1] == endptr)
2216 error (
_(
"Invalid download offset:%s."), argv[1]);
2218 if (argv[2] != NULL)
2219 error (
_(
"Too many parameters."));
2226 load_srec (monitor_desc, filename, load_offset,
2261 if (current_monitor->
stop)
2277 if (monitor_desc == NULL)
2278 error (
_(
"monitor target not open."));
2280 p = current_monitor->
prompt;
2298 if (a >=
'0' && a <=
'9')
2300 if (a >=
'a' && a <=
'f')
2301 return a -
'a' + 10;
2302 if (a >=
'A' && a <=
'F')
2303 return a -
'A' + 10;
2305 error (
_(
"Reply contains invalid hex digit 0x%x"), a);
2333 static char buf[64];
2337 xsnprintf (buf,
sizeof buf,
"Thread <main>");
2399 Set display of activity while downloading a file."),
_(
"\
2400 Show display of activity while downloading a file."),
_(
"\
2401 When enabled, a hashmark \'#\' is displayed."),
2407 Set debugging of remote monitor communication."),
_(
"\
2408 Show debugging of remote monitor communication."),
_(
"\
2409 When enabled, communication between GDB and the remote monitor\n\
void error_no_arg(const char *why)
struct gdbarch * target_gdbarch(void)
struct cleanup * make_cleanup_freeargv(char **arg)
int default_child_has_stack(struct target_ops *ops)
void target_terminal_ours(void)
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
void monitor_printf(char *pattern,...)
int putchar_unfiltered(int c)
static void monitor_wait_filter(char *buf, int bufmax, int *ext_resp_len, struct target_waitstatus *status)
void delete_inferior_silent(int pid)
void target_stop(ptid_t ptid)
#define MO_HAS_BLOCKWRITES
void monitor_close(struct target_ops *self)
void add_setshow_zuinteger_cmd(const char *name, enum command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
static void monitor_debug(const char *fmt,...) ATTRIBUTE_PRINTF(1
#define MO_RUN_FIRST_TIME
#define MO_GETMEM_READ_SINGLE
void fputs_unfiltered(const char *buf, struct ui_file *file)
#define MO_SREC_ACK_ROTATE
static void monitor_resume(struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal sig)
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
static void monitor_stop(struct target_ops *self, ptid_t)
static void scan(struct macro_buffer *dest, struct macro_buffer *src, struct macro_name_list *no_loop, macro_lookup_ftype *lookup_func, void *lookup_baton)
struct type ** const(pascal_builtin_types[])
int query(const char *ctlstr,...)
void init_wait_for_inferior(void)
static void monitor_detach(struct target_ops *ops, const char *args, int from_tty)
static int monitor_write_memory_bytes(CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
void push_target(struct target_ops *t)
void delete_thread_silent(ptid_t)
#define MO_SEND_BREAK_ON_STOP
#define MO_FILL_USES_ADDR
char * phex(ULONGEST l, int sizeof_l)
int unpush_target(struct target_ops *t)
void internal_error(const char *file, int line, const char *fmt,...)
static struct monitor_ops * current_monitor
void generic_mourn_inferior(void)
static void monitor_mourn_inferior(struct target_ops *ops)
int serial_setstopbits(struct serial *scb, int num)
int serial_write(struct serial *scb, const void *buf, size_t count)
#define MO_SETREG_INTERACTIVE
int(* wait_filter)(char *buf, int bufmax, int *response_length, struct target_waitstatus *status)
initialize_file_ftype _initialize_remote_monitors
static struct re_pattern_buffer setreg_resp_delim_pattern
int gdbarch_num_regs(struct gdbarch *gdbarch)
static void monitor_store_register(struct regcache *regcache, int regno)
#define MO_EXACT_DUMPADDR
static int monitor_read_memory_single(CORE_ADDR memaddr, gdb_byte *myaddr, int len)
static void monitor_dump_regs(struct regcache *regcache)
static void parse_register_dump(struct regcache *regcache, char *buf, int len)
static void static unsigned int monitor_debug_p
int default_child_has_execution(struct target_ops *ops, ptid_t the_ptid)
void regcache_write_pc(struct regcache *regcache, CORE_ADDR pc)
static CORE_ADDR * breakaddr
static char getmem_resp_delim_fastmap[256]
struct regcache * get_current_regcache(void)
void store_unsigned_integer(gdb_byte *, int, enum bfd_endian, ULONGEST)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static void monitor_fetch_register(struct regcache *regcache, int regno)
static void monitor_interrupt(int signo)
ptid_t ptid_build(int pid, long lwp, long tid)
static char register_fastmap[256]
static int monitor_expect_regexp(struct re_pattern_buffer *pat, char *buf, int buflen)
static void compile_pattern(char *pattern, struct re_pattern_buffer *compiled_pattern, char *fastmap)
int default_child_has_memory(struct target_ops *ops)
void(* supply_register)(struct regcache *regcache, char *name, int namelen, char *val, int vallen)
#define MO_NEED_REGDUMP_AFTER_CONT
static void monitor_error(char *function, char *message, CORE_ADDR memaddr, int len, char *string, int final_char)
struct cmd_list_element * setlist
#define MO_ADDR_BITS_REMOVE
void serial_log_command(struct target_ops *self, const char *cmd)
static ptid_t monitor_ptid
static int readchar(int timeout)
void monitor_write(char *buf, int buflen)
#define MO_NO_ECHO_ON_SETMEM
static void monitor_kill(struct target_ops *ops)
static int monitor_write_memory_block(CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
void initialize_file_ftype(void)
int(* dumpregs)(struct regcache *)
int monitor_expect(char *string, char *buf, int buflen)
static void monitor_load(struct target_ops *self, const char *args, int from_tty)
static void longlongendswap(unsigned char *a)
enum register_status regcache_cooked_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
void vfprintf_filtered(struct ui_file *stream, const char *format, va_list args)
void target_terminal_inferior(void)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
struct cmd_list_element * showlist
int serial_setbaudrate(struct serial *scb, int rate)
int serial_flush_input(struct serial *scb)
#define MO_CLR_BREAK_1_BASED
int default_child_has_all_memory(struct target_ops *ops)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
int monitor_dump_reg_block(struct regcache *regcache, char *block_cmd)
#define MO_CLR_BREAK_USES_ADDR
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
union target_waitstatus::@161 value
static enum target_xfer_status monitor_xfer_memory(gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST memaddr, ULONGEST len, ULONGEST *xfered_len)
#define MO_PRINT_PROGRAM_OUTPUT
#define MONITOR_OPS_MAGIC
int serial_send_break(struct serial *scb)
void target_mourn_inferior(void)
static enum target_xfer_status monitor_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
static void monitor_store_registers(struct target_ops *ops, struct regcache *regcache, int regno)
void serial_raw(struct serial *scb)
static void monitor_prepare_to_store(struct target_ops *self, struct regcache *regcache)
void puts_debug(char *prefix, char *string, char *suffix)
static int monitor_remove_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
struct thread_info * add_thread_silent(ptid_t ptid)
int gdbarch_addr_bit(struct gdbarch *gdbarch)
ULONGEST strtoulst(const char *num, const char **trailer, int base)
static int monitor_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
void printf_unfiltered(const char *format,...)
struct cmd_list_element * setdebuglist
void monitor_open(const char *args, struct monitor_ops *mon_ops, int from_tty)
struct ui_file * gdb_stdlog
static int monitor_wait_srec_ack(void)
static char * longlong_hexchars(unsigned long long value, char *outbuff)
void serial_close(struct serial *scb)
char * normal_pid_to_str(ptid_t ptid)
static struct re_pattern_buffer getmem_resp_delim_pattern
static void monitor_vsprintf(char *sndbuf, char *pattern, va_list args)
struct serial * serial_open(const char *name)
int ptid_get_pid(ptid_t ptid)
static void init_base_monitor_ops(void)
static void monitor_wait_cleanup(void *old_timeout)
const char const char int
void start_remote(int from_tty)
void discard_cleanups(struct cleanup *old_chain)
#define MO_GETMEM_16_BOUNDARY
void init_monitor_ops(struct target_ops *ops)
char * phex_nz(ULONGEST l, int sizeof_l)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
int default_child_has_registers(struct target_ops *ops)
int xsnprintf(char *str, size_t size, const char *format,...)
void clear_proceed_status(int step)
enum target_waitkind kind
const gdb_byte * gdbarch_breakpoint_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
struct ui_file * gdb_stderr
static int in_monitor_wait
#define MO_SETMEM_INTERACTIVE
#define MO_32_REGS_PAIRED
char * safe_strerror(int)
const char * host_address_to_string(const void *addr)
static int monitor_thread_alive(struct target_ops *ops, ptid_t ptid)
char ** gdb_buildargv(const char *s)
static int monitor_insert_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
int(* continue_hook)(void)
char * monitor_supply_register(struct regcache *regcache, int regno, char *valstr)
int monitor_readchar(void)
static char * monitor_pid_to_str(struct target_ops *ops, ptid_t ptid)
struct target_ops * target
struct inferior * current_inferior(void)
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
const char * to_shortname
static char setreg_resp_delim_fastmap[256]
char * monitor_get_dev_name(void)
unsigned long long ULONGEST
static int monitor_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, int len)
static void ATTRIBUTE_PRINTF(6, 0)
int serial_setparity(struct serial *scb, int parity)
static void monitor_interrupt_query(void)
int register_size(struct gdbarch *gdbarch, int regnum)
static void monitor_create_inferior(struct target_ops *ops, char *exec_file, char *args, char **env, int from_tty)
static int monitor_write_memory_longlongs(CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
void load_srec(struct serial *desc, const char *file, bfd_vma load_offset, int maxrecsize, int flags, int hashmark, int(*waitack)(void))
struct cmd_list_element * showdebuglist
static ptid_t monitor_wait(struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options)
#define MO_REGISTER_VALUE_FIRST
static struct re_pattern_buffer setmem_resp_delim_pattern
void target_preopen(int from_tty)
int serial_readchar(struct serial *scb, int timeout)
static char setmem_resp_delim_fastmap[256]
int monitor_expect_prompt(char *buf, int buflen)
#define MO_NO_ECHO_ON_OPEN
static struct target_ops * targ_ops
#define MO_GETMEM_NEEDS_RANGE
enum bfd_endian byte_order
void monitor_printf_noecho(char *pattern,...)
const char *(* regname)(int index)
static void monitor_interrupt_twice(int)
static void monitor_fetch_registers(struct target_ops *ops, struct regcache *regcache, int regno)
static void monitor_rcmd(struct target_ops *self, const char *command, struct ui_file *outbuf)
void error(const char *fmt,...)
static void monitor_printable_string(char *newstr, char *oldstr, int len)
void inferior_appeared(struct inferior *inf, int pid)
void do_cleanups(struct cleanup *old_chain)
static struct re_pattern_buffer register_pattern
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static void monitor_files_info(struct target_ops *ops)
void init_thread_list(void)
const ULONGEST const LONGEST len