applied Fix GDB support patch, needs testing, but patch provider verified it to work.

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@881 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
squall-leonhart 2009-08-08 15:28:56 +00:00
parent 9d9005542c
commit 6cb59fe795
2 changed files with 150 additions and 114 deletions

View File

@ -127,12 +127,12 @@ bool remoteTcpInit()
int error = WSAGetLastError(); int error = WSAGetLastError();
#endif // _WIN32 #endif // _WIN32
} }
char dummy; //char dummy;
recv(s2, &dummy, 1, 0); //recv(s2, &dummy, 1, 0);
if(dummy != '+') { //if(dummy != '+') {
fprintf(stderr, "ACK not received\n"); // fprintf(stderr, "ACK not received\n");
exit(-1); // exit(-1);
} //}
remoteSocket = s2; remoteSocket = s2;
// close(s); // close(s);
} }
@ -167,14 +167,14 @@ int remotePipeRecv(char *data, int len)
bool remotePipeInit() bool remotePipeInit()
{ {
char dummy; // char dummy;
if (read(0, &dummy, 1) == 1) // if (read(0, &dummy, 1) == 1)
{ // {
if(dummy != '+') { // if(dummy != '+') {
fprintf(stderr, "ACK not received\n"); // fprintf(stderr, "ACK not received\n");
exit(-1); // exit(-1);
} // }
} // }
return true; return true;
} }
@ -230,16 +230,13 @@ void remotePutPacket(const char *packet)
*p++ = hex[csum & 15]; *p++ = hex[csum & 15];
*p++ = 0; *p++ = 0;
// printf("Sending %s\n", buffer); // printf("Sending %s\n", buffer);
remoteSendFnc(buffer, (int)count + 4);
char c = 0; char c = 0;
remoteRecvFnc(&c, 1); while(c != '+'){
/* remoteSendFnc(buffer, (int)count + 4);
if(c == '+') remoteRecvFnc(&c, 1);
printf("ACK\n"); // fprintf(stderr,"sent:%s recieved:%c\n",buffer,c);
else if(c=='-') }
printf("NACK\n");
*/
} }
#define debuggerReadMemory(addr) \ #define debuggerReadMemory(addr) \
@ -560,7 +557,9 @@ void remoteStubMain()
remoteResumed = false; remoteResumed = false;
} }
const char *hex = "0123456789abcdef";
while(1) { while(1) {
char ack;
char buffer[1024]; char buffer[1024];
int res = remoteRecvFnc(buffer, 1024); int res = remoteRecvFnc(buffer, 1024);
@ -573,99 +572,135 @@ void remoteStubMain()
debugger = false; debugger = false;
break; break;
} }
if(res < 1024){
// fprintf(stderr, "Received %s\n", buffer); buffer[res] = 0;
char *p = buffer; }else{
char c = *p++; fprintf(stderr, "res=%d\n",res);
char pp = '+';
remoteSendFnc(&pp, 1);
if(c != '$')
continue;
c= *p++;
switch(c) {
case '?':
remoteSendSignal();
break;
case 'D':
remotePutPacket("OK");
#ifdef SDL
dbgMain = debuggerMain;
dbgSignal = debuggerSignal;
#endif
remoteResumed = true;
debugger = false;
return;
case 'e':
remoteStepOverRange(p);
break;
case 'k':
remotePutPacket("OK");
#ifdef SDL
dbgMain = debuggerMain;
dbgSignal = debuggerSignal;
#endif
debugger = false;
emulating = false;
return;
case 'C':
remoteResumed = true;
debugger = false;
return;
case 'c':
remoteResumed = true;
debugger = false;
return;
case 's':
remoteResumed = true;
remoteSignal = 5;
CPULoop(1);
if(remoteResumed) {
remoteResumed = false;
remoteSendStatus();
}
break;
case 'g':
remoteReadRegisters(p);
break;
case 'P':
remoteWriteRegister(p);
break;
case 'M':
remoteMemoryWrite(p);
break;
case 'm':
remoteMemoryRead(p);
break;
case 'X':
remoteBinaryWrite(p);
break;
case 'H':
remotePutPacket("OK");
break;
case 'q':
remotePutPacket("");
break;
case 'Z':
if(*p++ == '2') {
remoteWriteWatch(p, true);
} else
remotePutPacket("");
break;
case 'z':
if(*p++ == '2') {
remoteWriteWatch(p, false);
} else
remotePutPacket("");
break;
default:
{
*(strchr(p, '#') + 3) = 0;
fprintf(stderr, "Unknown packet %s\n", --p);
remotePutPacket("");
}
break;
} }
// fprintf(stderr, "res=%d Received %s\n",res, buffer);
char c = buffer[0];
char *p = &buffer[0];
int i = 0;
unsigned char csum = 0;
while(i < res){
if(buffer[i] == '$'){
i++;
csum = 0;
c = buffer[i];
p = &buffer[i+1];
while((i<res) && (buffer[i] !='#')){
csum += buffer[i];
i++;
}
}else if(buffer[i] == '#'){
buffer[i] = 0;
if((i+2)<res){
if((buffer[i+1] == hex[csum>>4]) && (buffer[i+2] == hex[csum & 0xf])){
ack = '+';
remoteSendFnc(&ack, 1);
//fprintf(stderr, "SentACK c=%c\n",c);
//process message...
switch(c) {
case '?':
remoteSendSignal();
break;
case 'D':
remotePutPacket("OK");
#ifdef SDL
dbgMain = debuggerMain;
dbgSignal = debuggerSignal;
#endif
remoteResumed = true;
debugger = false;
return;
case 'e':
remoteStepOverRange(p);
break;
case 'k':
remotePutPacket("OK");
#ifdef SDL
dbgMain = debuggerMain;
dbgSignal = debuggerSignal;
#endif
debugger = false;
emulating = false;
return;
case 'C':
remoteResumed = true;
debugger = false;
return;
case 'c':
remoteResumed = true;
debugger = false;
return;
case 's':
remoteResumed = true;
remoteSignal = 5;
CPULoop(1);
if(remoteResumed) {
remoteResumed = false;
remoteSendStatus();
}
break;
case 'g':
remoteReadRegisters(p);
break;
case 'P':
remoteWriteRegister(p);
break;
case 'M':
remoteMemoryWrite(p);
break;
case 'm':
remoteMemoryRead(p);
break;
case 'X':
remoteBinaryWrite(p);
break;
case 'H':
remotePutPacket("OK");
break;
case 'q':
remotePutPacket("");
break;
case 'Z':
if(*p++ == '2') {
remoteWriteWatch(p, true);
} else
remotePutPacket("");
break;
case 'z':
if(*p++ == '2') {
remoteWriteWatch(p, false);
} else
remotePutPacket("");
break;
default:
{
fprintf(stderr, "Unknown packet %s\n", --p);
remotePutPacket("");
}
break;
}
}else{
fprintf(stderr, "bad chksum csum=%x msg=%c%c\n",csum,buffer[i+1],buffer[i+2]);
ack = '-';
remoteSendFnc(&ack, 1);
fprintf(stderr, "SentNACK\n");
}//if
i+=3;
}else{
fprintf(stderr, "didn't receive chksum i=%d res=%d\n",i,res);
i++;
}//if
}else{
if(buffer[i] != '+'){ //ingnore ACKs
fprintf(stderr, "not sure what to do with:%c i=%d res=%d\n",buffer[i],i,res);
}
i++;
}//if
}//while
} }
} }

View File

@ -2190,6 +2190,7 @@ int main(int argc, char **argv)
exit(-1); exit(-1);
} }
} else { } else {
soundInit();
cartridgeType = 0; cartridgeType = 0;
strcpy(filename, "gnu_stub"); strcpy(filename, "gnu_stub");
rom = (u8 *)malloc(0x2000000); rom = (u8 *)malloc(0x2000000);