Re: [RFA] patch to add 'maint profile-gdb' command

Eli Zaretskii
2001-09-11T01:57:00Z

On Tue, 11 Sep 2001, Jason Molenda wrote:

> On Tue, Sep 11, 2001 at 09:39:16AM +0200, Eli Zaretskii wrote:
>
> > > monstartup provides some information, but not everything that full
> > > profiling gets you.
> >
> > Sorry, I don't understand what you mean. AFAIK, a program linked with
> > "-pg" calls monstartup in its startup code.
>
> No, there is a lot more to a profiled program than that. The
> compiler adds instrumentation in the code, sometimes simple calls
> to mcount, sometimes more than that. It'll link in different
> startup files (e.g. "gcrt1", "gcrtend"), and different versions of
> libc (e.g. "c_p"), as well as the "gmon" library on some systems.
> A simple call to monstartup() won't do that.

Granted, I already know that ;-)

What I meant is that given you did compile with -pg, monstartup should do
the same as linking with -pg, with the possible exception of linking in
libc_p.a. (I don't think profiling the library is something you would
want to do in this case. IIRC, many systems don't even have libc_p
installed.)

> Programs that are not loaded with -pg may selectively collect profiling
> statistics by calling monstartup() with the range of addresses to be pro-
> filed.
> [...]
> Only functions in that range that have been compiled with the -pg
> option to cc(1) will appear in the call graph part of the output; howev-
> er, all functions in that address range will have their execution time
> measured.
>
> Calling monstartup() will get you the timing information, but not
> the call graph information on a FreeBSD system, apparently. On a
> Linux system, calling monstartup() doesn't get you anything unless
> you compile with -pg.

I think there's a misunderstanding: I know that you need to compile
with -pg, I was talking about _linking_ with -pg (which is what causes
the profiling to start automatically, and requires that you stop it
in GDB's `main').

> #ifdef ENABLE_PROFILE
> #ifdef HAVE_MONCONTROL
> moncontrol (0);
> #endif
> #endif
>
> Unless we find some system which has profiling but doesn't have
> moncontrol(), I don't see any benefit to using autoconf to detect
> this.

I know at least one such system: DJGPP (moncontrol and monstartup were
added to CVS lately, but they are not in the last released version).

Does Cygwin have these functions?

Anyway, I thought it was a policy in GNU projects to test for presence of
any non-Posix function that a program needs.