Closed ntc2 closed 9 years ago
A patch with some relevant debug code:
commit 0321741a19c31fada029a3d45f9d424b2b99d391
Author: Nathan Collins <nathan.collins@gmail.com>
Date: 4 months ago
WIP: debugging the java switch statement problem.
My Java example could go in the tutorial if it worked.
diff --git src/Data/JVM/Symbolic/AST.hs src/Data/JVM/Symbolic/AST.hs
index a1f9d83..0e735e4 100644
--- src/Data/JVM/Symbolic/AST.hs
+++ src/Data/JVM/Symbolic/AST.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE StandaloneDeriving #-}
-- | This module defines the main data types for the AST interpreted
-- by the symbolic simulator. It enriches the JVM instruction set with
@@ -73,6 +74,11 @@ data SymInsn
| NormalInsn J.Instruction
deriving (Eq)
+deriving instance Show SymInsn
+deriving instance Show InvokeType
+deriving instance Show SymCond
+deriving instance Show CmpType
+
ppSymInsn :: SymInsn -> Doc
ppSymInsn stmt = case stmt of
PushInvokeFrame it ty key bid ->
diff --git src/Data/JVM/Symbolic/Translation.hs src/Data/JVM/Symbolic/Translation.hs
index 049ae0b..f4060cf 100644
--- src/Data/JVM/Symbolic/Translation.hs
+++ src/Data/JVM/Symbolic/Translation.hs
@@ -22,6 +22,8 @@ module Data.JVM.Symbolic.Translation
, SymTransWarning
) where
+import Debug.Trace
+
import Control.Applicative
import Control.Monad
import Control.Monad.RWS hiding ((<>))
@@ -168,7 +170,7 @@ liftBB cfg bb = do
-> [Int32]
-> [(Int32, PC)]
-> SymTrans ()
- switch currId il d is cs = do
+ switch currId il d is cs = traceShow (currId, il, d, is, cs) $ do
defineBlock currId $ reverse il ++ cases
zipWithM_ defineBlock caseBlockIds (brSymInstrs cfg <$> targets)
where targets = getBlock . snd <$> cs
diff --git src/Verifier/Java/Simulator.hs src/Verifier/Java/Simulator.hs
index f7b1f2b..2165292 100644
--- src/Verifier/Java/Simulator.hs
+++ src/Verifier/Java/Simulator.hs
@@ -92,6 +92,8 @@ module Verifier.Java.Simulator
, module Verifier.Java.Codebase
) where
+import GHC.Stack
+
import Prelude hiding (EQ, LT, GT)
import Control.Applicative hiding (empty)
@@ -1497,7 +1499,7 @@ instance MonadSim sbe m => JavaSemantics (Simulator sbe m) where
-- Pop value off top of stack.
popValue = modifyCallFrameM "popValue" $ \cf ->
case cf^.cfOpds of
- [] -> err "empty operand stack"
+ [] -> errorWithStackTrace "empty operand stack"
(x:xs) -> return (x, cf & cfOpds .~ xs)
-- Push value onto top of stack.
It appears that JSS can't handle
switch
statements with more than onecase
. I ran into this when I tried to add a new Java example to the tutorial indoc/tutorial/code/FFS.java
in thesaw-script
repo and it made SAW crash:Here are simple crashing and non-crashing examples:
And here is the corresponding Java bytecode -- extracted with
javap -c FFS
-- which is what JSS is actually processing. Crash:No crash:
The
lookupswitch
JVM bytecode is processed byswitch
insrc/Data/JVM/Symbolic/Translation.hs
, and the problem manifests as an empty stack pop inpopValue
insrc/Verifier/Java/Simulator.hs
.I pushed a
debug-broken-java-switch-statements
branch with these examples and some printf debugging inserted; I got side tracked failing to build SAW with profiling support to get stack traces. Runsaw ffs_java.saw
to see the crash.