?? remote-utils.c
字號:
/* Remote utility routines for the remote server for GDB. Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc.This file is part of GDB.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "server.h"#include <stdio.h>int gdb_fd;/* Convert hex digit A to a number. */static intfromhex (a) int a;{ if (a >= '0' && a <= '9') return a - '0'; else if (a >= 'a' && a <= 'f') return a - 'a' + 10; else error ("Reply contains invalid hex digit");}/* Convert number NIB to a hex digit. */static inttohex (nib) int nib;{ if (nib < 10) return '0' + nib; else return 'a' + nib - 10;}/* Send a packet to the remote machine, with error checking. The data of the packet is in BUF. Returns >= 0 on success, -1 otherwise. */intputpkt (buf) char *buf;{ int i; unsigned char csum = 0;// char buf2[200]; char buf2[200];//tanghao char buf3[1]; int cnt = strlen (buf); char *p; /* Copy the packet into buffer BUF2, encapsulating it and giving it a checksum. */ 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); *p = '\0'; //tanghao /* Send it over and over until we get a positive ack. */ do {/*original one tanghao int cc; write (gdb_fd, buf2, p - buf2); cc = read (gdb_fd, buf3, 1); if (cc <= 0) return -1;*/ int cc; if (write (gdb_fd, buf2, p - buf2) != p - buf2) { fprintf (stderr, "putpkt(write)\n\r"); return -1; } if (gdb_fd) printf ("putpkt (\"%s\"); [looking for ack]\n\r", buf2); cc = read (gdb_fd, buf3, 1); if (gdb_fd) printf ("[received '%c' (0x%x)]\n\r", buf3[0], buf3[0]); if (cc <= 0) { if (cc == 0) fprintf (stderr, "putpkt(read): Got EOF\n\r"); else fprintf (stderr, "putpkt(read)\n\r"); return -1; } } while (buf3[0] != '+'); return 1; /* Success! */}/* Come here when we get an input interrupt from the remote side. This interrupt should only be active while we are waiting for the child to do something. About the only thing that should come through is a ^C, which will cause us to send a SIGINT to the child. */static voidinput_interrupt(){ int cc; char c; cc = read (gdb_fd, &c, 1); if (cc != 1 || c != '\003') { return; } /* kill inferior */}voidenable_async_io(){/* signal (SIGIO, input_interrupt); */}voiddisable_async_io(){/* signal (SIGIO, SIG_IGN); */}/* Returns next char from remote GDB. -1 if error. */static intreadchar (){ char buf; read (gdb_fd, &buf, 1); return buf & 0x7f;}/* Read a packet from the remote machine, with error checking, and store it in BUF. Returns length of packet, or negative if error. */intgetpkt (buf) char *buf;{ char *bp; unsigned char csum, c1, c2; int c; while (1) { csum = 0; while (1) { c = readchar (); if (c == '$') break; if (gdb_fd) //tanghao printf ("[getpkt: discarding char '%c']\n\r", c); //tanghao if (c < 0) return -1; } bp = buf; while (1) { c = readchar (); if (c < 0) return -1; if (c == '#') break; *bp++ = c; csum += c; } *bp = 0; c1 = fromhex (readchar ()); c2 = fromhex (readchar ()); if (csum == (c1 << 4) + c2) break; fprintf (stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n\r", (c1 << 4) + c2, csum, buf); //tanghao//tanghao write (stdout, "-", 1); write (gdb_fd, "-", 1); } if (gdb_fd) //tanghao printf ("getpkt (\"%s\"); [sending ack] \n\r", buf); write (gdb_fd, "+", 1); if (gdb_fd) //tanghao printf ("[sent ack]\n\r"); return bp - buf;}voidwrite_ok (buf) char *buf;{ buf[0] = 'O'; buf[1] = 'K'; buf[2] = '\0';}voidwrite_enn (buf) char *buf;{ buf[0] = 'E'; buf[1] = 'N'; buf[2] = 'N'; buf[3] = '\0';}voidconvert_int_to_ascii (from, to, n) char *from, *to; int n;{ int nib; char ch; while (n--) { ch = *from++; nib = ((ch & 0xf0) >> 4) & 0x0f; *to++ = tohex (nib); nib = ch & 0x0f; *to++ = tohex (nib); } *to++ = 0;}voidconvert_ascii_to_int (from, to, n) char *from, *to; int n;{ int nib1, nib2; while (n--) { nib1 = fromhex (*from++); nib2 = fromhex (*from++); *to++ = (((nib1 & 0x0f) << 4) & 0xf0) | (nib2 & 0x0f); }}static char *outreg(regno, buf) int regno; char *buf;{ *buf++ = tohex (regno >> 4); *buf++ = tohex (regno & 0xf); *buf++ = ':'; convert_int_to_ascii (®isters[regno], buf, 4); buf += 8; *buf++ = ';'; return buf;}voidprepare_resume_reply (buf, status, signal) char *buf; char status; unsigned char signal;{ int nib; char ch; *buf++ = status; nib = ((signal & 0xf0) >> 4); *buf++ = tohex (nib); nib = signal & 0x0f; *buf++ = tohex (nib); if (status == 'T') { buf = outreg (17, buf); buf = outreg (14, buf); buf = outreg (15, buf); } /* For W and X, we're done. */ *buf++ = 0;}voiddecode_m_packet (from, mem_addr_ptr, len_ptr) char *from; unsigned int *mem_addr_ptr, *len_ptr;{ int i = 0, j = 0; char ch; *mem_addr_ptr = *len_ptr = 0; while ((ch = from[i++]) != ',') { *mem_addr_ptr = *mem_addr_ptr << 4; *mem_addr_ptr |= fromhex (ch) & 0x0f; } for (j = 0; j < 4; j++) { if ((ch = from[i++]) == 0) break; *len_ptr = *len_ptr << 4; *len_ptr |= fromhex (ch) & 0x0f; }}voiddecode_M_packet (from, mem_addr_ptr, len_ptr, to) char *from, *to; unsigned int *mem_addr_ptr, *len_ptr;{ int i = 0, j = 0; char ch; *mem_addr_ptr = *len_ptr = 0; while ((ch = from[i++]) != ',') { *mem_addr_ptr = *mem_addr_ptr << 4; *mem_addr_ptr |= fromhex (ch) & 0x0f; } while ((ch = from[i++]) != ':') { *len_ptr = *len_ptr << 4; *len_ptr |= fromhex (ch) & 0x0f; } convert_ascii_to_int (&from[i++], to, *len_ptr);}voiddecode_z_packet (from, breaktype, mem_addr_ptr, length) char *from; unsigned int *breaktype, *mem_addr_ptr, *length;{ int i = 0, j = 0; char ch; *breaktype = *mem_addr_ptr = *length =0; while ((ch = from[i++]) != ',') { *breaktype = *breaktype << 4; *breaktype |= fromhex (ch) & 0x0f; } while ((ch = from[i++]) != ',') { *mem_addr_ptr = *mem_addr_ptr << 4; *mem_addr_ptr |= fromhex (ch) & 0x0f; } while ((ch = from[i++]) != '\0') { *length = *length << 4; *length |= fromhex (ch) & 0x0f; }}voiddecode_Z_packet (from, breaktype, mem_addr_ptr, length) char *from; unsigned int *breaktype, *mem_addr_ptr, *length;{ int i = 0, j = 0; char ch; *breaktype = *mem_addr_ptr = *length =0; while ((ch = from[i++]) != ',') { *breaktype = *breaktype << 4; *breaktype |= fromhex (ch) & 0x0f; } while ((ch = from[i++]) != ',') { *mem_addr_ptr = *mem_addr_ptr << 4; *mem_addr_ptr |= fromhex (ch) & 0x0f; } while ((ch = from[i++]) != '\0') { *length = *length << 4; *length |= fromhex (ch) & 0x0f; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -