[Crash-utility] How to use scripts in crash?

Max Matveev makc at gmx.co.uk
Thu Mar 8 00:34:11 UTC 2012


On Wed, 7 Mar 2012 07:57:40 -0800, Lei Wen wrote:

 lei> I then need do following
 lei> 1. using "p" to get "file_systems" symbol value
 lei> 2. using "list" with command as "list -o file_system_type.next -s file_system_type.name,fs_flags <the file_systems  symbol value>"

 lei> So if the previous file_systems symbol value could be stored,
 lei> and then I don't need to copy the "p" result to "list" command
 lei> by hand, but could let script do such kind of thing.

Others have mentioned pykdump and sial, there is also a granddaddy of
it all - good ol' gdb script. They're not as flexible as sial or
pykdump but they have an advantage of being "always on" - gdb is part
of crash.

Here is an example of printing list of 'rpc tasks' from sunrpc module

define rpc_tasks
        set $e = ((struct list_head *)$arg0)
        set $n = $e->next
        set $of = &(((struct rpc_task *)0)->tk_task)

        while $n != $e
           set $i = (struct rpc_task *)((char *)$n - (char *)$of)
           set $proc = $i->tk_msg->rpc_proc
           if ($proc->p_name)
                   printf "%p\t%s", $i, $proc->p_name
           else
                   printf "%p\tNULL", $i
           end
           printf "\t%p(%s, xprt %p)\t%p", $i->tk_client,
           $i->tk_client->cl_protname, $i->tk_client->cl_xprt,
           $i->tk_client->$i->tk_rqstp

           if ($i->tk_rqstp)
                printf "(%x)", $i->tk_rqstp->rq_xid
           end
           printf "\t%d\n", $i->tk_pid
           set $n = $n->next
        end
end

You can type this by hand or save it into a file and then use
'source your.file.name.here' command in crash. After sourcing is done
you have a command called rpc_tasks which can be used like this:

crash> rpc_tasks 0xabcd8000

where 0xabcd8000 is the list_head of a task list.

The example shows how to walk a list and how to access a list entry if
the linkage is not directly at the start of the structure.

max




More information about the Crash-utility mailing list