Watcom __PRO,__EPI and program profile

This is a discussion on Watcom __PRO,__EPI and program profile within the Linux Programming forums, part of the Platform Specific Boards category; Hello. I'm trying to get program call tree for code analys (something like): main ---> func1 ---------> func2 ---> func3 ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    5

    Watcom __PRO,__EPI and program profile

    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?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    You need to declare two functions (perhaps in a separate source file compiled WITHOUT -ee and -ep flags) as follows.
    Code:
    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
    Code:
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    5
    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
    Code:
    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.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    5
    Ok, and what about "backtrace/stackWalk" in watcom (QNX)? With them it will be really simple to calculate function runtime depth.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    You will know all the function calls.
    You should be able to reconstruct call depth and call graphs using that information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jun 2012
    Posts
    5
    How,what info ? I think I cant understand your point of view.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    Have you written a separate source file containing this
    Code:
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Jun 2012
    Posts
    5
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 06-03-2007, 02:35 AM
  2. DLL linking in Watcom
    By Rutabega in forum Windows Programming
    Replies: 3
    Last Post: 11-21-2006, 09:12 AM
  3. WATCOM; Graphics Lib Problems
    By cboard_member in forum Game Programming
    Replies: 6
    Last Post: 12-16-2005, 02:17 AM
  4. Open Watcom C/C++....
    By Nitrous in forum C++ Programming
    Replies: 5
    Last Post: 07-29-2003, 12:34 PM
  5. Watcom C++ inline assembler
    By r0x in forum C++ Programming
    Replies: 0
    Last Post: 06-03-2002, 11:21 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21