Accessing size of arrays allocated on the stack

Frank Ch. Eigler fche@redhat.com
Wed Dec 12 23:19:00 GMT 2012


Hi, Alexander --

Alexander.Hoole wrote:

> I noticed that systemtap is able to know that a local variable, allocated on
> the stack, is an array.  [...]
> Does SystemTap presently support the ability to determine the size of local
> arrays using either built-in functionality or embedded C?

Not well.  There is a sizeof.stp sample, but that works for type names
that are resolvable via the @cast() construct, not general C type
declaration strings, and not references to a varable.  Via embedded-C
of course one can do anything one wants (return sizeof(some_c_type))
but that code doesn't have access to the DWARF data stap has
processed.

To get array bounds, stap would have to search for stuff like
DW_TAG_subrange_type -> DW_AT_upper_bound (which "extern array[];"
declarations won't have).  Stap would have to export this through
some new language feature, perhaps @byte_size($foo) (if one wants
all the array dimensions/element-sizes multiplied out).

- FChE



More information about the Systemtap mailing list