core/gdbstub: Migrate logging macros
Change to use the new logging macros
This commit is contained in:
parent
7f408eefa3
commit
10f0fbc0e5
|
@ -164,7 +164,7 @@ static u8 HexCharToValue(u8 hex) {
|
||||||
return hex - 'A' + 0xA;
|
return hex - 'A' + 0xA;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_ERROR(Debug_GDBStub, "Invalid nibble: %c (%02x)\n", hex, hex);
|
NGLOG_ERROR(Debug_GDBStub, "Invalid nibble: {:c} {:02x}\n", hex, hex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ static u8 ReadByte() {
|
||||||
u8 c;
|
u8 c;
|
||||||
size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL);
|
size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL);
|
||||||
if (received_size != 1) {
|
if (received_size != 1) {
|
||||||
LOG_ERROR(Debug_GDBStub, "recv failed : %ld", received_size);
|
NGLOG_ERROR(Debug_GDBStub, "recv failed : {}", received_size);
|
||||||
Shutdown();
|
Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ static void RemoveBreakpoint(BreakpointType type, PAddr addr) {
|
||||||
|
|
||||||
auto bp = p.find(addr);
|
auto bp = p.find(addr);
|
||||||
if (bp != p.end()) {
|
if (bp != p.end()) {
|
||||||
LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: %08x bytes at %08x of type %d\n",
|
NGLOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: {:08x} bytes at {:08x} of type {}\n",
|
||||||
bp->second.len, bp->second.addr, static_cast<int>(type));
|
bp->second.len, bp->second.addr, static_cast<int>(type));
|
||||||
p.erase(addr);
|
p.erase(addr);
|
||||||
}
|
}
|
||||||
|
@ -347,8 +347,8 @@ bool CheckBreakpoint(PAddr addr, BreakpointType type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) {
|
if (bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) {
|
||||||
LOG_DEBUG(Debug_GDBStub,
|
NGLOG_DEBUG(Debug_GDBStub,
|
||||||
"Found breakpoint type %d @ %08x, range: %08x - %08x (%u bytes)\n",
|
"Found breakpoint type {} @ {:08x}, range: {:08x} - {:08x} ({} bytes)\n",
|
||||||
static_cast<int>(type), addr, bp->second.addr, bp->second.addr + len, len);
|
static_cast<int>(type), addr, bp->second.addr, bp->second.addr + len, len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ bool CheckBreakpoint(PAddr addr, BreakpointType type) {
|
||||||
static void SendPacket(const char packet) {
|
static void SendPacket(const char packet) {
|
||||||
size_t sent_size = send(gdbserver_socket, &packet, 1, 0);
|
size_t sent_size = send(gdbserver_socket, &packet, 1, 0);
|
||||||
if (sent_size != 1) {
|
if (sent_size != 1) {
|
||||||
LOG_ERROR(Debug_GDBStub, "send failed");
|
NGLOG_ERROR(Debug_GDBStub, "send failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ static void SendReply(const char* reply) {
|
||||||
|
|
||||||
command_length = static_cast<u32>(strlen(reply));
|
command_length = static_cast<u32>(strlen(reply));
|
||||||
if (command_length + 4 > sizeof(command_buffer)) {
|
if (command_length + 4 > sizeof(command_buffer)) {
|
||||||
LOG_ERROR(Debug_GDBStub, "command_buffer overflow in SendReply");
|
NGLOG_ERROR(Debug_GDBStub, "command_buffer overflow in SendReply");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ static void SendReply(const char* reply) {
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
int sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0);
|
int sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0);
|
||||||
if (sent_size < 0) {
|
if (sent_size < 0) {
|
||||||
LOG_ERROR(Debug_GDBStub, "gdb: send failed");
|
NGLOG_ERROR(Debug_GDBStub, "gdb: send failed");
|
||||||
return Shutdown();
|
return Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ static void SendReply(const char* reply) {
|
||||||
|
|
||||||
/// Handle query command from gdb client.
|
/// Handle query command from gdb client.
|
||||||
static void HandleQuery() {
|
static void HandleQuery() {
|
||||||
LOG_DEBUG(Debug_GDBStub, "gdb: query '%s'\n", command_buffer + 1);
|
NGLOG_DEBUG(Debug_GDBStub, "gdb: query '{}'\n", command_buffer + 1);
|
||||||
|
|
||||||
const char* query = reinterpret_cast<const char*>(command_buffer + 1);
|
const char* query = reinterpret_cast<const char*>(command_buffer + 1);
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ static void SendSignal(u32 signal) {
|
||||||
std::string buffer =
|
std::string buffer =
|
||||||
Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15,
|
Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15,
|
||||||
htonl(Core::CPU().GetPC()), 13, htonl(Core::CPU().GetReg(13)));
|
htonl(Core::CPU().GetPC()), 13, htonl(Core::CPU().GetReg(13)));
|
||||||
LOG_DEBUG(Debug_GDBStub, "Response: %s", buffer.c_str());
|
NGLOG_DEBUG(Debug_GDBStub, "Response: {}", buffer);
|
||||||
SendReply(buffer.c_str());
|
SendReply(buffer.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,18 +467,18 @@ static void ReadCommand() {
|
||||||
// ignore ack
|
// ignore ack
|
||||||
return;
|
return;
|
||||||
} else if (c == 0x03) {
|
} else if (c == 0x03) {
|
||||||
LOG_INFO(Debug_GDBStub, "gdb: found break command\n");
|
NGLOG_INFO(Debug_GDBStub, "gdb: found break command\n");
|
||||||
halt_loop = true;
|
halt_loop = true;
|
||||||
SendSignal(SIGTRAP);
|
SendSignal(SIGTRAP);
|
||||||
return;
|
return;
|
||||||
} else if (c != GDB_STUB_START) {
|
} else if (c != GDB_STUB_START) {
|
||||||
LOG_DEBUG(Debug_GDBStub, "gdb: read invalid byte %02x\n", c);
|
NGLOG_DEBUG(Debug_GDBStub, "gdb: read invalid byte {:02x}\n", c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((c = ReadByte()) != GDB_STUB_END) {
|
while ((c = ReadByte()) != GDB_STUB_END) {
|
||||||
if (command_length >= sizeof(command_buffer)) {
|
if (command_length >= sizeof(command_buffer)) {
|
||||||
LOG_ERROR(Debug_GDBStub, "gdb: command_buffer overflow\n");
|
NGLOG_ERROR(Debug_GDBStub, "gdb: command_buffer overflow\n");
|
||||||
SendPacket(GDB_STUB_NACK);
|
SendPacket(GDB_STUB_NACK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -491,8 +491,9 @@ static void ReadCommand() {
|
||||||
u8 checksum_calculated = CalculateChecksum(command_buffer, command_length);
|
u8 checksum_calculated = CalculateChecksum(command_buffer, command_length);
|
||||||
|
|
||||||
if (checksum_received != checksum_calculated) {
|
if (checksum_received != checksum_calculated) {
|
||||||
LOG_ERROR(Debug_GDBStub,
|
NGLOG_ERROR(
|
||||||
"gdb: invalid checksum: calculated %02x and read %02x for $%s# (length: %d)\n",
|
Debug_GDBStub,
|
||||||
|
"gdb: invalid checksum: calculated {:02x} and read {:02x} for ${}# (length: {})\n",
|
||||||
checksum_calculated, checksum_received, command_buffer, command_length);
|
checksum_calculated, checksum_received, command_buffer, command_length);
|
||||||
|
|
||||||
command_length = 0;
|
command_length = 0;
|
||||||
|
@ -520,7 +521,7 @@ static bool IsDataAvailable() {
|
||||||
t.tv_usec = 0;
|
t.tv_usec = 0;
|
||||||
|
|
||||||
if (select(gdbserver_socket + 1, &fd_socket, nullptr, nullptr, &t) < 0) {
|
if (select(gdbserver_socket + 1, &fd_socket, nullptr, nullptr, &t) < 0) {
|
||||||
LOG_ERROR(Debug_GDBStub, "select failed");
|
NGLOG_ERROR(Debug_GDBStub, "select failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,7 +651,7 @@ static void ReadMemory() {
|
||||||
u32 len =
|
u32 len =
|
||||||
HexToInt(start_offset, static_cast<u32>((command_buffer + command_length) - start_offset));
|
HexToInt(start_offset, static_cast<u32>((command_buffer + command_length) - start_offset));
|
||||||
|
|
||||||
LOG_DEBUG(Debug_GDBStub, "gdb: addr: %08x len: %08x\n", addr, len);
|
NGLOG_DEBUG(Debug_GDBStub, "gdb: addr: {:08x} len: {:08x}\n", addr, len);
|
||||||
|
|
||||||
if (len * 2 > sizeof(reply)) {
|
if (len * 2 > sizeof(reply)) {
|
||||||
SendReply("E01");
|
SendReply("E01");
|
||||||
|
@ -738,7 +739,7 @@ static bool CommitBreakpoint(BreakpointType type, PAddr addr, u32 len) {
|
||||||
breakpoint.len = len;
|
breakpoint.len = len;
|
||||||
p.insert({addr, breakpoint});
|
p.insert({addr, breakpoint});
|
||||||
|
|
||||||
LOG_DEBUG(Debug_GDBStub, "gdb: added %d breakpoint: %08x bytes at %08x\n",
|
NGLOG_DEBUG(Debug_GDBStub, "gdb: added {} breakpoint: {:08x} bytes at {:08x}\n",
|
||||||
static_cast<int>(type), breakpoint.len, breakpoint.addr);
|
static_cast<int>(type), breakpoint.len, breakpoint.addr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -846,7 +847,7 @@ void HandlePacket() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG(Debug_GDBStub, "Packet: %s", command_buffer);
|
NGLOG_DEBUG(Debug_GDBStub, "Packet: {}", command_buffer);
|
||||||
|
|
||||||
switch (command_buffer[0]) {
|
switch (command_buffer[0]) {
|
||||||
case 'q':
|
case 'q':
|
||||||
|
@ -860,7 +861,7 @@ void HandlePacket() {
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
Shutdown();
|
Shutdown();
|
||||||
LOG_INFO(Debug_GDBStub, "killed by gdb");
|
NGLOG_INFO(Debug_GDBStub, "killed by gdb");
|
||||||
return;
|
return;
|
||||||
case 'g':
|
case 'g':
|
||||||
ReadRegisters();
|
ReadRegisters();
|
||||||
|
@ -939,7 +940,7 @@ static void Init(u16 port) {
|
||||||
breakpoints_write.clear();
|
breakpoints_write.clear();
|
||||||
|
|
||||||
// Start gdb server
|
// Start gdb server
|
||||||
LOG_INFO(Debug_GDBStub, "Starting GDB server on port %d...", port);
|
NGLOG_INFO(Debug_GDBStub, "Starting GDB server on port {}...", port);
|
||||||
|
|
||||||
sockaddr_in saddr_server = {};
|
sockaddr_in saddr_server = {};
|
||||||
saddr_server.sin_family = AF_INET;
|
saddr_server.sin_family = AF_INET;
|
||||||
|
@ -952,28 +953,28 @@ static void Init(u16 port) {
|
||||||
|
|
||||||
int tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0));
|
int tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0));
|
||||||
if (tmpsock == -1) {
|
if (tmpsock == -1) {
|
||||||
LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket");
|
NGLOG_ERROR(Debug_GDBStub, "Failed to create gdb socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set socket to SO_REUSEADDR so it can always bind on the same port
|
// Set socket to SO_REUSEADDR so it can always bind on the same port
|
||||||
int reuse_enabled = 1;
|
int reuse_enabled = 1;
|
||||||
if (setsockopt(tmpsock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_enabled,
|
if (setsockopt(tmpsock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_enabled,
|
||||||
sizeof(reuse_enabled)) < 0) {
|
sizeof(reuse_enabled)) < 0) {
|
||||||
LOG_ERROR(Debug_GDBStub, "Failed to set gdb socket option");
|
NGLOG_ERROR(Debug_GDBStub, "Failed to set gdb socket option");
|
||||||
}
|
}
|
||||||
|
|
||||||
const sockaddr* server_addr = reinterpret_cast<const sockaddr*>(&saddr_server);
|
const sockaddr* server_addr = reinterpret_cast<const sockaddr*>(&saddr_server);
|
||||||
socklen_t server_addrlen = sizeof(saddr_server);
|
socklen_t server_addrlen = sizeof(saddr_server);
|
||||||
if (bind(tmpsock, server_addr, server_addrlen) < 0) {
|
if (bind(tmpsock, server_addr, server_addrlen) < 0) {
|
||||||
LOG_ERROR(Debug_GDBStub, "Failed to bind gdb socket");
|
NGLOG_ERROR(Debug_GDBStub, "Failed to bind gdb socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(tmpsock, 1) < 0) {
|
if (listen(tmpsock, 1) < 0) {
|
||||||
LOG_ERROR(Debug_GDBStub, "Failed to listen to gdb socket");
|
NGLOG_ERROR(Debug_GDBStub, "Failed to listen to gdb socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for gdb to connect
|
// Wait for gdb to connect
|
||||||
LOG_INFO(Debug_GDBStub, "Waiting for gdb to connect...\n");
|
NGLOG_INFO(Debug_GDBStub, "Waiting for gdb to connect...\n");
|
||||||
sockaddr_in saddr_client;
|
sockaddr_in saddr_client;
|
||||||
sockaddr* client_addr = reinterpret_cast<sockaddr*>(&saddr_client);
|
sockaddr* client_addr = reinterpret_cast<sockaddr*>(&saddr_client);
|
||||||
socklen_t client_addrlen = sizeof(saddr_client);
|
socklen_t client_addrlen = sizeof(saddr_client);
|
||||||
|
@ -984,9 +985,9 @@ static void Init(u16 port) {
|
||||||
halt_loop = false;
|
halt_loop = false;
|
||||||
step_loop = false;
|
step_loop = false;
|
||||||
|
|
||||||
LOG_ERROR(Debug_GDBStub, "Failed to accept gdb client");
|
NGLOG_ERROR(Debug_GDBStub, "Failed to accept gdb client");
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(Debug_GDBStub, "Client connected.\n");
|
NGLOG_INFO(Debug_GDBStub, "Client connected.\n");
|
||||||
saddr_client.sin_addr.s_addr = ntohl(saddr_client.sin_addr.s_addr);
|
saddr_client.sin_addr.s_addr = ntohl(saddr_client.sin_addr.s_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1005,7 +1006,7 @@ void Shutdown() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO(Debug_GDBStub, "Stopping GDB ...");
|
NGLOG_INFO(Debug_GDBStub, "Stopping GDB ...");
|
||||||
if (gdbserver_socket != -1) {
|
if (gdbserver_socket != -1) {
|
||||||
shutdown(gdbserver_socket, SHUT_RDWR);
|
shutdown(gdbserver_socket, SHUT_RDWR);
|
||||||
gdbserver_socket = -1;
|
gdbserver_socket = -1;
|
||||||
|
@ -1015,7 +1016,7 @@ void Shutdown() {
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LOG_INFO(Debug_GDBStub, "GDB stopped.");
|
NGLOG_INFO(Debug_GDBStub, "GDB stopped.");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsServerEnabled() {
|
bool IsServerEnabled() {
|
||||||
|
|
Reference in New Issue