Weblog

All | China | Cricket | General | IPFilter | OpenSolaris | Solaris IPFilter | USA vs.... | Zones
« Previous day (Jul 16, 2007) | Main | Next day (Jul 18, 2007) »
20070717 Tuesday July 17, 2007

Scripting with cscope

The cscope (and cscope-fast) tools provide an excellent way for us to search for particular instances of phrases, etc, inside the Solaris source code. The only downside is that the tool is interactive: it wants to use curses to ask for input and display its output. How then to make use of its knowledge in scripts?

Whilst the proper solution is to have cscope and cscope-fast modified to have a non-curses output format, a workaround that can be used in the mean time is to define a special "tty" that ensures no escape sequences (or other nasties) end up in the output.

And the end result is I can do this:


$ ~/bin/cscope-grep ip_input
1       ip.c    <global>        15017   ip_input(ill_t  *ill,   ill_rx_ring_t  *ip_ring,        mblk_t  *mp_chain,
2       ip.h    <global>        3225    extern  void    ip_input(ill_t  *,     ill_rx_ring_t    *,      mblk_t  *,
3       ip_if.c ill_capability_dls_capabl       2925    dls.dls_rx      =      (uintptr_t)ip_input;
4       ip.c    ip_rput 14993   ip_input(ill,   NULL,   mp,     NULL);
5       ip_netinfo.c    ip_ni_queue_func_impl   1293    ip_input(ill,   NULL,  packet->ni_packet,       0);
6       ip_squeue.c     ip_soft_ring_assignment 754     ip_input(ill,   NULL,   mp_chain,       mhip);                          

Update

As Alan Burlinson mentioned below, cscope-fast has a command line option, "-l", that allows for it to generate output that is not screen orientated. This can be used like this:


$ cscope-fast -l -d -0 ip_input
uts/common/inet/ip/ip.c <global> 15017 ip_input(ill_t *ill, ill_rx_ring_t *ip_ring, mblk_t *mp_chain,
uts/common/inet/ip.h <global> 3225 extern void ip_input(ill_t *, ill_rx_ring_t *, mblk_t *,
uts/common/inet/ip/ip_if.c ill_capability_dls_capable 2925 dls.dls_rx = (uintptr_t)ip_input;
uts/common/inet/ip/ip.c ip_rput 14993 ip_input(ill, NULL, mp, NULL);
uts/common/inet/ip/ip_netinfo.c ip_ni_queue_func_impl 1293 ip_input(ill, NULL, packet->ni_packet, 0);
uts/common/inet/ip/ip_squeue.c ip_soft_ring_assignment 754 ip_input(ill, NULL, mp_chain, mhip);
>>

While this gives us a leg up, there are two problems:

To wrap this up, I've used a perl script below because I'm more familiar with perl being able to carve up an array and print it out than I am with shell.


#!/bin/perl
$args = join(' ',@ARGV);
open(I, "cat /dev/null | cscope-fast -l -d $args|") || die $!;
while (<I>) {
        last if (/^>>/);
        @F = split(/ /);
        @B = splice(@F,3,$#F);
        @A = splice(@F,0,3);
        print join("\t",@A)."\t".join(' ',@B)."\n";
}
close(I);
exit(0);

Thanks Alan for the pointer and reminder.

( Jul 17 2007, 10:05:44 AM PDT ) Permalink Comments [2]

Calendar

RSS Feeds

Search

Links

Navigation

Referers