This is the mail archive of the
mailing list for the GCC project.
Re: C++ and gather-detailed-mem-stats
Would it be possible to define a new function
attribute that transparently adds two parameters
for file name and line number? Or that etablishes
a binding between this information and existing
parameter names? This might be useful for regular
"C" programs as well.
void do_something (T1 t1, T2 t2)
__attribute ((caller_info (func => __FUNC__,
file => __FILE__,
line => __LINE__)));
Perhaps a compilation switch and a pre-defined macro
are necessary to meaningfully be able to code
the body of the function and/or to conditionally
enable the collection of the data.
The syntax above with the mix of parameter names
(but no types) and pre-defined macros may not make
sense, but perhaps the idea can be developed further
if there is interest.
Or maybe a builtin type?
void do_something (T1 t1, T2 t2,
const __builtin_caller_info_t * const caller_info)
This comes at the cost of an additional pointer argument
but it can be set to NULL if collection of caller info
is disabled. It can also be an opaque type established
via #define for configurations where either the compiler
doesn't support the feature or it is disabled. Otherwise,
__builtin_caller_info_t might have the obvious fields
(function_name, file_name, line_number).
Off-hand, I can see how to make this work OK with default
argument values and/or over-loading in C++, but some more
work would be involved (by the programmer) to make this
work for regular "C" programs.