Bug 5634 - support pointer type punning
: support pointer type punning
Status: RESOLVED FIXED
Product: systemtap
Classification: Unclassified
Component: translator
: unspecified
: P2 normal
: ---
Assigned To: Josh Stone
:
:
:
:
  Show dependency treegraph
 
Reported: 2008-01-17 18:31 UTC by Frank Ch. Eigler
Modified: 2009-02-19 21:42 UTC (History)
4 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 Frank Ch. Eigler 2008-01-17 18:31:30 UTC
It would be helpful to have a syntax for pointer type casting,
for times when the static type of the pointer does not match
the dynamic (actual) type.  Currently, this requires embedded-C
code to get around.

Perhaps like this:
    $ptr("struct tcp_socket")->tcp_socket_field

A more C-like syntax would be:
 ((struct tcp_socket*)$ptr)->tcp_socket_field
but parsing that is much more complicated.
Comment 1 Jim Keniston 2008-03-11 18:34:28 UTC
Yes, this would be very useful, whatever the syntax.

In the example given, the pointer is a target variable ($ptr), but it seems
important to be able to cast script variables as well.
Comment 2 Masami Hiramatsu 2008-05-19 21:19:38 UTC
Can this support casting to an array like below?

((struct tcp_socket[])$ptr)[1]->tcp_socket_field

or 

$ptr("struct tcp_socket []")[0]->tcp_socket_field
Comment 3 Frank Ch. Eigler 2008-06-27 20:51:27 UTC
*** Bug 6704 has been marked as a duplicate of this bug. ***
Comment 4 Josh Stone 2009-01-30 20:27:23 UTC
The '$ptr("type")' looks too similar functions calls, especially if we allow
script variables or expressions for the pointer source, and parsing a C-like
cast just scares me.

I was thinking of instead making the cast a builtin function, either a C++-like
'cast<struct tcp_socket *>($ptr)' or a simple 'cast("struct tcp_socket *",
$ptr)'.  The latter is slightly preferred because it wouldn't change our
tokenization.  Thoughts?
Comment 5 Frank Ch. Eigler 2009-01-30 20:35:25 UTC
You might like the @cast() syntax suggested in bug #6704.
Comment 6 Josh Stone 2009-02-19 02:54:18 UTC
I've added typecasting in commit 23ad66b, which I think will be enough for most
use cases.

(In reply to comment #2)
> Can this support casting to an array like below?

I did not add such support, but if it's enabled for #4166, then it should work
for this @cast too.
Comment 7 Josh Stone 2009-02-19 21:42:36 UTC
Release 0.9 includes @cast() support.