https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106018
Bug ID: 106018 Summary: Feature Request: Add function attribute fn_enter, and fn_exit Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: alan.rosenthal at gmail dot com Target Milestone: --- Add a function attributes: fn_enter and fn_exit to auto generate functions that are called before a function starts and after a function ends. This function: char myfn(int param1, bool pararm2, void* param3) __attribute__ ((fn_enter, fn_exit)) { if (param1) { return '0'; } if (param2) { return '1'; } char ret = (char) param3; return ret; } Would generated these two functions: void __enter_myfn(int param1, bool pararm2, void* param3); void __exit_myfn(char ret); These functions would be called during normal enter/exit conditions, i.e.: char myfn(int param1, bool pararm2, void* param3) __attribute__ ((fn_enter, fn_exit)) { __enter_myfn(param1, param2, param3); if (param1) { __exit_fn('0'); return '0'; } if (param2) { __exit_fn('1'); return '1'; } char ret = (char) param3; __exit_fn(ret); return ret; } This would allow a developer to easily add diagnostics to a specific function to get a better sense of how often it was called, with what arguments, and what the return value were. Similarly functionality exists in -finstrument-functions, but it doesn't provide a way to capture function parameters or return values.