instrument functions in gcc - not proper address getting printed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • myra
    New Member
    • Sep 2008
    • 5

    instrument functions in gcc - not proper address getting printed

    Hi,


    The problem is:

    I am trying to get the function call tree by using the profiling functions __cyg_profile_f unc_enter and __cyg_profile_f unc_exit. But it is printing the address of these fns (__cyg_profile_ func_enter and __cyg_profile_f unc_exit) instead of the other functions.

    Please see the code and suggest a solution.

    This is running on zdcc, a gcc derivative on Windows.

    The code is

    Code:
    #include <stdio.h>
    
    void __cyg_profile_func_enter( void *, void * )    __attribute__ ((no_instrument_function));
    void __cyg_profile_func_exit( void *, void * )    __attribute__ ((no_instrument_function));
    
    FILE *fp = NULL;
    
    int call_level = 0;
    
    void *last_fn;
    
    
    void __cyg_profile_func_enter(void *this_fn, void *call_site)
    {
    
     if (fp == NULL) fp = fopen( "trace.txt", "w" ); 
            if (fp == NULL) exit(-1); 
    
            if ( this_fn!=last_fn) ++call_level; 
            for (int i=0;i<=call_level;i++) fprintf(fp,"\t"); 
            fprintf(fp,  "entering %p\n", (int *)this_fn); 
            (void)call_site; 
            last_fn = this_fn; 
    
     }
    
    
    void __cyg_profile_func_exit(void *this_fn, void *call_site) 
    { 
            --call_level; 
            for (int i=0;i<=call_level;i++) fprintf(fp,"\t"); 
            fprintf(fp, "exiting %p\n", (int *)this_fn); 
            (void)call_site; 
    
    }
    The code gets compiled and when running I got the following output.
    Code:
    		entering 29ff
    		entering 29ff
    		entering 29ff
    	exiting 2a79
    	entering 29ff
    exiting 2a79
    entering 29ff
    exiting 2a79
    entering 29ff
    exiting 2a79
    entering 29ff
    exiting 2a79
    entering 29ff
    exiting 2a79
    I checked the addresses and found out that 29ff corresponds to __cyg_profile_f unc_enter and 2a79 corresponds to __cyg_profile_f unc_exit.

    Why is this happening? Why is the proper address not printed?
    Last edited by myra; Nov 6 '08, 11:31 AM. Reason: some error in code
  • myra
    New Member
    • Sep 2008
    • 5

    #2
    Somebody please answer!

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      This is an international forum, waiting just under 2 hours and then demanding a reply is not going to work. The person who knows the answer to your question may be in a different time zone to you and may have just gone to sleep.

      On this forum it is only consider OK to post this kind of message if
      1. It is worded in a polite fashion
      2. At least 24 hours have passed


      I have no experience with you compiler but a quick search of the web suggests that you should try declaring your functions in this manor, instead of

      Code:
      void __cyg_profile_func_enter( void *, void * )    __attribute__ ((no_instrument_function));
      
      void __cyg_profile_func_enter(void *this_fn, void *call_site)
      {
         ...
      }
      try

      Code:
      void __attribute__ ((no_instrument_function)) __cyg_profile_func_enter(void *this_fn, void *call_site)
      {
         ...
      }
      If this does not work you are going to have to wait for someone who knows more to answer.

      Comment

      • myra
        New Member
        • Sep 2008
        • 5

        #4
        Hi,

        Sorry. That was not demanding of an answer, but the tone of exasperation because I was under some pressure to finish it under a particular time.

        Will not repeat it.

        Thanks for the suggestion, but it also gives the same answer.

        Any other idea of what might be wrong?

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          OK so no-one else has replied, this is a general forum so it is possible no has experience with your compiler (or that bit of it) you may what to try finding a forum specific to your compiler or if there isn't one a GCC specific forum (which I am sure must exist somewhere).

          BTW did you mean zdcc or did you mean sdcc?

          Comment

          • myra
            New Member
            • Sep 2008
            • 5

            #6
            It is zdcc. It is specific for a zsp chips that were developed by LSI. Something called sdcc is also there for some other dsps of them.

            Well, I will see if i can find the info in some Gcc forum out there.

            Comment

            Working...