summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS13
-rw-r--r--elaborate.cxx20
-rw-r--r--elaborate.h2
-rwxr-xr-xtestsuite/systemtap.examples/io/traceio2.stp2
-rwxr-xr-xtestsuite/systemtap.syscall/sys.stp10
5 files changed, 35 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index 9fe26ba6..2c7ca4a6 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,18 @@
* What's new
+- Systemtap now warns about global variables being referenced from other
+ script files. This aims to protect against unintended local-vs-global
+ namespace collisions such as:
+
+ % cat some_tapset.stp
+ probe baz.one = bar { foo = $foo; bar = $bar }
+ % cat end_user_script.stp
+ global foo # intended to be private variable
+ probe timer.s(1) { foo ++ }
+ probe baz.* { println(foo, pp()) }
+ % stap end_user_script.stp
+ WARNING: cross-file global variable reference to foo from some_tapset.stp
+
- Preprocessor conditional for kernel configuration testing:
%( CONFIG_foo == "y" %? ... %)
diff --git a/elaborate.cxx b/elaborate.cxx
index 2446e4f8..c3f29603 100644
--- a/elaborate.cxx
+++ b/elaborate.cxx
@@ -1711,7 +1711,7 @@ symresolution_info::visit_foreach_loop (foreach_loop* e)
{
if (!array->referent)
{
- vardecl* d = find_var (array->name, e->indexes.size ());
+ vardecl* d = find_var (array->name, e->indexes.size (), array->tok);
if (d)
array->referent = d;
else
@@ -1760,7 +1760,7 @@ delete_statement_symresolution_info:
if (e->referent)
return;
- vardecl* d = parent->find_var (e->name, -1);
+ vardecl* d = parent->find_var (e->name, -1, e->tok);
if (d)
e->referent = d;
else
@@ -1782,7 +1782,7 @@ symresolution_info::visit_symbol (symbol* e)
if (e->referent)
return;
- vardecl* d = find_var (e->name, 0);
+ vardecl* d = find_var (e->name, 0, e->tok);
if (d)
e->referent = d;
else
@@ -1818,7 +1818,7 @@ symresolution_info::visit_arrayindex (arrayindex* e)
if (array->referent)
return;
- vardecl* d = find_var (array->name, e->indexes.size ());
+ vardecl* d = find_var (array->name, e->indexes.size (), array->tok);
if (d)
array->referent = d;
else
@@ -1877,7 +1877,7 @@ symresolution_info::visit_functioncall (functioncall* e)
vardecl*
-symresolution_info::find_var (const string& name, int arity)
+symresolution_info::find_var (const string& name, int arity, const token* tok)
{
if (current_function || current_probe)
{
@@ -1912,6 +1912,16 @@ symresolution_info::find_var (const string& name, int arity)
&& session.globals[i]->compatible_arity(arity))
{
session.globals[i]->set_arity (arity);
+ if (! session.suppress_warnings)
+ {
+ vardecl* v = session.globals[i];
+ // clog << "resolved " << *tok << " to global " << *v->tok << endl;
+ if (v->tok->location.file != tok->location.file)
+ {
+ session.print_warning ("cross-file global variable reference to " + lex_cast (*v->tok) + " from",
+ tok);
+ }
+ }
return session.globals[i];
}
diff --git a/elaborate.h b/elaborate.h
index bee71a50..fec62d59 100644
--- a/elaborate.h
+++ b/elaborate.h
@@ -37,7 +37,7 @@ public:
derived_probe* current_probe;
symresolution_info (systemtap_session& s);
- vardecl* find_var (const std::string& name, int arity);
+ vardecl* find_var (const std::string& name, int arity, const token *tok);
functiondecl* find_function (const std::string& name, unsigned arity);
void visit_block (block *s);
diff --git a/testsuite/systemtap.examples/io/traceio2.stp b/testsuite/systemtap.examples/io/traceio2.stp
index 1abea45d..797f3062 100755
--- a/testsuite/systemtap.examples/io/traceio2.stp
+++ b/testsuite/systemtap.examples/io/traceio2.stp
@@ -1,6 +1,6 @@
#! /usr/bin/env stap
-global device_of_interest, dev
+global device_of_interest
probe begin {
/* The following is not the most efficient way to do this.
diff --git a/testsuite/systemtap.syscall/sys.stp b/testsuite/systemtap.syscall/sys.stp
index e3564a15..79c7ff57 100755
--- a/testsuite/systemtap.syscall/sys.stp
+++ b/testsuite/systemtap.syscall/sys.stp
@@ -1,4 +1,4 @@
-global indent, indent_str, entry
+global indent, indent_str, entry_p
probe begin {
indent = 0
@@ -13,22 +13,22 @@ probe begin {
probe syscall.* ? {
if (pid() == target()) {
- if (entry) printf("\n")
+ if (entry_p) printf("\n")
printf("%s%s: %s (%s) = ", indent_str[indent], execname(), name, argstr)
# printf("%s%s: %s (%s) = ", indent_str[indent], execname(), probefunc(), argstr)
indent++
- entry = 1
+ entry_p = 1
}
}
probe syscall.*.return ? {
if (pid() == target()) {
if (indent) indent--
- if (entry)
+ if (entry_p)
printf("%s\n", retstr)
else
printf("%s%s\n", indent_str[indent],retstr)
- entry = 0
+ entry_p = 0
}
}