PDA

View Full Version : Watcom __PRO,__EPI and program profile



steph
06-27-2012, 03:42 AM
Hello.


I'm trying to get program call tree for code analys (something like):
main
--->func1
--------->func2
--->func3


In gcc there are great funtions as backtrace,backtrace_symbols,etc.
In windows stackwalk64.
I mentioned both of them for regular systems.


I've tried to found something like them in watcom (10.6 QNX4.25), but (for now) got nothing. After reading manual for wcc I get next two options for compilier
-ee - add __EPI to end of each function
-ep - add __PRO to start of each function
It seems that after building app and running it, I will get necessary profile "tree", but wlink refuse to link object file, printing "undifined symbol __PRO,__EPI".
In manual for wlink there are no any data about __PRO,__EPI.
So is it possible to use them? Are there any other functions that can help me to get function call depth?

Salem
06-27-2012, 03:56 AM
You need to declare two functions (perhaps in a separate source file compiled WITHOUT -ee and -ep flags) as follows.


static int callLevel = 0;
void __EPI ( const char *funcname ) {
callLevel++;
// somehow log the fact that funcname was called
}
void __PRO ( const char *funcname ) {
callLevel--;
}

NOTE!!!!!
I've guessed that each function receives a single char* parameter. This is a GUESS, you need to find out what parameter(s) it actually receives.

Add the resulting object file to the link when compiling with -ee/-ep flags.

It's like doing this in your code, except with some support from the compiler


void foo ( ) {
__EPI("foo"); // compiler adds this with the -ee flag
// do stuff
__PRO("foo"); // compiler adds this with the -ep flag
}

without having to go through and manually edit all the code.

steph
06-27-2012, 04:12 AM
One of the reasons - it mustn't be done manualy. It's look like to have only position of function start, but not end of it, so i can put only in
start
__EPI("foo");
void foo ( ) { __EPI("foo"); // compiler adds this with the -ee flag
// do stuff
if(suddenly)return 0;
__PRO("foo"); // compiler adds this with the -ep flag
}
In this part foo __PRO will be never executed, and searching every exiting point is fail.

Salem
06-27-2012, 04:40 AM
The compiler will arrange for __PRO to be called however the function returns.

The manual approach has the problems you describe, which is why it's only done as a last resort when the compiler has no support at all for any kind of profiling.

steph
06-27-2012, 04:57 AM
Ok, and what about "backtrace/stackWalk" in watcom (QNX)? With them it will be really simple to calculate function runtime depth.

Salem
06-27-2012, 05:42 AM
You will know all the function calls.
You should be able to reconstruct call depth and call graphs using that information.

steph
06-27-2012, 05:49 AM
How,what info ? I think I cant understand your point of view.

Salem
06-27-2012, 05:59 AM
Have you written a separate source file containing this


static int callLevel = 0;
void __EPI ( const char *funcname ) {
callLevel++;
// somehow log the fact that funcname was called
}
void __PRO ( const char *funcname ) {
callLevel--;
}
and managed to do a link WITHOUT getting undifined symbol __PRO,__EPI". ?

If not, you should practice that part of the exercise first.

> How,what info ?
By replacing "// somehow log the fact that funcname was called" in the above code with something which does what YOU want with regard to tracking function entry/exit.
All you have to do is think up what you need, then write the code to do it.

steph
06-27-2012, 06:15 AM
Still undifined symbol __EPI,even with extern and difinition.
I want to get function depth like,each time function called in thread:

main.1
d1 2
d2 3
d2 4