commit 1809a19c27d4dc5cebdf4c16bae51071019e9f96 (tree)
parent 2322d45d80a88730b356b6a2b0101bcffb5a0afd
Author: Andrew Kelley <andrew@ziglang.org>
Date: Sun, 5 Apr 2026 16:27:09 -0700
add objdump subcommand
does nothing so far
Diffstat:
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/lib/compiler/objdump.zig 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
@@ -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")) {