C++ and gather-detailed-mem-stats

Michael Matz matz@suse.de
Mon Aug 27 15:36:00 GMT 2012


On Fri, 24 Aug 2012, Diego Novillo wrote:

> > void foo (int bar) __attribute__((add_location_pack));
> > 
> > that directs GNU C++ to add a __Gcc_call_location_pack typed
> > argument at each call site (properly constructed of course)?
> I really like this idea.
> Couldn't we make it even more transparent?  If a function is marked with 
> __attribute__((add_location_pack)) (or some other attribute name), the 
> callers will always pass file, function and line as hidden arguments (in 
> the same way that 'this' is passed as a hidden argument).

Note that this is only half of the fix.  You also need a way to pass a 
given pack transparently to a callee, like in this situation:

void real_worker (int arg, location_pack *p);
void wrapme (location_pack *p)
  real_worker (1, p);

The location passed to the call of real_worker should be the one of the 
call to wrapme, not the call _in_ wrapme.  I.e. the same distinction that 
right now is served by MEM_STAT_INFO vs. PASS_MEM_STAT.

This distinction needs to be doable per call, e.g. if there are other 
functions that call real_worker that do want to pass the location of that 
call and not of their own callers:

void this_is_not_just_a_wrapper (location_pack *p)
  if (condition)
    real_worker (1 THIS_LOCATION);
    real_worker (2 THIS_LOCATION);
  add_stats_for_me (p);

There are a few obvious ways how to make this distinction with various 
levels of ease of use.  E.g. function that need such location_pack could 
just be marked with the attribute (adding a new argument), i.e. as 
Richards suggestion, and the callers decide what should be passed, namely
__builtin_location (the location pack of the current source position where 
that token is mentioned), or __builtin_caller_location.  The latter would 
be usable only in functions marked as __attribute__((add_location_pack)), 
and would return the passed location pack, not the current source 


More information about the Gcc mailing list