Skip to content

Instantly share code, notes, and snippets.

@AlainODea
Last active July 23, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

Here's a sample of the ld output when running make TEST=topHandler02 in ghc/testsuite/:

  3   5830         exec_common:exec-success     8959689596:     /usr/bin/ld -R/opt/local/lib/ -Y P,/lib/amd64:/usr/lib/amd64:/opt/local/lib/ -Q
argv[0]: /usr/bin/ld
argv[1]: -R/opt/local/lib/
argv[2]: -Y
argv[3]: P,/lib/amd64:/usr/lib/amd64:/opt/local/lib/
argv[4]: -Qy
argv[5]: -o
argv[6]: topHandler02.o
argv[7]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3
argv[8]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib/amd64
argv[9]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../amd64
argv[10]: -L/lib/amd64
argv[11]: -L/usr/lib/amd64
argv[12]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../../../x86_64-sun-solaris2.11/lib
argv[13]: -L/opt/local/gcc47/lib/gcc/x86_64-sun-solaris2.11/4.7.3/../../..
argv[14]: -R/opt/local/gcc47/x86_64-sun-solaris2.11/lib/amd64
argv[15]: -R/opt/local/gcc47/lib/amd64
argv[16]: -lrt
argv[17]: -r
argv[18]: /tmp/ghc89544_0/ghc89544_6.o
argv[19]: /tmp/ghc89544_0/ghc89544_5.o

@AlainODea
Copy link
Author

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