Compare commits
4 Commits
d7b8d7acb1
...
215e053b9a
Author | SHA1 | Date | |
---|---|---|---|
215e053b9a | |||
acb59994fc | |||
6d6a109a08 | |||
c1158b547e |
56
build.zig
56
build.zig
@@ -1,54 +1,44 @@
|
||||
const std = @import("std");
|
||||
const CompileStep = std.Build.CompileStep;
|
||||
|
||||
fn path(comptime suffix: []const u8) []const u8 {
|
||||
if (suffix[0] == '/') @compileError("expected a relative path");
|
||||
return comptime (std.fs.path.dirname(@src().file) orelse ".") ++ std.fs.path.sep_str ++ suffix;
|
||||
}
|
||||
|
||||
const pkgs = struct {
|
||||
const Pkg = std.build.Pkg;
|
||||
|
||||
pub const gdbstub: Pkg = .{
|
||||
.name = "gdbstub",
|
||||
.source = .{ .path = path("src/lib.zig") },
|
||||
.dependencies = &[_]Pkg{network},
|
||||
};
|
||||
|
||||
pub fn getModule(b: *std.Build) *std.build.Module {
|
||||
// https://github.com/MasterQ32/zig-network
|
||||
pub const network: Pkg = .{
|
||||
.name = "network",
|
||||
.source = .{ .path = path("lib/zig-network/network.zig") },
|
||||
};
|
||||
};
|
||||
const network = b.createModule(.{ .source_file = .{ .path = path("lib/zig-network/network.zig") } });
|
||||
|
||||
pub fn link(exe: *std.build.LibExeObjStep) void {
|
||||
exe.addPackage(pkgs.gdbstub);
|
||||
return b.createModule(.{
|
||||
.source_file = .{ .path = path("src/lib.zig") },
|
||||
.dependencies = &.{.{ .name = "network", .module = network }},
|
||||
});
|
||||
}
|
||||
|
||||
pub fn build(b: *std.build.Builder) void {
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
_ = target;
|
||||
const mode = b.standardReleaseOptions();
|
||||
// const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
// -- library --
|
||||
const lib = b.addStaticLibrary("gdbstub", "src/lib.zig");
|
||||
lib.addPackage(pkgs.network);
|
||||
// -- Library --
|
||||
|
||||
lib.setBuildMode(mode);
|
||||
lib.install();
|
||||
const lib_test = b.addTest(.{
|
||||
.root_source_file = .{ .path = "src/lib.zig" },
|
||||
.target = target,
|
||||
});
|
||||
|
||||
const lib_tests = b.addTest("src/lib.zig");
|
||||
lib_tests.setBuildMode(mode);
|
||||
const test_step = b.step("test", "Run Library Tests");
|
||||
test_step.dependOn(&lib_test.step);
|
||||
|
||||
const test_step = b.step("lib-test", "Run Library Tests");
|
||||
test_step.dependOn(&lib_tests.step);
|
||||
// -- Executable --
|
||||
|
||||
// // -- Executable --
|
||||
// const exe = b.addExecutable("gdbserver", "src/main.zig");
|
||||
// const exe = b.addExecutable(.{
|
||||
// .name = "gdbserver",
|
||||
// .root_source_file = .{ .path = "src/main.zig" },
|
||||
// .target = target,
|
||||
// .optimize = optimize,
|
||||
// });
|
||||
// link(exe);
|
||||
|
||||
// exe.setTarget(target);
|
||||
// exe.setBuildMode(mode);
|
||||
// exe.install();
|
||||
|
||||
// const run_cmd = exe.run();
|
||||
|
Submodule lib/zig-network updated: a8c4502538...45ae8cf0ce
@@ -4,6 +4,7 @@ const Packet = @import("Packet.zig");
|
||||
|
||||
const Socket = network.Socket;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Atomic = std.atomic.Atomic;
|
||||
const Emulator = @import("lib.zig").Emulator;
|
||||
|
||||
const Self = @This();
|
||||
@@ -94,16 +95,21 @@ const Action = union(enum) {
|
||||
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;
|
||||
|
||||
while (true) {
|
||||
const len = try self.client.receive(&buf);
|
||||
if (len == 0) break;
|
||||
|
||||
if (quit.load(.Monotonic)) break;
|
||||
const action = try self.parse(allocator, buf[0..len]);
|
||||
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 {
|
||||
|
@@ -25,7 +25,7 @@ const SwBkpt = struct {
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
self.deinit();
|
||||
self.list.deinit();
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ const SwBkpt = struct {
|
||||
}
|
||||
|
||||
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) {
|
||||
_ = self.list.orderedRemove(i);
|
||||
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 {
|
||||
for (self.list) |*bkpt_opt| {
|
||||
for (&self.list) |*bkpt_opt| {
|
||||
if (bkpt_opt.*) |bkpt| {
|
||||
if (bkpt.addr == addr) return; // idempotent
|
||||
} else {
|
||||
@@ -88,7 +88,7 @@ const HwBkpt = struct {
|
||||
}
|
||||
|
||||
pub fn remove(self: *@This(), addr: u32) void {
|
||||
for (self.list) |*bkpt_opt| {
|
||||
for (&self.list) |*bkpt_opt| {
|
||||
const bkpt = bkpt_opt.* orelse continue;
|
||||
|
||||
if (bkpt.addr == addr) {
|
||||
|
Reference in New Issue
Block a user