Bug 11360 - Bad interaction between -L and @defined
Summary: Bad interaction between -L and @defined
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Josh Stone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-09 02:17 UTC by Josh Stone
Modified: 2010-03-09 23:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Josh Stone 2010-03-09 02:17:09 UTC
$ stap -l syscall.poll
syscall.poll

$ stap -L syscall.poll
semantic error: unable to find local 'timeout' near pc 0xffffffff8112ccab in
sys_poll(fs/select.c) (alternatives: ufds nfds timeout_msecs end_time to ret):
identifier '$timeout' at /usr/local/share/systemtap/tapset/syscalls2.stp:353:57
        source: 	timeout = (@defined($timeout_msecs) ? $timeout_msecs : $timeout)
                	                                                       ^
semantic error: unable to find local 'timeout' near pc 0xffffffff8112ccab in
sys_poll(fs/select.c) (alternatives: ufds nfds timeout_msecs end_time to ret):
identifier '$timeout' at :355:48
        source: 		(@defined($timeout_msecs) ? $timeout_msecs : $timeout))
                		                                             ^
semantic error: probe_1906 with unresolved type: identifier 'timeout' at :353:2
        source: 	timeout = (@defined($timeout_msecs) ? $timeout_msecs : $timeout)
                	^
semantic error: probe_1906 with unresolved type: identifier 'argstr' at :354:2
        source: 	argstr = sprintf("%p, %d, %d", $ufds, $nfds,
                	^
syscall.poll name:string ufds_uaddr:long nfds:long timeout:unknown
argstr:unknown $ufds:struct pollfd* $nfds:unsigned int $timeout_msecs:long int
[1]

(The [1] is my shell prompt reporting the non-zero exit code)

The problem stems from the option parser:

  case 'L':
    s.listing_mode_vars = true;
    s.unoptimized = true; // This causes retention of variables for listing_mode

Without optimization, expressions like the ternary "@defined(x)?x:y" won't strip
out whichever of x or y is invalid, and the type-resolution phase takes notice.
Comment 1 Josh Stone 2010-03-09 02:34:44 UTC
I think it may work to re-enable optimization, but skip the
dead_assignment_remover for listing_mode_vars.  Here is the short patch, but I'm
still testing to see if any vars disappear accidentally with other optimizations.

diff --git a/elaborate.cxx b/elaborate.cxx
index 59110c7..f918264 100644
--- a/elaborate.cxx
+++ b/elaborate.cxx
@@ -2293,6 +2293,9 @@ dead_assignment_remover::visit_try_block (try_block *s)
 // removed as a side-effect-free statement expression.  Wahoo!
 void semantic_pass_opt3 (systemtap_session& s, bool& relaxed_p)
 {
+  if (s.listing_mode_vars)
+    return;
+
   // Recompute the varuse data, which will probably match the opt2
   // copy of the computation, except for those totally unused
   // variables that opt2 removed.
diff --git a/main.cxx b/main.cxx
index 9cc0370..a00aeb8 100644
--- a/main.cxx
+++ b/main.cxx
@@ -868,9 +868,8 @@ main (int argc, char * const argv [])
           break;
 
         case 'L':
-          s.listing_mode_vars = true;
-          s.unoptimized = true; // This causes retention of variables for
listing_mode
-
+          s.listing_mode_vars = true; // This causes retention of variables for
display
+          // Fall through to pick up -l's behavior too...
         case 'l':
          s.suppress_warnings = true;
           s.listing_mode = true;
Comment 2 Josh Stone 2010-03-09 23:35:54 UTC
On fche's suggestion, I've left most optimizations disabled for -L, but enabled
just the constant-folding optimization to prune @defined trees.

commit c0f562688ae877000f46058f748a8b986679863e