Compare commits

...

2 Commits

Author SHA1 Message Date
acb59994fc chore: update to latest zig master 2023-02-23 02:43:58 -06:00
6d6a109a08 fix: gracefully exit
fix stack overflow bug in State.deinit
allow for code in another thread to signal shutdown to gdbstub
2023-02-13 20:01:01 -06:00
3 changed files with 12 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ const Packet = @import("Packet.zig");
const Socket = network.Socket; const Socket = network.Socket;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const Atomic = std.atomic.Atomic;
const Emulator = @import("lib.zig").Emulator; const Emulator = @import("lib.zig").Emulator;
const Self = @This(); const Self = @This();
@@ -94,16 +95,21 @@ const Action = union(enum) {
nack, nack,
}; };
pub fn run(self: *Self, allocator: Allocator) !void { pub fn run(self: *Self, allocator: Allocator, quit: *Atomic(bool)) !void {
var buf: [Packet.max_len]u8 = undefined; var buf: [Packet.max_len]u8 = undefined;
while (true) { while (true) {
const len = try self.client.receive(&buf); const len = try self.client.receive(&buf);
if (len == 0) break; if (len == 0) break;
if (quit.load(.Monotonic)) break;
const action = try self.parse(allocator, buf[0..len]); const action = try self.parse(allocator, buf[0..len]);
try self.send(allocator, action); try self.send(allocator, action);
} }
// Just in case its the gdbstub that exited first,
// attempt to signal to the GUI that it should also exit
quit.store(true, .Monotonic);
} }
fn parse(self: *Self, allocator: Allocator, input: []const u8) !Action { fn parse(self: *Self, allocator: Allocator, input: []const u8) !Action {

View File

@@ -25,7 +25,7 @@ const SwBkpt = struct {
} }
pub fn deinit(self: *@This()) void { pub fn deinit(self: *@This()) void {
self.deinit(); self.list.deinit();
self.* = undefined; self.* = undefined;
} }
@@ -47,7 +47,7 @@ const SwBkpt = struct {
} }
pub fn remove(self: *@This(), addr: u32) void { pub fn remove(self: *@This(), addr: u32) void {
for (self.list.items) |bkpt, i| { for (self.list.items, 0..) |bkpt, i| {
if (bkpt.addr == addr) { if (bkpt.addr == addr) {
_ = self.list.orderedRemove(i); _ = self.list.orderedRemove(i);
log.debug("Removed Breakpoint at 0x{X:0>8}", .{addr}); log.debug("Removed Breakpoint at 0x{X:0>8}", .{addr});
@@ -73,7 +73,7 @@ const HwBkpt = struct {
} }
pub fn add(self: *@This(), addr: u32, kind: u32) !void { pub fn add(self: *@This(), addr: u32, kind: u32) !void {
for (self.list) |*bkpt_opt| { for (&self.list) |*bkpt_opt| {
if (bkpt_opt.*) |bkpt| { if (bkpt_opt.*) |bkpt| {
if (bkpt.addr == addr) return; // idempotent if (bkpt.addr == addr) return; // idempotent
} else { } else {
@@ -88,7 +88,7 @@ const HwBkpt = struct {
} }
pub fn remove(self: *@This(), addr: u32) void { pub fn remove(self: *@This(), addr: u32) void {
for (self.list) |*bkpt_opt| { for (&self.list) |*bkpt_opt| {
const bkpt = bkpt_opt.* orelse continue; const bkpt = bkpt_opt.* orelse continue;
if (bkpt.addr == addr) { if (bkpt.addr == addr) {