authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-05 16:27:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-11 18:56:51-07:00
log1809a19c27d4dc5cebdf4c16bae51071019e9f96
treecbfca4dfc481446140c88687e8b442090646fdec
parent2322d45d80a88730b356b6a2b0101bcffb5a0afd

add objdump subcommand

does nothing so far

2 files changed, 41 insertions(+), 2 deletions(-)

lib/compiler/objdump.zig created+33
......@@ -0,0 +1,33 @@
1const std = @import("std");
2const Io = std.Io;
3const fatal = std.process.fatal;
4
5pub fn main(init: std.process.Init) !void {
6 const io = init.io;
7 const args = try init.minimal.args.toSlice(init.arena.allocator());
8
9 var input_path: ?[]const u8 = null;
10 var i: usize = 0;
11 while (i < args.len) : (i += 1) {
12 const arg = args[i];
13 if (std.mem.startsWith(u8, arg, "-")) {
14 if (std.mem.eql(u8, arg, "-h") or std.mem.eql(u8, arg, "--help")) {
15 return Io.File.stdout().writeStreamingAll(io, usage);
16 } else {
17 fatal("unrecognized argument: {s}", .{arg});
18 }
19 } else if (input_path == null) {
20 input_path = arg;
21 } else {
22 fatal("unexpected positional: {s}", .{arg});
23 }
24 }
25}
26
27const usage =
28 \\Usage: zig objdump [options] file
29 \\
30 \\Options:
31 \\ -h, --help Print this help and exit
32 \\
33;
src/main.zig+8-2
......@@ -95,13 +95,14 @@ const normal_usage =
9595 \\ reduce Minimize a bug report
9696 \\ translate-c Convert C code to Zig code
9797 \\
98 \\ ar Use Zig as a drop-in archiver
98 \\ ar Combine object files into static archive
9999 \\ cc Use Zig as a drop-in C compiler
100100 \\ c++ Use Zig as a drop-in C++ compiler
101101 \\ dlltool Use Zig as a drop-in dlltool.exe
102102 \\ lib Use Zig as a drop-in lib.exe
103 \\ objcopy Manipulate executables and relocatables
104 \\ objdump Print information about executables and relocatables
103105 \\ ranlib Use Zig as a drop-in ranlib
104 \\ objcopy Use Zig as a drop-in objcopy
105106 \\ rc Use Zig as a drop-in rc.exe
106107 \\
107108 \\ env Print lib path, std path, cache directory, and version
......@@ -342,6 +343,11 @@ fn mainArgs(
342343 .cmd_name = "objcopy",
343344 .root_src_path = "objcopy.zig",
344345 });
346 } else if (mem.eql(u8, cmd, "objdump")) {
347 return jitCmd(gpa, arena, io, cmd_args, environ_map, .{
348 .cmd_name = "objdump",
349 .root_src_path = "objdump.zig",
350 });
345351 } else if (mem.eql(u8, cmd, "fetch")) {
346352 return cmdFetch(gpa, arena, io, cmd_args, environ_map);
347353 } else if (mem.eql(u8, cmd, "libc")) {