Checking Target Variable Availability

As code evolves the target variables available may change. The @defined makes it easier to handle those variations in the available target variables. The @defined provides a test to see if a particular target variable is available. The result of this test can be used to select the appropriate expression.
The Example 3.10, “Testing target variable available Example” from the memory.stp tapset provides an probe event alias. Some version of the kernel functions being probed have an argument $flags. When available, the $flags argument is used to generate the local variable write_access. The versions of the probed functions that do not have the $flags argument have a $write argument and that is used instead for the local variable write_access.

Example 3.10. Testing target variable available Example

probe vm.pagefault = kernel.function("__handle_mm_fault@mm/memory.c") ?,
                     kernel.function("handle_mm_fault@mm/memory.c") ?
        name = "pagefault"
        write_access = (@defined($flags)
			? $flags & FAULT_FLAG_WRITE : $write_access)
	address =  $address