public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* Typed locals in functions and probes? Feasibility of language enhancement?
@ 2020-07-21  2:48 Craig Ringer
  2020-08-20 23:17 ` Frank Ch. Eigler
  0 siblings, 1 reply; 2+ messages in thread
From: Craig Ringer @ 2020-07-21  2:48 UTC (permalink / raw)
  To: systemtap

I find that I write things like this a lot:

if (foo && (@cast(foo)->bar)
    return @cast(foo)->bar->baz

Because systemtap type-erases locals to long or string, code for member
access gets repetitive fast. I can @define macros for shorthand, but that
only goes so far, and it obfuscates the code a bit.

Is there an accepted pattern for this that I'm missing?

If not, how feasible would it be to track inferred types for locals?
Definitely NOT for globals, just for locals within a function? Could it be
relatively low hanging fruit to implement this, something folks here might
be able to point me in the right direction for? Or is it a major language
change that's in the too hard basket?

-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 2ndQuadrant - PostgreSQL Solutions for the Enterprise

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Typed locals in functions and probes? Feasibility of language enhancement?
  2020-07-21  2:48 Typed locals in functions and probes? Feasibility of language enhancement? Craig Ringer
@ 2020-08-20 23:17 ` Frank Ch. Eigler
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Ch. Eigler @ 2020-08-20 23:17 UTC (permalink / raw)
  To: Craig Ringer; +Cc: systemtap


craig wrote:

> I find that I write things like this a lot:
>
> if (foo && (@cast(foo)->bar)
>     return @cast(foo)->bar->baz
>
> Because systemtap type-erases locals to long or string, code for member
> access gets repetitive fast. I can @define macros for shorthand, but that
> only goes so far, and it obfuscates the code a bit.
> Is there an accepted pattern for this that I'm missing?

Systemtap actually tries to associate some dwarf-based typing with local
variables.  For example, this works:

  probe kernel.function("work_busy") { f($work) }
  function f(w) { ww = & @cast(w,"work_struct");
                  println(ww->data->counter) }

This is due to the "auto-casting" facility added to systemtap
back in 2014.  I ... can't seem to find the facility actually
documented in the stap or stapprobes man page tho.  See this
bit of the systemtap 2.6 release notes:

https://sourceware.org/legacy-ml/systemtap/2014-q3/msg00231.html

We could probably start tracking these types across function call
parameter-passing boundaries also.  Via PR25841, functions called from a
probe handler also have some connection to the dwarf context.


- FChE


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-20 23:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21  2:48 Typed locals in functions and probes? Feasibility of language enhancement? Craig Ringer
2020-08-20 23:17 ` Frank Ch. Eigler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).