This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] give alternates for read only variable warning


-> nl -ba /work/scox/systemtap/src/testsuite/systemtap.base/warnings.stp
     1  # PR 1119
     2
     3  global elide_me1
     4  function elide_me2 () {}
     5  function foo:long () { elide_me3 = 1 }
     6  function bar() { print(elide+me1) ; ; ; }
     7  probe never { elide_me4 = 1; (elide_me5+5); print (foo()) }
     8  probe never { print(elide+me1) bar () }
     9
    10  # PR 6611
    11
    12  probe probea = kernel.statement("bio_init@fs/bio.c:135")
    13                 { printf("%d", funca(2)); elide_me6="foo" }
    14  probe probea { printf("%d", funcb(2,3)); printf("%s",var) }
    15
    16  function funcb(a:long, b:long) {return a + b}
    17  function funca(a:long) {a=b; elide_me7=1; return a}

-> stap -p2 /work/scox/stap/6611.stp
WARNING: eliding unused function identifier 'elide_me2'
at /work/scox/stap/6611.stp:4:10
WARNING: read-only local variable identifier 'elide_me5'
at /work/scox/stap/6611.stp:7:31
         (alternatives: elide_me4 elide_me1)
WARNING: read-only local variable identifier 'elide'
at /work/scox/stap/6611.stp:8:21
         (alternatives: me1 elide_me1)
WARNING: read-only local variable identifier 'me1'
at /work/scox/stap/6611.stp:8:27
         (alternatives: elide elide_me1)
WARNING: read-only local variable identifier 'var'
at /work/scox/stap/6611.stp:14:54
         (alternatives: elide_me6 elide_me1)
WARNING: read-only local variable identifier 'elide'
at /work/scox/stap/6611.stp:6:24
         (alternatives: me1 elide_me1)
WARNING: read-only local variable identifier 'me1'
at /work/scox/stap/6611.stp:6:30
         (alternatives: elide elide_me1)
WARNING: read-only local variable identifier 'b'
at /work/scox/stap/6611.stp:17:27
         (alternatives: a elide_me7 elide_me1)
WARNING: eliding unused variable identifier 'elide_me1'
at /work/scox/stap/6611.stp:3:8
WARNING: side-effect-free function 'foo' identifier 'foo'
at /work/scox/stap/6611.stp:5:10
WARNING: eliding unused variable identifier 'elide_me4'
at /work/scox/stap/6611.stp:7:15
WARNING: eliding unused variable identifier 'elide_me5'
at /work/scox/stap/6611.stp:7:31
WARNING: eliding unused variable identifier 'elide_me6'
at /work/scox/stap/6611.stp:13:42
WARNING: eliding unused variable identifier 'elide_me3'
at /work/scox/stap/6611.stp:5:24
WARNING: eliding unused variable identifier 'elide_me7'
at /work/scox/stap/6611.stp:17:30

/work/scox/systemtap/src /work/scox/systemtap/bld/x86_64-redhat-linux ~
diff --git a/ChangeLog b/ChangeLog
index 0a0b9ab..4b323b7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,15 @@
+2008-06-13  Stan Cox  <scox@redhat.com>
+
+	* elaborate.cxx (print_warning): Return "warning was printed" status.
+	(semantic_pass_opt2): List variable alternatives for probes and
+	functions.
+	* session.h (print_warning): Return "warning was printed" status.
+
 2008-06-11  Mark Wielaard  <mwielaard@redhat.com>
 
 	* elaborate.cxx (print_warning): Only output WARNING, don't put it
 	in the message_str and seen_warnings.
-	* session.h (print_waring): Reindent.
+	* session.h (print_warning): Reindent.
 
 2008-06-11  Frank Ch. Eigler  <fche@elastic.org>
 
diff --git a/elaborate.cxx b/elaborate.cxx
index d0665c9..f8197ca 100644
--- a/elaborate.cxx
+++ b/elaborate.cxx
@@ -1228,7 +1228,7 @@ systemtap_session::print_error (const semantic_error& e)
     print_error (* e.chain);
 }
 
-void
+bool
 systemtap_session::print_warning (string message_str)
 {
   // Duplicate elimination
@@ -1236,7 +1236,9 @@ systemtap_session::print_warning (string message_str)
     {
       seen_warnings.insert (message_str);
       clog << "WARNING: " << message_str << endl;
+      return true;
     }
+  return false;
 }
 
 
@@ -1612,7 +1614,7 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p)
   
   // Now in vut.read/written, we have a mixture of all locals, globals
   
-  for (unsigned i=0; i<s.probes.size(); i++)
+  for (unsigned i=0; i<s.probes.size(); i++) 
     for (unsigned j=0; j<s.probes[i]->locals.size(); /* see below */)
       {
         vardecl* l = s.probes[i]->locals[j];
@@ -1638,11 +1640,26 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p)
           {
             if (vut.written.find (l) == vut.written.end())
               if (! s.suppress_warnings)
-		s.print_warning ("read-only local variable " + stringify(*l->tok));
-
+		  {
+		    stringstream o;
+		    vector<vardecl*>::iterator it;
+		    for ( it = s.probes[i]->locals.begin() ;
+			  it != s.probes[i]->locals.end(); it++ )
+		      if (l->name.compare(((vardecl*)*it)->name) != 0)
+			o << " " <<  ((vardecl*)*it)->name;
+		    for ( it = s.globals.begin() ;
+			  it != s.globals.end() ; it++ )
+		      if (l->name.compare(((vardecl*)*it)->name) != 0)
+			o << " " <<  ((vardecl*)*it)->name;
+
+		    if (s.print_warning ("read-only local variable " + stringify(*l->tok)))
+			clog << "         (alternatives:" + o.str () + ")" << endl;
+		  }
+	    
             j++;
           }
       }
+  
   for (unsigned i=0; i<s.functions.size(); i++)
     for (unsigned j=0; j<s.functions[i]->locals.size(); /* see below */)
       {
@@ -1667,9 +1684,26 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p)
           }
         else
           {
+	    stringstream o;
+	    vector<vardecl*>::iterator it;
+	    for ( it = s.functions[i]->formal_args.begin() ;
+		  it != s.functions[i]->formal_args.end(); it++ )
+	      if (l->name.compare(((vardecl*)*it)->name) != 0)
+		o << " " <<  ((vardecl*)*it)->name;
+	    for ( it = s.functions[i]->locals.begin() ;
+		  it != s.functions[i]->locals.end(); it++ )
+	      if (l->name.compare(((vardecl*)*it)->name) != 0)
+		o << " " <<  ((vardecl*)*it)->name;
+	    for ( it = s.globals.begin() ;
+		  it != s.globals.end() ; it++ )
+	      if (l->name.compare(((vardecl*)*it)->name) != 0)
+		o << " " <<  ((vardecl*)*it)->name;
+
             if (vut.written.find (l) == vut.written.end())
               if (! s.suppress_warnings)
-                s.print_warning ("read-only local variable " + stringify(*l->tok));
+                if (s.print_warning ("read-only local variable " + stringify(*l->tok)))
+		  clog << "         (alternatives:" + o.str () + ")" << endl;
+		  
             j++;
           }
       }
diff --git a/session.h b/session.h
index ba94514..4b4c31b 100644
--- a/session.h
+++ b/session.h
@@ -167,7 +167,7 @@ struct systemtap_session
   unsigned num_errors () { return seen_errors.size(); }
   // void print_error (const parse_error& e);
   void print_error (const semantic_error& e);
-  void print_warning (std::string w);
+  bool print_warning (std::string w);
 
   // reNB: new POD members likely need to be explicitly cleared in the ctor.
 };

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]