#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0

    Wrapping function calls using Diab compiler


    I know that gcc has a --wrap option for wrapping function calls, I would like to do a similar wrapping using Wind River Diab compiler, any ideas how to do this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    I think you should take this one up with the Wind River support folks. I am unaware of an equivalent in Diab to the --wrap facility in gcc, but it's been almost a decade since I have used Diab for any development. If I recall correctly, we did have access to a good bit of the C run-time sources for our target architecture and made on or two modifications therein.

    Another approach would be to use the system debug facilities to break-in whenever those functions were called and redirect execution to your own functions. You can use the symbol table generated by the linker to add break-point instructions at the desired locations. Hmm... for that matter you could just change the target address to call into your code first.

    Are you using an embedded OS?
    I no longer wish to be associated with this site.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by jwdonahue
    I think you should take this one up with the Wind River support folks. I am unaware of an equivalent in Diab to the --wrap facility in gcc, but it's been almost a decade since I have used Diab for any development. If I recall correctly, we did have access to a good bit of the C run-time sources for our target architecture and made on or two modifications therein.

    Another approach would be to use the system debug facilities to break-in whenever those functions were called and redirect execution to your own functions. You can use the symbol table generated by the linker to add break-point instructions at the desired locations. Hmm... for that matter you could just change the target address to call into your code first.

    Are you using an embedded OS?
    I am running on Windows, but the target system is PowerPC architecture, I don't have source code access,I just have the libraries and header files which are compiled using Diab to get the final ELF file, can you enlighten me more about your alternatives, or direct me to sources where I can read about and perform such stuff?

    Thanks
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    Have you got an OS on the target?
    I no longer wish to be associated with this site.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by jwdonahue
    Have you got an OS on the target?
    Yes my target operating system is OSEK compliant OS.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    I have no idea what OSEK is and no time to look it up. Assuming it's a reasonably complete operating system, it should provide debugging and image loading support. On some OS's you can load executable code into memory, modify it and then jump into the start address of the program. Some operating systems support configuring a debugger to always load a specified executable image and you can supply the debugger that does the loading or you can use the system debugger and supply it with a script to set break-points and actions for specific addresses in the image.

    On PPC the break-point instruction will fit in the same space or less than any of the the other supported op-codes. Replace all call instructions to the functions you want to wrap with a break-point instruction and supply a break-point handler. Your handler will be invoked with the address of the break point, use that address to lookup the function it replaced and call into whatever code you want to execute, then call the original function.
    I no longer wish to be associated with this site.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    Oh, I forgot add that you can also replace the target address supplied to the call instruction with the address of the function you want to run before calling the "wrapped" function.

    Note that for the options I have presented you'll have to have a pretty good understanding of the ABI for your processor. If you don't know what an ABI is, you might find this approach to be a bit of a challenge. There are folks around here who can assist you when you get into trouble (and you probably will), but it's something that very few people do on a daily basis and usually requires extra time and focus on your problem, so you probably won't get a lot of fast answers to issues. You'll definitely have to demonstrate a high degree of motivation to help yourself and formulate good questions to get the help you need.

    What did the Diab folks have to say?

    Having said that, and just in case you haven't already looked it up:
    http://en.wikipedia.org/wiki/Applica...nary_Interface.
    I no longer wish to be associated with this site.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    Originally Posted by jwdonahue
    Oh, I forgot add that you can also replace the target address supplied to the call instruction with the address of the function you want to run before calling the "wrapped" function.

    Note that for the options I have presented you'll have to have a pretty good understanding of the ABI for your processor. If you don't know what an ABI is, you might find this approach to be a bit of a challenge. There are folks around here who can assist you when you get into trouble (and you probably will), but it's something that very few people do on a daily basis and usually requires extra time and focus on your problem, so you probably won't get a lot of fast answers to issues. You'll definitely have to demonstrate a high degree of motivation to help yourself and formulate good questions to get the help you need.

    What did the Diab folks have to say?

    Having said that, and just in case you haven't already looked it up:
    Hi thank you for the elaborate answer, I will surely put my efforts into your suggestions, I got reply from Diab that they don't support that feature, but they have taken steps to provide it in the future releases.

IMN logo majestic logo threadwatch logo seochat tools logo