dtrace_program_strcompile
() Function
After the program has a DTrace handle, the next step is to compile the D program. The consumer uses the dtrace_program_strcompile
() function to compile the string that contains the D program. You can also use the dtrace_program_fcompile
() function to compile a file that contains a D program. Both of these functions return a pointer to a data structure that describes the compiled program.
dtrace_prog_t *dtrace_program_strcompile(dtrace_hdl_t *dtp, const char *s, dtrace_probespec_t spec, uint_t cflags, int argc, char *const argv[])
The arguments to the dtrace_program_strcompile
() function are:
-
The DTrace handle.
-
A string containing the D program. The
dtrace_program_fcompile
() function passes a file handle. -
A
dtrace_probespec_t
spec to indicate the context of the probe you are using, which can be a provider, a module, a function, or a name. For example, if you specify theDTRACE_PROBESPEC_PROVIDER
probe, you can specify only provider names. The typical consumer uses only theDTRACE_PROBESPEC_NAME
probe. -
Flags. The full list of flags can be found in the
/usr/include/dtrace.h
file. Some of the common options are:-
DTRACE_C_DIFV
-
Shows the target language instructions that results from the compilation and additional information to execute the target language instructions.
-
DTRACE_C_ZDEFS
-
Instructs the compiler to permit probes, whose definitions do not match the existing probes. By default, the compiler does not allow probe definitions that do not match existing probes.
-
DTRACE_C_CPP
-
Instructs the compiler to preprocess the input program with the C preprocessor. For more information, see the
cpp
(1) man page.
-
-
Number of arguments, which are passed to the program.
-
Arguments passed to the program.
The arguments to the dtrace_program_fcompile
() function are fewer because the dtrace_probespec_t
argument is not passed. You can modify the consumer to accept a file specified in the command line by replacing the dtrace_program_strcompile
() function with code similar to the following example:
if ((fp = fopen(argv[1], "r")) == NULL) fatal("failed to open %s", argv[1]); if ((prog = dtrace_program_fcompile(g_dtp, fp, 0, 0, NULL)) == NULL) fatal("invalid program");