The D compiler defines a set of built-in macro variables that you
can use when writing D programs or interpreter files. Macro
variables are identifiers that are prefixed with a dollar sign
($
) and are expanded once by the D compiler
when processing your input file. The following table describes the
macro variables that the D compiler provides.
Table 9.1 D Macro Variables
Name | Description | Reference |
---|---|---|
| Macro arguments | |
| Effective group ID |
See the |
| Effective user ID |
See the |
| Real group ID |
See the |
| Process ID |
See the |
| Process group ID |
See the |
| Parent process ID |
See the |
| Session ID |
See the |
| Target process ID | Section 9.4, “Target Process ID” |
| Real user ID |
See the |
With the exception of the $[0-9]+
macro
arguments and the $target
macro variable, all
of the macro variables expand to integers that correspond to
system attributes, such as the process ID and the user ID. The
variables expand to the attribute value associated with the
current dtrace process or whatever process is
running the D compiler.
Using macro variables in interpreter files enables you to create
persistent D programs that you do not need to edit every time you
want to use them. For example, to count all system calls, except
those that are executed by the dtrace command,
you would use the following D program clause containing
$pid
:
syscall:::entry /pid != $pid/ { @calls = count(); }
This clause always produces the desired result, even though each invocation of the dtrace command has a different process ID. Macro variables can be used in a D program anywhere that an integer, identifier, or string can be used.
Macro variables are expanded only one time when the input file is parsed, not recursively.
Except in probe descriptions, each macro variable is expanded to form a separate input token and cannot be concatenated with other text to yield a single token.
For example, if $pid
expands to the value
456
, the D code in the following example would
expand to the two adjacent tokens 123
and
456
, resulting in a syntax error, rather than
the single integer token 123456
:
123$pid
However, in probe descriptions, macro variables are expanded and
concatenated with adjacent text. For example, the following clause
uses the DTrace pid
provider to instrument the
dtrace command:
# dtrace -c ./a.out -n 'pid$target:libc.so::entry'
Macro variables are only expanded one time within each probe
description field and they may not contain probe description
delimiters (:
).