Compare commits

...

5 Commits

5 changed files with 59 additions and 17 deletions

@ -1 +1 @@
Subproject commit 13012701334821cf1038a81920eaafff1921268a Subproject commit 1266e61757af01485f56b4e5bd3969fdaba9c356

View File

@ -10,6 +10,7 @@
#include <pthread.h> #include <pthread.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/select.h>
#include <mqueue.h> #include <mqueue.h>
#include <errno.h> #include <errno.h>
@ -142,10 +143,27 @@ static int wait_hit_or_break(struct msg *msg)
if (exit_loop) if (exit_loop)
return 1; return 1;
SetsNonblock(client_socket);
if (ret < 0 && errno == EAGAIN) { if (ret < 0 && errno == EAGAIN) {
/* Breakpoint has not been hit yet, look for incoming messages from gdb. */ /* Breakpoint has not been hit yet, look for incoming messages from gdb. */
SetsNonblock(client_socket);
{
const int fd = in_queue > client_socket ? in_queue : client_socket;
fd_set set;
FD_ZERO(&set);
FD_SET(in_queue, &set);
FD_SET(client_socket, &set);
/* Warning: mqd_t are file descriptors in Linux and hence
* can be used with select(), but this is not portable. */
if (select(fd + 1, &set, NULL, NULL, NULL) < 0)
{
perror("wait_hit_or_break: select");
return EOF;
}
}
char packet; char packet;
size_t len = sizeof packet; size_t len = sizeof packet;
const enum read_socket_err err = ReadSocket(client_socket, &packet, &len); const enum read_socket_err err = ReadSocket(client_socket, &packet, &len);
@ -178,15 +196,22 @@ static int wait_hit_or_break(struct msg *msg)
break; break;
} }
} }
else if (msg->type != MSG_TYPE_HIT) { else {
fprintf(stderr, "unexpected msg.type %d\n", msg->type); switch (msg->type) {
return 1; case MSG_TYPE_BREAK:
return 1;
case MSG_TYPE_HIT:
return 0;
default:
fprintf(stderr, "%s:%d:unexpected msg.type %d\n",
__func__, __LINE__, msg->type);
return EOF;
}
} }
else
return 0;
} while (1); } while (1);
return 1; return EOF;
} }
#endif #endif
@ -266,7 +291,7 @@ int dbg_sys_del_breakpoint(address addr)
msg.type = MSG_TYPE_REMOVE_BREAKPOINT; msg.type = MSG_TYPE_REMOVE_BREAKPOINT;
if (mq_send(out_queue, (const char *)&msg, sizeof msg, 0)) { if (mq_send(out_queue, (const char *)&msg, sizeof msg, 0)) {
perror("dbg_sys_breakpoint(): mq_send()"); perror("dbg_sys_del_breakpoint(): mq_send()");
} }
return wait_ack(&msg); return wait_ack(&msg);

View File

@ -66,7 +66,8 @@ struct msg {
MSG_TYPE_SHUTDOWN, MSG_TYPE_SHUTDOWN,
/* Response frames. */ /* Response frames. */
MSG_TYPE_HIT MSG_TYPE_HIT,
MSG_TYPE_BREAK,
} type; } type;
union { union {

View File

@ -655,8 +655,10 @@ void psxMTLO() { _rLo_ = _rRs_; } // Lo = Rs
* Special purpose instructions * * Special purpose instructions *
* Format: OP * * Format: OP *
*********************************************************/ *********************************************************/
static void process_gdb(int);
void psxBREAK() { void psxBREAK() {
// Break exception - psx rom doens't handles this // Break exception - psx rom doens't handles this
if (Config.GdbServer) process_gdb(1);
} }
void psxSYSCALL() { void psxSYSCALL() {
@ -1204,7 +1206,7 @@ static void intClear(u32 Addr, u32 Size) {
static void intShutdown() { static void intShutdown() {
} }
static void process_gdb(void) { static void process_gdb(int found_break) {
static int shutdown; static int shutdown;
static u32 tgt_addr; static u32 tgt_addr;
static int step, must_continue; static int step, must_continue;
@ -1215,7 +1217,14 @@ start:
if (shutdown) if (shutdown)
return; return;
if (halt || step || (must_continue && tgt_addr && tgt_addr == psxRegs.pc)) { if (found_break) {
msg.type = MSG_TYPE_BREAK;
gdbstub_sys_send(&msg);
must_continue = 0;
step = 0;
halt = 0;
}
else if (halt || step || (must_continue && tgt_addr && tgt_addr == psxRegs.pc)) {
msg.type = MSG_TYPE_HIT; msg.type = MSG_TYPE_HIT;
#if DEBUG == 1 #if DEBUG == 1
printf("hit address 0x%08X\n", psxRegs.pc); printf("hit address 0x%08X\n", psxRegs.pc);
@ -1276,7 +1285,7 @@ static inline void execI() {
debugI(); debugI();
if (Config.GdbServer) process_gdb(); if (Config.GdbServer) process_gdb(0);
else if (Config.Debug) ProcessDebug(); else if (Config.Debug) ProcessDebug();
psxRegs.pc += 4; psxRegs.pc += 4;

View File

@ -68,11 +68,15 @@ int StartServer(unsigned short port) {
localsocketaddr.sin_addr = localhostaddr; localsocketaddr.sin_addr = localhostaddr;
localsocketaddr.sin_port = htons(port); localsocketaddr.sin_port = htons(port);
if (bind(ret, (struct sockaddr *) &localsocketaddr, sizeof(localsocketaddr)) < 0) if (bind(ret, (const struct sockaddr *) &localsocketaddr, sizeof(localsocketaddr)) < 0) {
perror("gdbserver bind() failed");
return -1; return -1;
}
if (listen(ret, 1) != 0) if (listen(ret, 1)) {
perror("gdbserver listen() failed");
return -1; return -1;
}
return ret; return ret;
} }
@ -215,7 +219,7 @@ enum read_socket_err ReadSocket(int client_socket, char *buf, size_t *const len)
#endif #endif
} }
int RawReadSocket(int client_socket, char *buffer, size_t len) { int RawReadSocket(int client_socket, char *buf, size_t len) {
#if 0 #if 0
int r = 0; int r = 0;
int mlen = len < ptr ? len : ptr; int mlen = len < ptr ? len : ptr;
@ -250,6 +254,9 @@ int RawReadSocket(int client_socket, char *buffer, size_t len) {
r += mlen; r += mlen;
return r; return r;
#else
#warning please check
return ReadSocket(client_socket, buf, &len);
#endif #endif
} }