# Script for testing $$vars, $$parms, $$locals
#
# This works by grep'ing for the format strings produced in pass-3, then
# comparing that $$vars is the same as $$parms + $$locals.
#
# NB: With PR3217 compiled-printf code, we can't tell as easily what was
# generated.  However, there's still the ifdef'ed STP_LEGACY_PRINT code which
# has the format string we care about here.  If that ever goes away, we'll
# probably have to fall back to comparing pass-2 output instead.
    
set test "vars"

# grab C statement that $$vars yields
set cmd [concat stap -p3 -e {"probe kernel.statement(\"bio_copy_user@fs/bio.c+1\") \{print (\$\$vars)\}"} | grep {"_stp_snprintf.*="} | sed -e {"s/^.*MAXSTRINGLEN, \"//"} -e {s/\".*$//}]
catch {eval exec $cmd} vars

# grab C statement that $$parms yields
set cmd [regsub "vars" $cmd "parms"]
catch {eval exec $cmd} parms

# grab C statement that $$locals yields
set cmd [regsub "parms" $cmd "locals"]
catch {eval exec $cmd} locals

# syntax check of $$vars C statement
set vars_ok [regexp "(\[a-z_\]+=%#llx *)+" $vars]
if {!$vars_ok} {
    fail "$test"
} else {
    pass "$test"
}

# $$vars should be equivalent to $$parms + $$locals
if {![string equal $vars "$parms $locals"]} {
    fail "$test parms/locals"
    verbose -log "vars=$vars="
    verbose -log "rest=$parms $locals="
} else {
    pass "$test parms/locals"
}

