summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjistone <jistone>2006-01-16 23:40:50 +0000
committerjistone <jistone>2006-01-16 23:40:50 +0000
commit45c2b487202a3455db7cc86f108bfe2fe54677ef (patch)
treece7eea7a4fbb27cd347bb03e8e3312be26207ba8
parentf903d01cf2ace79ec2f9a046e8072d0095b4928b (diff)
downloadsystemtap-steved-45c2b487202a3455db7cc86f108bfe2fe54677ef.tar.gz
systemtap-steved-45c2b487202a3455db7cc86f108bfe2fe54677ef.tar.xz
systemtap-steved-45c2b487202a3455db7cc86f108bfe2fe54677ef.zip
2006-01-16 Josh Stone <joshua.i.stone@intel.com>
PR 2140 * translate.cxx (mapvar::del): Add ability to delete an indexed stat from (p)maps. (delete_statement_operand_visitor::visit_symbol): Add ability to delete entire pmaps and scalars. (delete_statement_operand_tmp_visitor): Add a special tmpvar visitor to parallel delete_statement_operand_visitor. (c_tmpcounter::visit_delete_statement): Invoke the new visitor. * testsuite/buildok/delete.stp: Also test scalar deletes. * vim/syntax/stap.vim: Recognize 'delete' operator. 2006-01-16 Josh Stone <joshua.i.stone@intel.com> * stat.c (_stp_stat_clear): add a function that just clears a Stat, so we can use delete in the translator.
-rw-r--r--ChangeLog13
-rw-r--r--runtime/ChangeLog5
-rw-r--r--runtime/stat.c17
-rwxr-xr-xtestsuite/buildok/delete.stp11
-rw-r--r--translate.cxx91
-rw-r--r--vim/syntax/stap.vim2
6 files changed, 121 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 2410547b..f9daa241 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-01-16 Josh Stone <joshua.i.stone@intel.com>
+
+ PR 2140
+ * translate.cxx (mapvar::del): Add ability to delete an indexed stat
+ from (p)maps.
+ (delete_statement_operand_visitor::visit_symbol): Add ability to
+ delete entire pmaps and scalars.
+ (delete_statement_operand_tmp_visitor): Add a special tmpvar visitor
+ to parallel delete_statement_operand_visitor.
+ (c_tmpcounter::visit_delete_statement): Invoke the new visitor.
+ * testsuite/buildok/delete.stp: Also test scalar deletes.
+ * vim/syntax/stap.vim: Recognize 'delete' operator.
+
2006-01-15 Frank Ch. Eigler <fche@elastic.org>
PR 2148
diff --git a/runtime/ChangeLog b/runtime/ChangeLog
index 159bb484..099949bf 100644
--- a/runtime/ChangeLog
+++ b/runtime/ChangeLog
@@ -1,3 +1,8 @@
+2006-01-16 Josh Stone <joshua.i.stone@intel.com>
+
+ * stat.c (_stp_stat_clear): add a function that just
+ clears a Stat, so we can use delete in the translator.
+
2006-01-16 Martin Hunt <hunt@redhat.com>
* map.c (_stp_pmap_agg): Return NULL when aggregation
diff --git a/runtime/stat.c b/runtime/stat.c
index c759a043..29dcef9b 100644
--- a/runtime/stat.c
+++ b/runtime/stat.c
@@ -1,6 +1,7 @@
/* -*- linux-c -*-
* Statistics Aggregation
* Copyright (C) 2005 Red Hat Inc.
+ * Copyright (C) 2006 Intel Corporation
*
* This file is part of systemtap, and is free software. You can
* redistribute it and/or modify it under the terms of the GNU General
@@ -270,6 +271,22 @@ void _stp_stat_print (Stat st, char *fmt, int clear)
__stp_stat_print (fmt, st, agg, 0);
STAT_UNLOCK(agg);
}
+
+/** Clear Stats.
+ * Clears the Stats.
+ *
+ * @param st Stat
+ */
+void _stp_stat_clear (Stat st)
+{
+ int i;
+ for_each_cpu(i) {
+ stat *sd = per_cpu_ptr (st->sd, i);
+ STAT_LOCK(sd);
+ _stp_stat_clear_data (st, sd);
+ STAT_UNLOCK(sd);
+ }
+}
/** @} */
#endif /* _STAT_C_ */
diff --git a/testsuite/buildok/delete.stp b/testsuite/buildok/delete.stp
index 20ad109a..52b3936d 100755
--- a/testsuite/buildok/delete.stp
+++ b/testsuite/buildok/delete.stp
@@ -1,20 +1,17 @@
#! stap -p4
#
# Make sure that 'delete' works in all variations.
-#
-# NOTE: It hasn't been decided yet whether 'delete' should work on scalar
-# numbers and strings, so for now those are commented out.
global a, b, c, d, e, f
probe begin {
- a = 1; #delete a;
- b = "b"; #delete b;
+ a = 1; delete a;
+ b = "b"; delete b;
c <<< 1; delete c;
d[1] = 1; delete d[1]; delete d;
e[1] = "e"; delete e[1]; delete e;
f[1] <<< 1; delete f[1]; delete f;
- x = 1; #delete x;
- y = "y"; #delete y;
+ x = 1; delete x;
+ y = "y"; delete y;
}
diff --git a/translate.cxx b/translate.cxx
index 2b0e44fa..094262f3 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -185,7 +185,7 @@ struct c_tmpcounter:
void visit_for_loop (for_loop* s);
void visit_foreach_loop (foreach_loop* s);
// void visit_return_statement (return_statement* s);
- // void visit_delete_statement (delete_statement* s);
+ void visit_delete_statement (delete_statement* s);
void visit_binary_expression (binary_expression* e);
// void visit_unary_expression (unary_expression* e);
void visit_pre_crement (pre_crement* e);
@@ -610,7 +610,7 @@ struct mapvar
{
if (type() == pe_string)
return (call_prefix("set", indices) + ", NULL)");
- else if (type() == pe_long)
+ else if ((type() == pe_long) || (type() == pe_stats))
return (call_prefix("set", indices) + ", 0)");
else
throw semantic_error("setting a value of an unsupported map type");
@@ -2135,6 +2135,18 @@ c_unparser::visit_next_statement (next_statement* s)
}
+struct delete_statement_operand_tmp_visitor:
+ public traversing_visitor
+{
+ c_tmpcounter *parent;
+ delete_statement_operand_tmp_visitor (c_tmpcounter *p):
+ parent (p)
+ {}
+ //void visit_symbol (symbol* e);
+ void visit_arrayindex (arrayindex* e);
+};
+
+
struct delete_statement_operand_visitor:
public throwing_visitor
{
@@ -2150,14 +2162,65 @@ struct delete_statement_operand_visitor:
void
delete_statement_operand_visitor::visit_symbol (symbol* e)
{
- mapvar mvar = parent->getmap(e->referent, e->tok);
- varlock_w guard (*parent, mvar);
- /* NB: such memory deallocation/allocation operations
- are not generally legal in all probe contexts.
- parent->o->newline() << mvar.fini ();
- parent->o->newline() << mvar.init ();
- */
- parent->o->newline() << "_stp_map_clear (" << mvar.qname() << ");";
+ if (e->referent->arity > 0)
+ {
+ mapvar mvar = parent->getmap(e->referent, e->tok);
+ varlock_w guard (*parent, mvar);
+ /* NB: such memory deallocation/allocation operations
+ are not generally legal in all probe contexts.
+ parent->o->newline() << mvar.fini ();
+ parent->o->newline() << mvar.init ();
+ */
+ if (mvar.is_parallel())
+ parent->o->newline() << "_stp_pmap_clear (" << mvar.qname() << ");";
+ else
+ parent->o->newline() << "_stp_map_clear (" << mvar.qname() << ");";
+ }
+ else
+ {
+ var v = parent->getvar(e->referent, e->tok);
+ varlock_w guard (*parent, v);
+ switch (e->type)
+ {
+ case pe_stats:
+ parent->o->newline() << "_stp_stat_clear (" << v.qname() << ");";
+ break;
+ case pe_long:
+ parent->o->newline() << v.qname() << " = 0;";
+ break;
+ case pe_string:
+ parent->o->newline() << v.qname() << "[0] = '\\0';";
+ break;
+ case pe_unknown:
+ default:
+ throw semantic_error("Cannot delete unknown expression type", e->tok);
+ }
+ }
+}
+
+void
+delete_statement_operand_tmp_visitor::visit_arrayindex (arrayindex* e)
+{
+ symbol *array;
+ hist_op *hist;
+ classify_indexable (e->base, array, hist);
+
+ if (array)
+ {
+ vardecl* r = array->referent;
+
+ // One temporary per index dimension.
+ for (unsigned i=0; i<r->index_types.size(); i++)
+ {
+ tmpvar ix = parent->parent->gensym (r->index_types[i]);
+ ix.declare (*(parent->parent));
+ e->indexes[i]->visit(parent);
+ }
+ }
+ else
+ {
+ throw semantic_error("cannot delete histogram bucket entries\n", e->tok);
+ }
}
void
@@ -2186,6 +2249,14 @@ delete_statement_operand_visitor::visit_arrayindex (arrayindex* e)
void
+c_tmpcounter::visit_delete_statement (delete_statement* s)
+{
+ delete_statement_operand_tmp_visitor dv (this);
+ s->value->visit (&dv);
+}
+
+
+void
c_unparser::visit_delete_statement (delete_statement* s)
{
visit_statement (s, 1);
diff --git a/vim/syntax/stap.vim b/vim/syntax/stap.vim
index 39947179..86c7d260 100644
--- a/vim/syntax/stap.vim
+++ b/vim/syntax/stap.vim
@@ -11,7 +11,7 @@ elseif exists("b:current_syntax")
finish
endif
-syn keyword stapStatement contained break continue return next containedin=stapBlock
+syn keyword stapStatement contained break continue return next delete containedin=stapBlock
syn keyword stapRepeat contained while for foreach in containedin=stapBlock
syn keyword stapConditional contained if else containedin=stapBlock
syn keyword stapDeclaration global probe function