| Valgrind 3.3 - Advanced Debugging and Profiling for GNU/Linux applications by J. Seward, N. Nethercote, J. Weidendorfer and the Valgrind Development Team Paperback (6"x9"), 164 pages ISBN 0954612051 RRP £12.95 ($19.95) |
4.2.6 Limitations--original function signatures
As shown in the above example, to call the original you must use a macro of the form ‘CALL_FN_*’. For technical reasons it is impossible to create a single macro to deal with all argument types and numbers, so a family of macros covering the most common cases is supplied. In what follows, 'W' denotes a machine-word-typed value (a pointer or a C ‘long’), and 'v' denotes C's ‘void’ type. The currently available macros are:
- Macro: CALL_FN_v_v
- Call an original function of type
void fn (void).
- Macro: CALL_FN_W_v
- Call an original function of type
long fn (void).
- Macro: CALL_FN_v_W
- Call an original function of type
void fn (long).
- Macro: CALL_FN_W_W
- Call an original function of type
long fn (long).
- Macro: CALL_FN_v_WW
- Call an original function of type
void fn (long, long).
- Macro: CALL_FN_W_WW
- Call an original function of type
long fn (long, long).
- Macro: CALL_FN_v_WWW
- Call an original function of type
void fn (long, long, long).
- Macro: CALL_FN_W_WWW
- Call an original function of type
long fn (long, long, long).
- Macro: CALL_FN_W_WWWW
- Call an original function of type
long fn (long, long, long, long).
- Macro: CALL_FN_W_5W
- Call an original function of type
long fn (long, long, long, long, long).
- Macro: CALL_FN_W_6W
- Call an original function of type
long fn (long, long, long, long, long, long).
CALL_FN_W_12W
The set of supported types can be expanded as needed. It is regrettable that this limitation exists. Function wrapping has proven difficult to implement, with a certain apparently unavoidable level of ickyness. After several implementation attempts, the present arrangement appears to be the least-worst tradeoff. At least it works reliably in the presence of dynamic linking and dynamic code loading/unloading.
You should not attempt to wrap a function of one type signature with a wrapper of a different type signature. Such trickery will surely lead to crashes or strange behaviour. This is not of course a limitation of the function wrapping implementation, merely a reflection of the fact that it gives you sweeping powers to shoot yourself in the foot if you are not careful. Imagine the instant havoc you could wreak by writing a wrapper which matched any function name in any soname--in effect, one which claimed to be a wrapper for all functions in the process.
| ISBN 0954612051 | Valgrind 3.3 - Advanced Debugging and Profiling for GNU/Linux applications | See the print edition |