Global constants
Mark McLoughlin
markmc@redhat.com
Mon Feb 13 17:39:00 GMT 2006
Hi,
Trying out systemtap, I found myself doing the likes of:
---
global O_CREAT
probe begin {
O_CREAT = 64
}
probe kernel.function ("sys_open") {
if ($flags & O_CREAT) {
printf ("foo\n");
}
}
---
Then I thought it might be handy to have these kind of globals defined
in the system tapsets so I patched stap with:
---
o->newline() << "static rwlock_t "
<< "global_" << c_varname (v->name) << "_lock;";
+ o->newline() << "#define global_"
+ << c_varname(v->name) << "_DEFINED 1";
---
and put the likes of this in the system tapsets:
---
global O_CREAT
function init_sys_open_flags () %{
#ifdef global_O_CREAT_DEFINED
global_O_CREAT = 64;
#endif
%}
probe begin {
init_sys_open_flags ();
}
---
But then I thought that perhaps support for global constants like this
in the language wouldn't be such a bad idea, so you could just do:
---
const O_CREAT = 64
probe kernel.function ("sys_open") {
if ($flags & O_CREAT) {
printf ("foo\n");
}
}
---
Attached is a patch which implements this. The patch still needs closer
review, a bit of tidying up, perhaps some more optimisations for
constants, test cases for it in the test suite etc. but it does
basically seem to work. I thought I'd send it here for comments before
finishing it off.
So, thoughts?
Thanks,
Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: systemtap-0.5.4-global-constants.patch
Type: text/x-patch
Size: 45568 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/systemtap/attachments/20060213/c6346a1f/attachment.bin>
More information about the Systemtap
mailing list