Re: Show functions in obj files? (Ronald F. Guilmette)
15 Sep 1996 14:15:30 -0400

          From comp.compilers

Related articles
Show functions in obj files? (Dietmar Schroeder) (1996-08-30)
Re: Show functions in obj files? danielv@CRT.UMontreal.CA (Daniel Villeneuve) (1996-08-31)
Re: Show functions in obj files? (1996-09-15)
Extracting call graphs (Re: Show functions in obj files?) (Eamonn McManus) (1996-09-22)
Re: Extracting call graphs (Re: Show functions in obj files?) (1996-09-23)
| List of all articles for this month |

From: (Ronald F. Guilmette)
Newsgroups: comp.compilers
Date: 15 Sep 1996 14:15:30 -0400
Organization: Infinite Monkeys & Co.
References: 96-08-101
Keywords: linker, tools, comment

Dietmar Schroeder <> wrote:
>we are looking for a tool that could display all functions used in a
>c-program by examinating the gcc compiled obj files (inc. debug info).
>Does XVCG do the job?
>We couldn't use gprof, because the program does not run!

If you only want the function names, and if you are on some sort of an
ELF-based systems which provides an SVR4-style `nm' command, just do:

                nm foobar | grep FUNC | awk -F'|' '{print $8}'

where `foobar' is the object file or executable file that you are interested

If on the other hand you are on some sort of system (e.g. an a.out system
or a Linux system) where all you have available is a good old-fashioned
sort of an `nm' program, then instead just do:

                nm foobar | grep ' T ' | awk '{print $3}'

If you want a list of the complete function _declarations_ (including
prototypes) and you want to generate it from an object file (which has
somplete source-level symbolic debugging information in it) this _can_
theoretically be done, and it shouldn't even be that hard, but I've
never seen any tool that did it. I suspect that is mostly just because
nobody ever felt like writing one.

On the other hand, if you want a _call graph_ of your C code (which I suspect
that you do, given that fact that you said that you want a list of functions
that are ``used'') then there ought to be _some_ tool out there somewhere
which will do that for you, but I confess that I don't know where you would
get it off the top of my head. (Wouldn't it be nice if either GCC or LCC
did this?)

One the other hand (I'm running out of hands) if you want _profiling data_
then you really do want some tool like `prof' or `gprof'. If you can't
get gprof to work for you, then it may be due to a bug and you should report
that to the proper GNU mailing list. If you need it to work yesterday,
the you should consider hiring a consultant from the SERVICE file (which
is distributed with GCC and other GNU packages) to get it working for you.


-- Ron Guilmette, Roseville, CA -------- Infinite Monkeys & Co. ------------
---- E-mail: ----------- Purveyors of Compiler Test Suites -
[I have more than once spliced together nm, sort, and awk to make an object
file cross-referencer. It's not perfect, since it doesn't know about indirect
calls, and in most cases it can't distinguish among multiple functions in the
same object file, but it can still be pretty useful. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.