#! stap -p2

probe kernel.function("sys_open") { println(@defined($foobar)?$foobar:0)  } # invalid
probe kernel.function("sys_open") { println(@defined($mode)?$mode:$nosuchvar)  }  # valid
probe kernel.function("sys_open").return { println(@defined($foobar)?$foobar:0)  } # invalid
probe kernel.function("sys_open").return { println(@defined($mode)?$mode:$nosuchvar)  } # valid
probe kernel.trace("*")? { println(@defined($rw)?$rw:0) } # valid and invalid in places
probe kernel.mark("*")? { println(@defined($foo)?$foo:0) } # invalid
probe kernel.mark("*")? { println(@defined($name)?$name:$nosuchvar) } # valid
probe kernel.mark("*")? { println(@defined($argJJJ)?$argJJJ:0) }
probe process("stap").mark("pass*__*")? { println(@defined($arg1)?$arg1:$nosuchvar) } # valid
probe process("stap").mark("pass*__*")? { println(@defined($nosuchvar)?$nosuchvar:0) } # invalid
probe procfs("file").read { println(@defined($nosuchvar)?$nosuchvar:0) } # invalid
probe procfs("file").write { println(@defined($value)?$value:$nosuchvar) } # valid

probe begin,end,error,never { println(@defined($nosuchvar)?$nosuchvar:0) } # invalid
probe timer.s(1),timer.jiffies(1) { println(@defined($nosuchvar)?$nosuchvar:0) } # invalid
probe timer.profile { println(@defined($nosuchvar)?$nosuchvar:0) } # invalid

probe begin { println(@defined(@cast(0, "task_struct")->foo)?$nosuchvar:0) } # invalid
probe begin { println(@defined(@cast(0, "task_struct")->pid)?1:$nosuchvar) } # valid
probe kernel.function("sys_open") { println(@defined(@cast(0, "task_struct")->foo)?$nosuchvar:0) } # invalid
probe kernel.function("sys_open") { println(@defined(@cast(0, "task_struct")->pid)?1:$nosuchvar) } # valid

function foo1() { println(@defined(@cast(0, "task_struct")->foo)?$nosuchvar:0) } # invalid
function foo2() { println(@defined(@cast(0, "task_struct")->pid)?1:$nosuchvar) } # valid
probe begin { foo1(); foo2(); }

# PR11598: support @defined(&...)
probe begin { println(@defined(@cast(0, "task_struct")->rcu)?$nosuchvar:0) } # invalid
probe begin { println(@defined(&@cast(0, "task_struct")->rcu)?1:$nosuchvar) } # valid
probe kernel.function("release_task") { println(@defined($p->rcu)?$nosuchvar:0) } # invalid
probe kernel.function("release_task") { println(@defined(&$p->rcu)?1:$nosuchvar) } # valid
