Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Aug 2004 10:41:11 -0400
From:      =?UTF-8?Q?Josh_=C5=8Cckert?= <torstenvl@gmail.com>
To:        "Jeremy C. Reed" <reed@reedmedia.net>
Cc:        freebsd-chat@freebsd.org
Subject:   Re: tool for listing C functions used in source code?
Message-ID:  <126eac480408210741323f9d16@mail.gmail.com>
In-Reply-To: <Pine.LNX.4.43.0408202115030.11735-100000@pilchuck.reedmedia.net>
References:  <Pine.LNX.4.43.0408202115030.11735-100000@pilchuck.reedmedia.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 20 Aug 2004 21:30:24 -0700 (PDT), Jeremy C. Reed
<reed@reedmedia.net> wrote:
> On Fri, 20 Aug 2004, [UTF-8] Josh =C5=8Cckert wrote:
>=20
> > > What are some good tools for searching source code that can list all =
the
> > > standard libc functions used?
>=20
> > for i in `ls /usr/share/man/man3/ | sed -e '/\\\..*$/d'`; do echo $i;
> > grep -c $i filename.c; done
>=20
> Thank you for your ideas. Nevertheless, I am looking for a tool that
> actually parses the code and follows includes like cflow, cscope or cxref
> (which I still can't figure out yet).
>=20
> Your idea implies that the function used is accurately documented. Also i=
t
> is missing a cut or sed to chop the  ".3" off the end. Also, your idea
> could have many false positives due to matching partial function names.
> Also, it could match on code that is never used (because of C processor
> directives or in comments). By the time, I get a bunch of sed and grep to
> help organize it, it would be easier to find a program that already does
> it.
>=20
> > man sed
> > man grep
>=20
> I know sed and grep. Along with awk, they are my good friends :)
>=20
> Some things I have tried:
>=20
> cflows (I also packaged it for pkgsrc.)
>=20
>   cflow /usr/src/bin/ls/*.c | egrep '{}$' | cut -f 3
>=20
> But the output is missing getopt and printf and probably others. Also it
> shows functions that aren't shown in code (like clock(3)), but that is
> probably okay since they must be called by a function in the code. (I'd
> like it to tell me what functions are calling the other functions.) Any
> suggestions with cflow?
>=20
> I also tried cxref, like:
>=20
>  cxref -xref-all -raw /usr/src/*bin/*/*c | grep ^Calls | grep -v ' : /'
>=20
> It appears to do a good job. I still need to figure out how to get it to
> do source that is in different directories while still outputting to one
> "-raw" standard output. Any examples for doing that?
>=20
> I also tried cscope, but I can't figure out how to get it to what I want.
> I do not want something interactive. And I don't want to manually have to
> run it numerous times to get my info.
>=20
> Any other suggestions?
>=20
>  Jeremy C. Reed
>=20
>                          technical support & remote administration
>                          http://www.pugetsoundtechnology.com/
>=20
>=20
>=20
> _______________________________________________
> freebsd-chat@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-chat
> To unsubscribe, send any mail to "freebsd-chat-unsubscribe@freebsd.org"
>=20

Your original post said 'used' -- this is kind of ambiguous. Since the
call to clock() seemed okay but you complained about dead code being
counted, I'll assume you mean 'called, directly or indirectly'. The
problem with this is that the program would have to know the internal
implementations of standard library functions when it scans the source
code, or it would have to scan the binary. I don't know how to
accomplish either of these ends personally (perhaps your cflow or
whatever will work for you?). However, if you only want things that
your code calls directly, your criticisms are unfounded.

> Your idea implies that the function used is accurately documented.

If it's in libc, it should be documented.

> Also it
> is missing a cut or sed to chop the  ".3" off the end.

Uhhh... really? . o O ( sed -e '/\\\..*$/d' )

> Also, your idea
> could have many false positives due to matching partial function names.

"you might want to replace all tokens that can separate two function
calls with newlines and create a temporary file and then search that
instead" Extend that a bit further and replace all whitespace with
newlines, then delete newlines, then put any operators that aren't on
a line by themselves on a line by themselves... If you separated out
all the tokens in the code you could then check the whole line,
something like ^$i\$ or whatever the syntactic mess necessary to
accomplish that is. Then it would match the entire function name or
not at all.

> Also, it could match on code that is never used (because of C processor
> directives or in comments).

So uh... run the C processor err umm preprocessor on the code first...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?126eac480408210741323f9d16>