diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | elaborate.cxx | 32 | ||||
-rw-r--r-- | staptree.cxx | 33 | ||||
-rw-r--r-- | tapset/ChangeLog | 8 | ||||
-rw-r--r-- | tapset/signal.stp | 4 | ||||
-rw-r--r-- | tapset/syscalls2.stp | 2 | ||||
-rw-r--r-- | tapset/vfs.stp | 14 | ||||
-rw-r--r-- | tapset/x86_64/syscalls.stp | 2 | ||||
-rw-r--r-- | testsuite/ChangeLog | 7 | ||||
-rwxr-xr-x | testsuite/buildok/eleven.stp | 14 | ||||
-rw-r--r-- | testsuite/systemtap.base/warnings.exp | 2 | ||||
-rw-r--r-- | testsuite/systemtap.base/warnings.stp | 7 | ||||
-rw-r--r-- | testsuite/systemtap.examples/disktop.stp | 2 | ||||
-rwxr-xr-x | testsuite/transok/three.stp | 1 |
14 files changed, 105 insertions, 32 deletions
@@ -1,3 +1,12 @@ +2008-05-20 Frank Ch. Eigler <fche@elastic.org> + + PR 6538 + * elaborate.cxx (semantic_pass_opt2): Warn about read-only locals and + globals. + * staptree.cxx (varuse_collecting_visitor::visit_symbol): Recognize + initialized global as written-to. + (visit_foreach_loop): Belatedly recognize index symbols as lvalues. + 2008-05-20 Tim Moore <timoore@redhat.com> * configure.ac: Check for tr1/unordered_map header. diff --git a/elaborate.cxx b/elaborate.cxx index 4bc43832..f8bfabdb 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -1624,7 +1624,13 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p) // don't increment j } else - j++; + { + if (vut.written.find (l) == vut.written.end()) + if (! s.suppress_warnings) + clog << "WARNING: read-only local variable " << *l->tok << endl; + + j++; + } } for (unsigned i=0; i<s.functions.size(); i++) for (unsigned j=0; j<s.functions[i]->locals.size(); /* see below */) @@ -1649,7 +1655,12 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p) // don't increment j } else - j++; + { + if (vut.written.find (l) == vut.written.end()) + if (! s.suppress_warnings) + clog << "WARNING: read-only local variable " << *l->tok << endl; + j++; + } } for (unsigned i=0; i<s.globals.size(); /* see below */) { @@ -1671,7 +1682,12 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p) // don't increment i } else - i++; + { + if (vut.written.find (l) == vut.written.end()) + if (! s.suppress_warnings) + clog << "WARNING: read-only global variable " << *l->tok << endl; + i++; + } } } @@ -1834,6 +1850,8 @@ void semantic_pass_opt3 (systemtap_session& s, bool& relaxed_p) for (unsigned i=0; i<s.functions.size(); i++) s.functions[i]->body->visit (& dar); // The rewrite operation is performed within the visitor. + + // XXX: we could also zap write-only globals here } @@ -2057,6 +2075,8 @@ void semantic_pass_opt4 (systemtap_session& s, bool& relaxed_p) p->body = new null_statement(); p->body->tok = p->tok; + + // XXX: possible duplicate warnings; see below } } for (unsigned i=0; i<s.functions.size(); i++) @@ -2080,6 +2100,12 @@ void semantic_pass_opt4 (systemtap_session& s, bool& relaxed_p) fn->body = new null_statement(); fn->body->tok = fn->tok; + + // XXX: the next iteration of the outer optimization loop may + // take this new null_statement away again, and thus give us a + // fresh warning. It would be better if this fixup was performed + // only after the relaxation iterations. + // XXX: or else see bug #6469. } } } diff --git a/staptree.cxx b/staptree.cxx index 02a6c8dc..b5cbd5c9 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -1713,6 +1713,10 @@ varuse_collecting_visitor::visit_symbol (symbol *e) if (e->referent == 0) throw semantic_error ("symbol without referent", e->tok); + // handle initialized globals + if (e->referent->init) + written.insert (e->referent); + if (current_lvalue == e || current_lrvalue == e) { written.insert (e->referent); @@ -1789,10 +1793,19 @@ varuse_collecting_visitor::visit_post_crement (post_crement *e) void varuse_collecting_visitor::visit_foreach_loop (foreach_loop* s) { - functioncall_traversing_visitor::visit_foreach_loop (s); + // NB: we duplicate so don't bother call + // functioncall_traversing_visitor::visit_foreach_loop (s); + + symbol *array = NULL; + hist_op *hist = NULL; + classify_indexable (s->base, array, hist); + if (array) + array->visit(this); + else + hist->visit(this); + // If the collection is sorted, imply a "write" access to the - // array in addition to the "read" one already noted in the - // base class call above. + // array in addition to the "read" one already noted above. if (s->sort_direction) { symbol *array = NULL; @@ -1801,6 +1814,20 @@ varuse_collecting_visitor::visit_foreach_loop (foreach_loop* s) if (array) this->written.insert (array->referent); // XXX: Can hist_op iterations be sorted? } + + // NB: don't forget to visit the index expressions, which are lvalues. + for (unsigned i=0; i<s->indexes.size(); i++) + { + expression* last_lvalue = current_lvalue; + current_lvalue = s->indexes[i]; // leave a mark for ::visit_symbol + s->indexes[i]->visit (this); + current_lvalue = last_lvalue; + } + + if (s->limit) + s->limit->visit (this); + + s->block->visit (this); } diff --git a/tapset/ChangeLog b/tapset/ChangeLog index a0f14ded..3afc7aa3 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,11 @@ +2008-05-20 Frank Ch. Eigler <fche@elastic.org> + + PR 6538 + * signal.stp (_signal.send.part[23]): Initialize dummy sinfo. + * syscalls2.stp (syscall.compat_sys_semtimedop): Fix sops_uaddr. + * vfs.stp (__find_bdevname): Rewrite. + * x86_64/syscalls.stp (syscall.pipe32): Fix argstr. + 2008-05-20 Mark Wielaard <mwielaard@redhat.com> PR 5001 diff --git a/tapset/signal.stp b/tapset/signal.stp index ec947eb7..72ba9520 100644 --- a/tapset/signal.stp +++ b/tapset/signal.stp @@ -63,7 +63,7 @@ probe _signal.send.part2 = kernel.function("send_group_sigqueue") { name = "send_group_sigqueue" task = $p - # sinfo = $q->info + sinfo = 0 # $q->info shared = 1 send2queue = 1 } @@ -72,7 +72,7 @@ probe _signal.send.part3 = kernel.function("send_sigqueue") { name = "send_sigqueue" task = $p - # sinfo = $q->info + sinfo = 0 # $q->info shared = 0 send2queue = 1 } diff --git a/tapset/syscalls2.stp b/tapset/syscalls2.stp index 31e1830d..344396f4 100644 --- a/tapset/syscalls2.stp +++ b/tapset/syscalls2.stp @@ -1364,7 +1364,7 @@ probe syscall.semtimedop.return = kernel.function("sys_semtimedop").return ? { probe syscall.compat_sys_semtimedop = kernel.function("compat_sys_semtimedop") ? { name = "compat_sys_semtimedop" semid = $semid - sops_uaddr = tsems + sops_uaddr = $tsems nsops = $nsops timeout_uaddr = $timeout argstr = sprintf("%d, %p, %d, %s", $semid, $tsems, $nsops, diff --git a/tapset/vfs.stp b/tapset/vfs.stp index 75b1b279..6073dffc 100644 --- a/tapset/vfs.stp +++ b/tapset/vfs.stp @@ -33,16 +33,10 @@ function __bdevname:string (bdev:long) %{ /* pure */ global __devnames function __find_bdevname:string(dev:long, bdev:long) { -# return "" - - __devname = __devnames[dev] - - if (__devname != null) - return __devname - - __devname = __devnames[dev] = __bdevname(bdev) - - return __devname + if (dev in __devnames) + return __devnames[dev] + else + return __devnames[dev] = __bdevname(bdev) } function ppos_pos:long (ppos:long) %{ /* pure */ diff --git a/tapset/x86_64/syscalls.stp b/tapset/x86_64/syscalls.stp index 418aaf23..c9ab617f 100644 --- a/tapset/x86_64/syscalls.stp +++ b/tapset/x86_64/syscalls.stp @@ -131,7 +131,7 @@ probe syscall.vm86_warning.return = kernel.function("sys32_vm86_warning").return # probe syscall.pipe32 = kernel.function("sys32_pipe") { name = "pipe" - argstr = sprintf("%p", fd) + argstr = sprintf("%p", $fd) } probe syscall.pipe32.return = kernel.function("sys32_pipe").return { name = "pipe" diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 3c74b83d..80f2ae78 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2008-05-20 Frank Ch. Eigler <fche@elastic.org> + + PR 6538 + * systemtap.base/warnings.*: New tests. + * buildok/eleven.stp, systemtap.examples/disktop.stp, + transok/three.stp: Adapt to new warnings. + 2008-05-21 Mark Wielaard <mwielaard@redhat.com> * buildok/aux_syscalls-embedded.stp: Don't check _struct_utimbuf_u diff --git a/testsuite/buildok/eleven.stp b/testsuite/buildok/eleven.stp index 66d4a318..e6627fdc 100755 --- a/testsuite/buildok/eleven.stp +++ b/testsuite/buildok/eleven.stp @@ -3,15 +3,17 @@ probe begin { a = -1 / -1; - b = 2147483647; - c = 4294967295 / a; + b = 2147483647 + a; + c = 4294967295 / b; d = (-2147483647-1) % c; - e = 9223372036854775807 * b; - d /= b % e; - b %= 0 / f; - x = 1 / 0; + e = 9223372036854775807 * d; + f /= b % e; + g %= 0 / f; + h = 1 / 0; + println (h) } probe end { y %= 0; + println (y) } diff --git a/testsuite/systemtap.base/warnings.exp b/testsuite/systemtap.base/warnings.exp index 025bde89..6cff723d 100644 --- a/testsuite/systemtap.base/warnings.exp +++ b/testsuite/systemtap.base/warnings.exp @@ -9,7 +9,7 @@ expect { eof { } } wait -if {$ok == 9} { +if {$ok == 22} { pass $test } else { fail "$test ($ok)" diff --git a/testsuite/systemtap.base/warnings.stp b/testsuite/systemtap.base/warnings.stp index a0ce8d8d..a2ac5afc 100644 --- a/testsuite/systemtap.base/warnings.stp +++ b/testsuite/systemtap.base/warnings.stp @@ -1,9 +1,8 @@ -# PR 1119 +# PR 1119, 6538 global elide_me1 - function elide_me2 () {} - function foo:long () { elide_me3 = 1 } - +function bar() { print(elide+me1) ; ; ; } probe never { elide_me4 = 1; (elide_me5+5); print (foo()) } +probe never { print(elide+me1) bar () } diff --git a/testsuite/systemtap.examples/disktop.stp b/testsuite/systemtap.examples/disktop.stp index 24b1e331..2637d735 100644 --- a/testsuite/systemtap.examples/disktop.stp +++ b/testsuite/systemtap.examples/disktop.stp @@ -42,7 +42,7 @@ probe kernel.function("vfs_write").return { probe timer.ms(5000) { /* skip non-read/write disk */ - if (read_bytes+write+bytes) { + if (read_bytes+write_bytes) { printf("\n%-25s, %-8s%4dKb/sec, %-7s%6dKb, %-7s%6dKb\n\n",ctime(gettimeofday_s()),"Average:", ((read_bytes+write_bytes)/1024)/5,"Read:",read_bytes/1024,"Write:",write_bytes/1024) diff --git a/testsuite/transok/three.stp b/testsuite/transok/three.stp index 6e99b640..a7406db4 100755 --- a/testsuite/transok/three.stp +++ b/testsuite/transok/three.stp @@ -7,6 +7,7 @@ function f1 (a, b) { d = "hello"; # poo[c] = bab[d] = "hi" bab = "hi"; + poo [c+1] = c+2; bab = poo[c]; return 0 } |