Compare commits

...

3 Commits

Author SHA1 Message Date
Rekai Nyangadzayi Musuka bc47ff4883 feat: implement qThreadExtraInfo
TODO: figure out what this exactly does lol
2024-03-05 23:14:50 -06:00
Rekai Nyangadzayi Musuka 3670bebbc4 feat: implement 'T' packet 2024-03-05 23:14:32 -06:00
Rekai Nyangadzayi Musuka 309851ab06 fix: make xml memory map optional
Can make it mandatory once I've figured out the whole NDS memory map thing
2024-03-05 23:13:47 -06:00
2 changed files with 27 additions and 10 deletions

View File

@ -195,12 +195,19 @@ pub fn parse(self: *Self, allocator: Allocator, state: *Server.State, emu: *Emul
}, },
'H' => return .{ .static = "" }, 'H' => return .{ .static = "" },
'v' => { 'v' => {
if (!substr(self.contents[1..], "MustReplyEmpty")) { if (substr(self.contents[1..], "MustReplyEmpty")) return .{ .static = "" };
log.warn("Unimplemented: {s}", .{self.contents});
if (substr(self.contents[1..], "Cont")) {
switch (self.contents[5]) {
'?' => return .{ .static = "" }, // TODO: Implement vCont
else => {},
}
} }
log.warn("Unimplemented: {s}", .{self.contents});
return .{ .static = "" }; return .{ .static = "" };
}, },
'T' => return .{ .static = "OK " }, // We assume single threaded here
'q' => { 'q' => {
if (self.contents[1] == 'C' and self.contents.len == 2) return .{ .static = "QC1" }; if (self.contents[1] == 'C' and self.contents.len == 2) return .{ .static = "QC1" };
@ -208,11 +215,19 @@ pub fn parse(self: *Self, allocator: Allocator, state: *Server.State, emu: *Emul
if (substr(self.contents[1..], "sThreadInfo")) return .{ .static = "l" }; if (substr(self.contents[1..], "sThreadInfo")) return .{ .static = "l" };
if (substr(self.contents[1..], "Attached")) return .{ .static = "1" }; // Tell GDB we're attached to a process if (substr(self.contents[1..], "Attached")) return .{ .static = "1" }; // Tell GDB we're attached to a process
if (substr(self.contents[1..], "Supported")) { if (substr(self.contents[1..], "ThreadExtraInfo")) {
const format = "PacketSize={x:};swbreak+;hwbreak+;qXfer:features:read+;qXfer:memory-map:read+"; const extra_info = "FIXME: what is even expected here?";
// TODO: Anything else? const ret = try allocator.dupe(u8, &std.fmt.bytesToHex(extra_info, .lower));
const ret = try std.fmt.allocPrint(allocator, format, .{Self.max_len}); return .{ .alloc = ret };
}
if (substr(self.contents[1..], "Supported")) {
const format = "PacketSize={x:};swbreak+;hwbreak+;qXfer:features:read+;{s}";
const mem_map = if (state.memmap_xml == null) "" else "qXfer:memory-map:read+";
// TODO: Anything else?
const ret = try std.fmt.allocPrint(allocator, format, .{ Self.max_len, mem_map });
return .{ .alloc = ret }; return .{ .alloc = ret };
} }
@ -249,6 +264,8 @@ pub fn parse(self: *Self, allocator: Allocator, state: *Server.State, emu: *Emul
} }
if (substr(self.contents[1..], "Xfer:memory-map:read")) { if (substr(self.contents[1..], "Xfer:memory-map:read")) {
const mem_map = state.memmap_xml.?;
var tokens = std.mem.tokenize(u8, self.contents[1..], ":,"); var tokens = std.mem.tokenize(u8, self.contents[1..], ":,");
_ = tokens.next(); // Xfer _ = tokens.next(); // Xfer
_ = tokens.next(); // memory-map _ = tokens.next(); // memory-map
@ -260,11 +277,11 @@ pub fn parse(self: *Self, allocator: Allocator, state: *Server.State, emu: *Emul
const length = try std.fmt.parseInt(usize, length_str, 16); const length = try std.fmt.parseInt(usize, length_str, 16);
// see above // see above
const len = @min(length, (state.memmap_xml.len + 1) - offset); const len = @min(length, (mem_map.len + 1) - offset);
const ret = try allocator.alloc(u8, len); const ret = try allocator.alloc(u8, len);
ret[0] = if (ret.len < length) 'l' else 'm'; ret[0] = if (ret.len < length) 'l' else 'm';
@memcpy(ret[1..], state.memmap_xml[offset..]); @memcpy(ret[1..], mem_map[offset..]);
return .{ .alloc = ret }; return .{ .alloc = ret };
} }

View File

@ -21,10 +21,10 @@ emu: Emulator,
pub const State = struct { pub const State = struct {
should_quit: bool = false, should_quit: bool = false,
target_xml: []const u8, target_xml: []const u8,
memmap_xml: []const u8, memmap_xml: ?[]const u8,
}; };
const Xml = struct { target: []const u8, memory_map: []const u8 }; const Xml = struct { target: []const u8, memory_map: ?[]const u8 };
pub fn init(emulator: Emulator, xml: Xml) !Self { pub fn init(emulator: Emulator, xml: Xml) !Self {
var server = std.net.StreamServer.init(.{}); var server = std.net.StreamServer.init(.{});