Skip to content

Commit

Permalink
make it possible to invoke magic-trace run -- prog args
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
v-gb authored and Xyene committed Feb 17, 2024
1 parent 3b73ef9 commit 9846bd7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9846bd7

Please sign in to comment.