Skip to content

Instantly share code, notes, and snippets.

@AlainODea
Last active July 23, 2017 17:08
Show Gist options
  • Save AlainODea/61f1ed3d2711ad111ac2 to your computer and use it in GitHub Desktop.
Save AlainODea/61f1ed3d2711ad111ac2 to your computer and use it in GitHub Desktop.
DTrace detailed program arguments (destructive hack)
#!/usr/sbin/dtrace -s
#pragma D option destructive
proc:::exec-success
/execname == $$1/
{
trace(pid);
stop();
system("pargs %d ; prun %d", pid, pid);
}

pargs.d(1m) -- captures arguments of subprocesses of a command

SYNOPSIS

pargs.d [SUBPROCESS NAME] -c [COMMAND]

DESCRIPTION

pargs.d captures the arguments to subprocesses of a specific name that are executed by a command.

OPTIONS

-c

Run the specified command cmd and exit upon its completion. If more than one -c option is present on the command line, dtrace exits when all commands have exited, reporting the exit status for each child process as it terminates. The process-ID of the first command is made available to any D programs specified on the command line or using the -s option through the $target macro variable. Refer to the Solaris Dynamic Tracing Guide for more information on macro variables.

EXAMPLES

Example 1: Showing the arguments handed to cpphs by make (for
           debugging GHC builds)

    pargs.d cpphs -c make

SEE ALSO

dtrace(1M)
@AlainODea
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment