From 1809a19c27d4dc5cebdf4c16bae51071019e9f96 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 5 Apr 2026 16:27:09 -0700 Subject: [PATCH] add objdump subcommand does nothing so far --- lib/compiler/objdump.zig | 33 +++++++++++++++++++++++++++++++++ src/main.zig | 10 ++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 lib/compiler/objdump.zig diff --git a/lib/compiler/objdump.zig b/lib/compiler/objdump.zig new file mode 100644 index 0000000000000000000000000000000000000000..002001306e3540334754c15af3db979049b5a328 --- /dev/null +++ b/lib/compiler/objdump.zig @@ -0,0 +1,33 @@ +const std = @import("std"); +const Io = std.Io; +const fatal = std.process.fatal; + +pub fn main(init: std.process.Init) !void { + const io = init.io; + const args = try init.minimal.args.toSlice(init.arena.allocator()); + + var input_path: ?[]const u8 = null; + var i: usize = 0; + while (i < args.len) : (i += 1) { + const arg = args[i]; + if (std.mem.startsWith(u8, arg, "-")) { + if (std.mem.eql(u8, arg, "-h") or std.mem.eql(u8, arg, "--help")) { + return Io.File.stdout().writeStreamingAll(io, usage); + } else { + fatal("unrecognized argument: {s}", .{arg}); + } + } else if (input_path == null) { + input_path = arg; + } else { + fatal("unexpected positional: {s}", .{arg}); + } + } +} + +const usage = + \\Usage: zig objdump [options] file + \\ + \\Options: + \\ -h, --help Print this help and exit + \\ +; diff --git a/src/main.zig b/src/main.zig index 0ba118025462ef94db94e5d7bca4ebd148a7aad3..0395a21a5ff5aaa04ba4d1cb43bc629ec6e8c0e2 100644 --- a/src/main.zig +++ b/src/main.zig @@ -95,13 +95,14 @@ const normal_usage = \\ reduce Minimize a bug report \\ translate-c Convert C code to Zig code \\ - \\ ar Use Zig as a drop-in archiver + \\ ar Combine object files into static archive \\ cc Use Zig as a drop-in C compiler \\ c++ Use Zig as a drop-in C++ compiler \\ dlltool Use Zig as a drop-in dlltool.exe \\ lib Use Zig as a drop-in lib.exe + \\ objcopy Manipulate executables and relocatables + \\ objdump Print information about executables and relocatables \\ ranlib Use Zig as a drop-in ranlib - \\ objcopy Use Zig as a drop-in objcopy \\ rc Use Zig as a drop-in rc.exe \\ \\ env Print lib path, std path, cache directory, and version @@ -342,6 +343,11 @@ fn mainArgs( .cmd_name = "objcopy", .root_src_path = "objcopy.zig", }); + } else if (mem.eql(u8, cmd, "objdump")) { + return jitCmd(gpa, arena, io, cmd_args, environ_map, .{ + .cmd_name = "objdump", + .root_src_path = "objdump.zig", + }); } else if (mem.eql(u8, cmd, "fetch")) { return cmdFetch(gpa, arena, io, cmd_args, environ_map); } else if (mem.eql(u8, cmd, "libc")) { -- 2.54.0