By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,945 Members | 1,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,945 IT Pros & Developers. It's quick & easy.

instrument functions in gcc - not proper address getting printed

P: 5
Hi,


The problem is:

I am trying to get the function call tree by using the profiling functions __cyg_profile_func_enter and __cyg_profile_func_exit. But it is printing the address of these fns (__cyg_profile_func_enter and __cyg_profile_func_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

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. void __cyg_profile_func_enter( void *, void * )    __attribute__ ((no_instrument_function));
  4. void __cyg_profile_func_exit( void *, void * )    __attribute__ ((no_instrument_function));
  5.  
  6. FILE *fp = NULL;
  7.  
  8. int call_level = 0;
  9.  
  10. void *last_fn;
  11.  
  12.  
  13. void __cyg_profile_func_enter(void *this_fn, void *call_site)
  14. {
  15.  
  16.  if (fp == NULL) fp = fopen( "trace.txt", "w" ); 
  17.         if (fp == NULL) exit(-1); 
  18.  
  19.         if ( this_fn!=last_fn) ++call_level; 
  20.         for (int i=0;i<=call_level;i++) fprintf(fp,"\t"); 
  21.         fprintf(fp,  "entering %p\n", (int *)this_fn); 
  22.         (void)call_site; 
  23.         last_fn = this_fn; 
  24.  
  25.  }
  26.  
  27.  
  28. void __cyg_profile_func_exit(void *this_fn, void *call_site) 
  29.         --call_level; 
  30.         for (int i=0;i<=call_level;i++) fprintf(fp,"\t"); 
  31.         fprintf(fp, "exiting %p\n", (int *)this_fn); 
  32.         (void)call_site; 
  33.  
The code gets compiled and when running I got the following output.
Expand|Select|Wrap|Line Numbers
  1.         entering 29ff
  2.         entering 29ff
  3.         entering 29ff
  4.     exiting 2a79
  5.     entering 29ff
  6. exiting 2a79
  7. entering 29ff
  8. exiting 2a79
  9. entering 29ff
  10. exiting 2a79
  11. entering 29ff
  12. exiting 2a79
  13. entering 29ff
  14. exiting 2a79
I checked the addresses and found out that 29ff corresponds to __cyg_profile_func_enter and 2a79 corresponds to __cyg_profile_func_exit.

Why is this happening? Why is the proper address not printed?
Nov 6 '08 #1
Share this Question
Share on Google+
5 Replies


P: 5
Somebody please answer!
Nov 6 '08 #2

Banfa
Expert Mod 5K+
P: 8,916
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

Expand|Select|Wrap|Line Numbers
  1. void __cyg_profile_func_enter( void *, void * )    __attribute__ ((no_instrument_function));
  2.  
  3. void __cyg_profile_func_enter(void *this_fn, void *call_site)
  4. {
  5.    ...
  6. }
  7.  
try

Expand|Select|Wrap|Line Numbers
  1. void __attribute__ ((no_instrument_function)) __cyg_profile_func_enter(void *this_fn, void *call_site)
  2. {
  3.    ...
  4. }
  5.  
If this does not work you are going to have to wait for someone who knows more to answer.
Nov 6 '08 #3

P: 5
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?
Nov 7 '08 #4

Banfa
Expert Mod 5K+
P: 8,916
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?
Nov 7 '08 #5

P: 5
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.
Nov 7 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.