Bug 18191 - DWARF-based sizeof(), array_size(), typeof() operators
Summary: DWARF-based sizeof(), array_size(), typeof() operators
Status: NEW
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 enhancement
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-01 17:46 UTC by David Smith
Modified: 2015-04-01 22:48 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Smith 2015-04-01 17:46:43 UTC
As mentioned by Stephane Chazelas on the mailing list:

<https://sourceware.org/ml/systemtap/2015-q1/msg00236.html>

It might be nice to have DWARF-based sizeof(), array_size(), typeof() operators.
Comment 1 Stephane Chazelas 2015-04-01 22:39:15 UTC
[Thanks David]

I don't know about the other ones, but a DWARF-based sizeof() (at least for kernel symbols) should just be a matter of:

function sizeof:long (addr:long) %{ /* pure */ /* pragma:symbols */
  STAP_RETVALUE = -1;
  _stp_kallsyms_lookup(STAP_ARG_addr, (unsigned long*)&(STAP_RETVALUE), NULL, NULL, NULL);
%}

See http://stackoverflow.com/questions/29034267/get-size-of-target-array-in-systemtap for where the request is coming from.
Comment 2 Frank Ch. Eigler 2015-04-01 22:48:35 UTC
(In reply to Stephane Chazelas from comment #1)

> function sizeof:long (addr:long) %{ /* pure */ /* pragma:symbols */
>   STAP_RETVALUE = -1;
>   _stp_kallsyms_lookup(STAP_ARG_addr, (unsigned long*)&(STAP_RETVALUE),
> NULL, NULL, NULL);
> %}

Note that the above great start is not actually DWARF-based - it's just symbol-table based.  We might want to do a few things extra:

- rename to symsize (since that's what it does)

- throw an error if the address can't be resolved to a known symbol, instead of returning a sentinel -1

- having a user-space variant usymsize() that passes 'current' as the last parameter to the underlying lookup function