On Tue, May 20, 2008 at 1:54 PM, <[EMAIL PROTECTED]> wrote: > Dear Shafi > > Thanks you very much for the clear details. Definitely your inputs are > helpful. > > 1) I am sure that in gcc-4.0 I found there is file gmon.c in the path > gcc-4.0.0/gcc/gmon.c. Anyhow let me concentrate on gmon.c of glibc. > I am not sure why this is found in gcc. It is not available in other versions.
> 2) Next thing I would like to know is to better understand the gmon.c of > glibc I would like to degug glibc. since glibc is linked with gcc, I built > gcc and glibc separately. while debugging gcc is referring shared glib > library, but not the one I built freshly for debugging purpose. To make > this happen, where I need to change the path to like both gcc and glibc ? IIRC by passing -static to linker you can link with the static glibc. To make sure that your glibc is picked up maybe you can hide the other glibc from the PATH variable. > > 3) Please correct me If I am wrong > a. for every function mcount() function is called to collect the caller > and callee address. where this collected info is placed ? > b. the flow of monstartup() function > monstartup()-->moncontrol() --> profil() > > who will call the monstartup() ? is it gcrt0 ? before calling the > main() function of our routine ? Thats right. Thats the other thing that happen when -pg option is provided. A different startup files is used. This will have a call to the monstartup. monstartup will initialize all the data structures required for collecting profile data and invokes profil system call. > > c. write_profiling() ---> write_gmon() functions calls write_hist(), > write_call_graph() and write_bb_counts(). here who calls the > write_profiling() ? > > d. mcleanup() calls write_gmon(). who calls the mcleanup() ? is it > gcrt0 ? after control return from main() function ? IIRC it is mcleanup that calls the output function write_gmon, which in turn calls the other functions. mcleanup will be called from the startup file after main returns. mcleanup dumps all the information in the output file. Hope this helps. Regards, Shafi > > Thanks and Regards > Raja > > > > > > > > >> 2008/5/19 <[EMAIL PROTECTED]>: >>> Hi, >>> >>> I am Raja, I need a favor on understand how the gmon.out file is >>> created. >>> Please help me. >>> >>> 1. gmon.c is available in both gcc and glibc. Which is the one used to >>> create gmon.out ? >> >> I don't think gcc has gmon.c. Only glibc has it. You can also find >> gmon in newlib for some targets. But this will be customized for the >> target >> >>> >>> 2. Can you brief how profile information required to create gmon.out is >>> captured?���"B"BWhich are the functions are > responsible for this ? >> >> These days gmon.c is used only to get histogram records(time related >> infomation). All the other information is now produced by gcc itself, >> than can be analyzed using gcov. (You will get gcov when you build >> gcc). >> For histogram records, gmon.c code primarily uses 'profil' system >> call. You can get more information about this in man pages. And of >> course you will get to know how this is used if you go through the >> code in gmon.c >> >> When -pg switch is enabled all complier does is inserting a call to >> the function mcount, usually after the function prologue. This is the >> function the collects all the needed information. For profiling >> information about caller address and callee address is necessary. If >> this information cannot be obtained using __bultin_return_address then >> this is calculated by mcount in a target specific manner and passed >> onto another function that takes these address as the arguments and >> gathers the profiling information. >> >>> >>> 3. Suppose assume that executable is built without ��Cpg > option, but >>> want >>> to create gmon.out at run-time. Is there any way or guidelines to >>> implement? >> >> A call to the profiling function (mcount) should be there to generate >> profiling information. Without that you won't be able to generate >> gmon.out >> >> Hope this helps, >> >> Regards, >> Shafi >> >>> >>> Thanks and Regards >>> Raja Saleru >>> >>> >> > >