fix: make xml memory map optional

Can make it mandatory once I've figured out the whole NDS memory map thing
This commit is contained in:
Rekai Nyangadzayi Musuka 2024-03-05 23:13:47 -06:00
parent 7ae72ed5a8
commit 309851ab06
2 changed files with 18 additions and 9 deletions

View File

@ -195,10 +195,16 @@ 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 = "" };
}, },
'q' => { 'q' => {
@ -209,10 +215,11 @@ pub fn parse(self: *Self, allocator: Allocator, state: *Server.State, emu: *Emul
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..], "Supported")) {
const format = "PacketSize={x:};swbreak+;hwbreak+;qXfer:features:read+;qXfer:memory-map:read+"; const format = "PacketSize={x:};swbreak+;hwbreak+;qXfer:features:read+;{s}";
// TODO: Anything else? const mem_map = if (state.memmap_xml == null) "" else "qXfer:memory-map:read+";
const ret = try std.fmt.allocPrint(allocator, format, .{Self.max_len}); // TODO: Anything else?
const ret = try std.fmt.allocPrint(allocator, format, .{ Self.max_len, mem_map });
return .{ .alloc = ret }; return .{ .alloc = ret };
} }
@ -249,6 +256,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 +269,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(.{});