@@ 2,11 2,12 @@ use fmt;
use os;
use os::exec;
use time;
+use getopt;
use format::dwarf;
use trace;
-export fn main() void = {
+fn run(prog: str) void = {
fmt::printfln("bpinst = 0x{:02x}", bpinst)!;
match (trace::fork()) {
case let pid : trace::pid_t =>
@@ 24,8 25,36 @@ export fn main() void = {
trace::cont(pid);
case void =>
trace::traceme();
- let prog = os::args[1];
let cmd = exec::cmd(prog, prog)!;
exec::exec(&cmd);
};
};
+
+fn usage(name: str) void = {
+ fmt::printfln("usage: {} <executable-file>", name)!;
+};
+
+export fn main() void = {
+ const cmd = getopt::parse(os::args,
+ "hadb",
+ ('h', "print this help message and exit"),
+ "executable-file"
+ );
+ defer getopt::finish(&cmd);
+
+ for (let i = 0z; i < len(cmd.opts); i += 1) {
+ const opt = cmd.opts[i];
+ switch (opt.0) {
+ case 'h' =>
+ usage(os::args[0]);
+ return;
+ };
+ };
+
+ if (len(cmd.args) < 1) {
+ usage(os::args[0]);
+ return;
+ };
+ const prog = cmd.args[0];
+ run(prog);
+};