From 9846bd78e013e443a6ed67a1c2da997585e484f0 Mon Sep 17 00:00:00 2001 From: Valentin Gatien-Baron Date: Fri, 9 Feb 2024 16:15:22 -0500 Subject: [PATCH] make it possible to invoke `magic-trace run -- prog args` instead of `magic-trace run prog -- args`. The current CLI is annoying because you can't just prefix the command line with `magic-trace run`, you have to insert of `--` in between the prog and the args. Signed-off-by: Valentin Gatien-Baron --- src/trace.ml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/trace.ml b/src/trace.ml index abb5135e0..4411041ff 100644 --- a/src/trace.ml +++ b/src/trace.ml @@ -575,7 +575,7 @@ module Make_commands (Backend : Backend_intf.S) = struct ~readme:(fun () -> "=== examples ===\n\n\ # Run a process, snapshotting at ^C or exit\n\ - magic-trace run ./program -- arg1 arg2\n\n\ + magic-trace run -- ./program arg1 arg2\n\n\ # Run and trace all threads of a process, not just the main one, snapshotting \ at ^C or exit\n\ magic-trace run -multi-thread ./program -- arg1 arg2\n\n\ @@ -585,13 +585,21 @@ module Make_commands (Backend : Backend_intf.S) = struct (let%map_open.Command record_opt_fn = record_flags and decode_opts = decode_flags and debug_print_perf_commands = debug_print_perf_commands - and prog = anon ("COMMAND" %: string) and argv = - flag "--" escape ~doc:"ARGS Arguments for the command. Ignored by magic-trace." + let%map_open.Command command = anon (maybe ("COMMAND" %: string)) + and more_command = + flag "--" escape ~doc:"ARGS Arguments for the command. Ignored by magic-trace." + in + Option.to_list command @ Option.value more_command ~default:[] in fun () -> let open Deferred.Or_error.Let_syntax in let%bind () = check_for_perf () in + let prog = + match List.hd argv with + | None -> failwith "no program name provided at the command line" + | Some prog -> prog + in let executable = match Shell.which prog with | Some path -> path @@ -603,7 +611,6 @@ module Make_commands (Backend : Backend_intf.S) = struct evaluate_trace_filter ~trace_filter:opts.trace_filter ~elf in let%bind pid = - let argv = prog :: List.concat (Option.to_list argv) in run_and_record opts ~elf