kernel_utils.tcl 2.2 KB
#
# Copyright (C) 1996-1998 by the Board of Trustees
#    of Leland Stanford Junior University.
# 
# This file is part of the SimOS distribution. 
# See LICENSE file for terms of the license. 
#
# kernel_utils.tcl
# various little helpful utilities...

#
# tracking process fork, exec, and exit
annotation set osEvent procstart {
    log "PFORK $CYCLES cpu=$CPU  $PID($CPU)-$PROCESS($CPU)\n"
}
annotation set pc kernel::exece {
    set argv [symbol read "kernel:exec.c:((struct execa*)$a0)->argp"]
    log "PEXEC $CYCLES cpu=$CPU "

    # print out the whole command line
    set arg 1
    while {$arg != 0} {
        set arg [symbol read kernel::((int*)$argv)<0>]
        if {$arg != 0} {
            set arg [symbol read kernel::((char**)$argv)<0>]
            log " $arg"
            set argv [expr $argv + 4]
        }
    }
    log "\n"
}
annotation set osEvent procexit {
    log "PEXIT $CYCLES cpu=$CPU  $PID($CPU)-$PROCESS($CPU)\n"
}


# reads the process table and prints all the processes and their status
proc dumpProcesses {} {
    set proctbl "((proc_t*)[symbol read kernel::proc])"
    set numprocs [symbol read kernel::v.v_proc]

    for {set i 0} {$i < $numprocs} {incr i} {
        set stat [symbol read kernel:proc.h:$proctbl<$i>.p_stat]

        if $stat {
            console "pid [symbol read kernel:proc.h:$proctbl<$i>.p_pid] "

            set upte [symbol read kernel:proc.h:$proctbl<$i>.p_upgs<0>.pgi]
            set user "((user_t*)[expr (($upte & 0xFFFFFE00) << 3) + 0x80000000])"
            console "\"[symbol read kernel:proc.h:$user->u_comm]\" "
            
            switch $stat {
                1 {
                    console "sleeping "
                    set semapp [symbol read kernel:proc.h:&$proctbl<$i>.p_wchan]
                    set sema [hex [symbol read kernel::*((int*)$semapp)]]
                    if {$sema != 0} {
                        console "on [symbol find kernel $sema] "
                    }
                }
                2 { console "running " }
                3 { console "zombie " }
                4 { console "stoped " }
                5 { console "creating " }
                6 { console "sxbrk " }
            }
            
            console "\n"
        }
    }
}