New paste Repaste Download
#!/usr/bin/awk -f
#
# sydtrace.awk:
# Feed the output of sydtrace.bt to this script.
#
BEGIN {
    # Lookup command (override by setting CARGO_BIN_EXE_syd-sys in the environment)
    lookup_cmd = "syd-sys"
    if (ENVIRON["CARGO_BIN_EXE_syd-sys"] != "") lookup_cmd = ENVIRON["CARGO_BIN_EXE_syd-sys"]
}
{
    # Keep kstack/ustack and stack lines untouched.
    if ($0 ~ /^kstack:/ || $0 ~ /^ustack:/ || $0 ~ /^[ \t]*»/) {
        print
        next
    }
    # Extract sys=NUMBER and comm=TOKEN (if present) using RSTART/RLENGTH
    sysnum = ""
    commtok = ""
    if (match($0, /sys=[-]?[0-9]+/)) {
        # sys= starts at RSTART, length RLENGTH; value begins after "sys="
        sysnum = substr($0, RSTART + 4, RLENGTH - 4)
    }
    if (match($0, /comm=[^ ]+/)) {
        # comm= starts at RSTART, length RLENGTH; value begins after "comm="
        commtok = substr($0, RSTART + 5, RLENGTH - 5)
    }
    # If either missing, print unchanged.
    if (sysnum == "" || commtok == "") {
        print
        next
    }
    # If sys is negative, do not query and leave line as-is.
    if (substr(sysnum, 1, 1) == "-") {
        print
        next
    }
    # Defensive numeric check: require all digits
    if (sysnum !~ /^[0-9]+$/) {
        print
        next
    }
    # Lookup (cached). `seen` flags whether we've cached this sysnum.
    if (seen[sysnum]) {
        name = cache[sysnum]
    } else {
        name = ""
        cmd = lookup_cmd " " sysnum
        if ((cmd | getline out) == 1) {
            # parse first whitespace-separated token as the syscall name
            n = split(out, parts)
            if (n >= 1) name = parts[1]
        }
        close(cmd)
        cache[sysnum] = name
        seen[sysnum] = 1
    }
    # If lookup failed (empty name), leave original line unchanged.
    if (name == "") {
        print
        next
    }
    # Insert name=<name> immediately after the comm=... token.
    if (match($0, /comm=[^ ]+/)) {
        prefix = substr($0, 1, RSTART - 1)
        token  = substr($0, RSTART, RLENGTH)
        rest   = substr($0, RSTART + RLENGTH)
        print prefix token " name=" name rest
    } else {
        # defensive fallback
        print
    }
}
Filename: dev/sydtrace.awk. Size: 2kb. View raw, , hex, or download this file.

This paste expires on 2025-10-14 16:51:38.661105. Pasted through v1-api.