31 #include <sys/ioctl.h> 37 #include <netinet/in.h> 40 #include <sys/socket.h> 45 #if HAVE_NETINET_TCP_H 46 #include <netinet/tcp.h> 49 #include <sys/ioctl.h> 60 #include <arpa/inet.h> 69 #include <sys/iomgr.h> 72 #ifndef HAVE_SOCKLEN_T 76 #ifndef IN_PROCESS_AGENT 79 # define INVALID_DESCRIPTOR INVALID_SOCKET 81 # define INVALID_DESCRIPTOR -1 124 # define read(fd, buf, len) recv (fd, (char *) buf, len, 0) 125 # define write(fd, buf, len) send (fd, (char *) buf, len, 0) 145 #if defined(F_SETFL) && defined (FASYNC) 146 int save_fcntl_flags;
148 save_fcntl_flags =
fcntl (fd, F_GETFL, 0);
149 fcntl (fd, F_SETFL, save_fcntl_flags | FASYNC);
150 #if defined (F_SETOWN) 151 fcntl (fd, F_SETOWN, getpid ());
159 struct sockaddr_in sockaddr;
165 tmp =
sizeof (sockaddr);
173 (
char *) &tmp,
sizeof (tmp));
179 (
char *) &tmp,
sizeof (tmp));
182 signal (SIGPIPE, SIG_IGN);
200 fprintf (stderr,
"Remote debugging from host %s\n",
201 inet_ntoa (sockaddr.sin_addr));
225 const char *port_str;
227 static int winsock_initialized;
230 struct sockaddr_in sockaddr;
245 port_str = strchr (
name,
':');
246 if (port_str == NULL)
252 port = strtoul (port_str + 1, &port_end, 10);
253 if (port_str[1] ==
'\0' || *port_end !=
'\0')
257 if (!winsock_initialized)
261 WSAStartup (MAKEWORD (1, 0), &wsad);
262 winsock_initialized = 1;
266 listen_desc = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
272 setsockopt (
listen_desc, SOL_SOCKET, SO_REUSEADDR, (
char *) &tmp,
275 sockaddr.sin_family = PF_INET;
276 sockaddr.sin_port = htons (port);
277 sockaddr.sin_addr.s_addr = INADDR_ANY;
279 if (bind (
listen_desc, (
struct sockaddr *) &sockaddr,
sizeof (sockaddr))
292 const char *port_str;
294 port_str = strchr (
name,
':');
296 if (port_str == NULL)
297 error (
"Only <host>:<port> is supported on this platform.");
302 fprintf (stderr,
"Remote debugging using stdio\n");
314 else if (port_str == NULL)
318 if (stat (
name, &statbuf) == 0
332 struct termios termios;
338 termios.c_cflag &= ~(CSIZE | PARENB);
339 termios.c_cflag |= CLOCAL | CS8;
340 termios.c_cc[VMIN] = 1;
341 termios.c_cc[VTIME] = 0;
347 fprintf (stderr,
"Remote debugging using %s\n",
name);
359 struct sockaddr_in sockaddr;
361 len =
sizeof (sockaddr);
363 (
struct sockaddr *) &sockaddr, &len) < 0
364 || len <
sizeof (sockaddr))
366 port = ntohs (sockaddr.sin_port);
368 fprintf (stderr,
"Listening on port %d\n", port);
396 #ifndef IN_PROCESS_AGENT 406 for (i = 0; i < len; i++)
410 addr = addr | (
fromhex (ch) & 0x0f);
421 while (*end !=
'\0' && *end !=
';')
433 #ifndef IN_PROCESS_AGENT 440 try_rle (
char *buf,
int remaining,
unsigned char *csum,
char **p)
452 for (n = 1; n < remaining; n++)
453 if (buf[n] != buf[0])
468 while (n + 29 ==
'$' || n + 29 ==
'#')
481 #ifndef IN_PROCESS_AGENT 494 buf += sprintf (buf,
"p-%x.", -pid);
496 buf += sprintf (buf,
"p%x.", pid);
500 buf += sprintf (buf,
"-%x", -tid);
502 buf += sprintf (buf,
"%x", tid);
540 error (
"invalid remote ptid: %s\n", p);
572 return write (fileno (stdout), buf, count);
585 return read (fileno (stdin), buf, count);
598 unsigned char csum = 0;
603 buf2 = (
char *)
xmalloc (strlen (
"$") + cnt + strlen (
"#nn") + 1);
614 for (i = 0; i < cnt;)
615 i +=
try_rle (buf + i, cnt - i, &csum, &p);
618 *p++ =
tohex ((csum >> 4) & 0xf);
619 *p++ =
tohex (csum & 0xf);
650 debug_printf (
"putpkt (\"%s\"); [looking for ack]\n", buf2);
710 struct timeval immediate = { 0, 0 };
717 if (select (
remote_desc + 1, &readset, 0, 0, &immediate) > 0)
726 fprintf (stderr,
"client connection closed\n");
729 else if (cc != 1 || c !=
'\003')
731 fprintf (stderr,
"input_interrupt, count = %d c = %d ", cc, c);
733 fprintf (stderr,
"('%c')\n", c);
735 fprintf (stderr,
"('\\x%02x')\n", c & 0xff);
766 sigemptyset (&sigio_set);
767 sigaddset (&sigio_set, SIGIO);
768 sigprocmask (block ? SIG_BLOCK : SIG_UNBLOCK, &sigio_set, NULL);
774 nto_comctrl (
int enable)
776 struct sigevent event;
780 event.sigev_notify = SIGEV_SIGNAL_THREAD;
781 event.sigev_signo = SIGIO;
782 event.sigev_code = 0;
783 event.sigev_value.sival_ptr = NULL;
784 event.sigev_priority = -1;
785 ionotify (
remote_desc, _NOTIFY_ACTION_POLLARM, _NOTIFY_COND_INPUT,
789 ionotify (
remote_desc, _NOTIFY_ACTION_POLL, _NOTIFY_COND_INPUT, NULL);
930 unsigned char csum, c1, c2;
977 if (csum == (c1 << 4) + c2)
983 "Bad checksum, sentsum=0x%x, csum=0x%x, " 984 "buf=%s [no-ack-mode, Bad medium?]\n",
985 (c1 << 4) + c2, csum, buf);
990 fprintf (stderr,
"Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
991 (c1 << 4) + c2, csum, buf);
1000 debug_printf (
"getpkt (\"%s\"); [sending ack] \n", buf);
1017 debug_printf (
"getpkt (\"%s\"); [no ack sent] \n", buf);
1061 #ifndef IN_PROCESS_AGENT 1066 if ((regno >> 12) != 0)
1067 *buf++ =
tohex ((regno >> 12) & 0xf);
1068 if ((regno >> 8) != 0)
1069 *buf++ =
tohex ((regno >> 8) & 0xf);
1070 *buf++ =
tohex ((regno >> 4) & 0xf);
1071 *buf++ =
tohex (regno & 0xf);
1082 struct target_waitstatus *status)
1088 switch (status->kind)
1090 case TARGET_WAITKIND_STOPPED:
1091 case TARGET_WAITKIND_FORKED:
1092 case TARGET_WAITKIND_VFORKED:
1093 case TARGET_WAITKIND_VFORK_DONE:
1094 case TARGET_WAITKIND_EXECD:
1095 case TARGET_WAITKIND_THREAD_CREATED:
1096 case TARGET_WAITKIND_SYSCALL_ENTRY:
1097 case TARGET_WAITKIND_SYSCALL_RETURN:
1106 enum gdb_signal signal = GDB_SIGNAL_TRAP;
1107 const char *
event = (status->kind == TARGET_WAITKIND_FORKED
1108 ?
"fork" :
"vfork");
1110 sprintf (buf,
"T%02x%s:", signal, event);
1111 buf += strlen (buf);
1112 buf =
write_ptid (buf, status->value.related_pid);
1117 enum gdb_signal signal = GDB_SIGNAL_TRAP;
1119 sprintf (buf,
"T%02xvforkdone:;", signal);
1123 enum gdb_signal signal = GDB_SIGNAL_TRAP;
1124 const char *
event =
"exec";
1125 char hexified_pathname[PATH_MAX * 2];
1127 sprintf (buf,
"T%02x%s:", signal, event);
1128 buf += strlen (buf);
1133 strlen (status->value.execd_pathname));
1135 sprintf (buf,
"%s;", hexified_pathname);
1136 xfree (status->value.execd_pathname);
1137 status->value.execd_pathname = NULL;
1138 buf += strlen (buf);
1140 else if (status->kind == TARGET_WAITKIND_THREAD_CREATED
1143 enum gdb_signal signal = GDB_SIGNAL_TRAP;
1145 sprintf (buf,
"T%02xcreate:;", signal);
1147 else if (status->kind == TARGET_WAITKIND_SYSCALL_ENTRY
1148 || status->kind == TARGET_WAITKIND_SYSCALL_RETURN)
1150 enum gdb_signal signal = GDB_SIGNAL_TRAP;
1151 const char *
event = (status->kind == TARGET_WAITKIND_SYSCALL_ENTRY
1152 ?
"syscall_entry" :
"syscall_return");
1154 sprintf (buf,
"T%02x%s:%x;", signal, event,
1155 status->value.syscall_number);
1158 sprintf (buf,
"T%02x", status->value.sig);
1160 buf += strlen (buf);
1176 memcpy (buf,
"watch:", 6);
1185 for (i =
sizeof (
void *) * 2; i > 0; i--)
1186 *buf++ =
tohex ((addr >> (i - 1) * 4) & 0xf);
1191 sprintf (buf,
"swbreak:;");
1192 buf += strlen (buf);
1196 sprintf (buf,
"hwbreak:;");
1197 buf += strlen (buf);
1229 sprintf (buf,
"thread:");
1230 buf += strlen (buf);
1233 buf += strlen (buf);
1239 sprintf (buf,
"core:");
1240 buf += strlen (buf);
1241 sprintf (buf,
"%x", core);
1243 buf += strlen (buf);
1250 strcpy (buf,
"library:;");
1251 buf += strlen (buf);
1258 case TARGET_WAITKIND_EXITED:
1260 sprintf (buf,
"W%x;process:%x",
1263 sprintf (buf,
"W%02x", status->value.integer);
1265 case TARGET_WAITKIND_SIGNALLED:
1267 sprintf (buf,
"X%x;process:%x",
1270 sprintf (buf,
"X%02x", status->value.sig);
1272 case TARGET_WAITKIND_THREAD_EXITED:
1273 sprintf (buf,
"w%x;", status->value.integer);
1274 buf += strlen (buf);
1277 case TARGET_WAITKIND_NO_RESUMED:
1281 error (
"unhandled waitkind");
1291 *mem_addr_ptr = *len_ptr = 0;
1293 while ((ch = from[i++]) !=
',')
1295 *mem_addr_ptr = *mem_addr_ptr << 4;
1296 *mem_addr_ptr |=
fromhex (ch) & 0x0f;
1299 for (j = 0; j < 4; j++)
1301 if ((ch = from[i++]) == 0)
1303 *len_ptr = *len_ptr << 4;
1304 *len_ptr |=
fromhex (ch) & 0x0f;
1310 unsigned char **to_p)
1314 *mem_addr_ptr = *len_ptr = 0;
1316 while ((ch = from[i++]) !=
',')
1318 *mem_addr_ptr = *mem_addr_ptr << 4;
1319 *mem_addr_ptr |=
fromhex (ch) & 0x0f;
1322 while ((ch = from[i++]) !=
':')
1324 *len_ptr = *len_ptr << 4;
1325 *len_ptr |=
fromhex (ch) & 0x0f;
1329 *to_p = (
unsigned char *)
xmalloc (*len_ptr);
1331 hex2bin (&from[i++], *to_p, *len_ptr);
1336 unsigned int *len_ptr,
unsigned char **to_p)
1340 *mem_addr_ptr = *len_ptr = 0;
1342 while ((ch = from[i++]) !=
',')
1344 *mem_addr_ptr = *mem_addr_ptr << 4;
1345 *mem_addr_ptr |=
fromhex (ch) & 0x0f;
1348 while ((ch = from[i++]) !=
':')
1350 *len_ptr = *len_ptr << 4;
1351 *len_ptr |=
fromhex (ch) & 0x0f;
1355 *to_p = (
unsigned char *)
xmalloc (*len_ptr);
1358 *to_p, *len_ptr) != *len_ptr)
1368 unsigned int *len,
unsigned char *data)
1375 while ((ch = *buf++) !=
':')
1382 packet_len -= buf - b;
1394 gdb_byte *pattern,
unsigned int *pattern_lenp)
1396 const char *p = buf;
1400 packet_len -= p - buf;
1402 pattern, packet_len);
1422 for (sym = *symcache_p; sym; sym =
next)
1481 unsigned int mem_len;
1511 warning (
"Malformed response to qSymbol, ignoring: %s\n",
own_buf);
1515 p =
own_buf + strlen (
"qSymbol:");
1517 while (*q && *q !=
':')
1521 if (p == q || *q ==
'\0')
1572 unsigned char *
mem_buf = NULL;
1573 unsigned int mem_len;
1611 warning (
"An error occurred while relocating an instruction: %s\n",
1618 warning (
"Malformed response to qRelocInsn, ignoring: %s\n",
1632 int len = strlen (msg);
1633 char *buf = (
char *)
xmalloc (len * 2 + 2);
const struct target_desc * tdesc
static int putpkt_binary_1(char *buf, int cnt, int is_notif)
void delete_callback_event(int id)
void remote_prepare(const char *name)
int handle_serial_event(int err, gdb_client_data client_data)
struct thread_info * current_thread
void monitor_output(const char *msg)
static int remote_is_stdio
static void xfree(T *ptr)
int remote_unescape_input(const gdb_byte *buffer, int len, gdb_byte *out_buf, int out_maxlen)
#define target_core_of_thread(ptid)
int(* stopped_by_watchpoint)(void)
void clear_symbol_cache(struct sym_cache **symcache_p)
int putpkt_binary(char *buf, int cnt)
ptid_t read_ptid(const char *buf, const char **obuf)
int ptid_get_pid(const ptid_t &ptid)
const char ** expedite_regs
int decode_xfer_write(char *buf, int packet_len, CORE_ADDR *offset, unsigned int *len, unsigned char *data)
static void block_unblock_async_io(int block)
static void reschedule(void)
void prepare_resume_reply(char *buf, ptid_t ptid, struct target_waitstatus *status)
void warning(const char *fmt,...)
#define target_stopped_by_hw_breakpoint()
struct ui_file * gdb_stdlog
static void enable_async_notification(int fd)
int bin2hex(const gdb_byte *bin, char *hex, int count)
void enable_async_io(void)
static void reset_readchar(void)
void initialize_async_io(void)
char * paddress(CORE_ADDR addr)
void handle_v_requests(char *own_buf, int packet_len, int *new_packet_len)
static int write_prim(const void *buf, int count)
char * write_ptid(char *buf, ptid_t ptid)
void remote_open(const char *name)
process_info * get_first_process(void)
static int pid_of(const thread_info *thread)
struct target_ops * the_target
void perror(const char *)
void disable_async_io(void)
static int read_prim(void *buf, int count)
char * xstrdup(const char *s)
ptid_t ptid_build(int pid, long lwp, long tid)
#define STDIO_CONNECTION_NAME
void decode_address(CORE_ADDR *addrp, const char *start, int len)
static int async_io_enabled
#define target_stopped_by_sw_breakpoint()
static int process_remaining(void *context)
static char * outreg(struct regcache *regcache, int regno, char *buf)
int remote_connection_is_stdio(void)
void delete_file_handler(gdb_fildes_t fd)
void collect_register_as_string(struct regcache *regcache, int n, char *buf)
const char * decode_address_to_semicolon(CORE_ADDR *addrp, const char *start)
void(* request_interrupt)(void)
static int readchar(void)
int read_inferior_memory(CORE_ADDR memaddr, unsigned char *myaddr, int len)
static gdb_fildes_t remote_desc
static int readchar_callback
int register_size(const struct target_desc *tdesc, int n)
void decode_m_packet(char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
int look_up_one_symbol(const char *name, CORE_ADDR *addrp, int may_ask_gdb)
int disable_packet_Tthread
int decode_search_memory_packet(const char *buf, int packet_len, CORE_ADDR *start_addrp, CORE_ADDR *search_space_lenp, gdb_byte *pattern, unsigned int *pattern_lenp)
static int startswith(const char *string, const char *pattern)
#define INVALID_DESCRIPTOR
static unsigned char * mem_buf
struct process_info * current_process(void)
int putpkt_notif(char *buf)
long ptid_get_lwp(const ptid_t &ptid)
int append_callback_event(callback_handler_func *proc, gdb_client_data data)
int write_inferior_memory(CORE_ADDR memaddr, const unsigned char *myaddr, int len)
void switch_to_thread(ptid_t ptid)
void add_file_handler(gdb_fildes_t fd, handler_func *proc, gdb_client_data client_data)
static gdb_fildes_t listen_desc
struct sym_cache * symbol_cache
void decode_M_packet(char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr, unsigned char **to_p)
static void free_sym_cache(struct sym_cache *sym)
int find_regno(const struct target_desc *tdesc, const char *name)
const struct target_desc * current_target_desc(void)
static unsigned char readchar_buf[BUFSIZ]
static unsigned char * readchar_bufp
#define target_async(enable)
static int try_rle(char *buf, int remaining, unsigned char *csum, char **p)
const char * target_pid_to_str(ptid_t ptid)
struct regcache * get_thread_regcache(struct thread_info *thread, int fetch)
void perror_with_name(const char *string)
int ptid_equal(const ptid_t &ptid1, const ptid_t &ptid2)
unsigned long long ULONGEST
static int handle_accept_event(int err, gdb_client_data client_data)
int hex2bin(const char *hex, gdb_byte *bin, int count)
const char * unpack_varlen_hex(const char *buff, ULONGEST *result)
void debug_printf(const char *fmt,...)
int transport_is_reliable
static void input_interrupt(int unused)
void check_remote_input_interrupt_request(void)
CORE_ADDR(* stopped_data_address)(void)
int decode_X_packet(char *from, int packet_len, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr, unsigned char **to_p)
static int readchar_bufcnt
void error(const char *fmt,...)
static ULONGEST hex_or_minus_one(const char *buf, const char **obuf)
int relocate_instruction(CORE_ADDR *to, CORE_ADDR oldloc)
void write_enn(char *buf)