Skip to content
Snippets Groups Projects
Commit 2d6d5a7b authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Include current function name in state-node

This adds another informative bit to the state-graph: The function
name of the function where the state was seen.
parent d7b60c9d
Branches
No related tags found
No related merge requests found
...@@ -99,8 +99,8 @@ uint32_t hash_os_state() { ...@@ -99,8 +99,8 @@ uint32_t hash_os_state() {
return first_hash ^ second_hash; return first_hash ^ second_hash;
} }
void _print_os_state(const char *syscall, int line) { void _print_os_state(const char *syscall, const char *func) {
kout << "Line " << line << " before syscall " << syscall << " in state "; kout << "Function " << func << " before syscall " << syscall << " in state ";
kout << "0x" << hex << hash_os_state() << dec << endl; kout << "0x" << hex << hash_os_state() << dec << endl;
fflush(stdout); fflush(stdout);
} }
......
...@@ -86,7 +86,7 @@ preIdleHook interrupts = do ...@@ -86,7 +86,7 @@ preIdleHook interrupts = do
return $ return $
"void PreIdleHook() {\n" "void PreIdleHook() {\n"
<> " _print_os_state(\"PreIdleHook\", __LINE__);\n" <> " _print_os_state(\"PreIdleHook\", __func__);\n"
<> triggerCode <> triggerCode
<> " ShutdownMachine();\n" <> " ShutdownMachine();\n"
<> "}\n" <> "}\n"
...@@ -107,7 +107,7 @@ triggerInterrupts (Just ints) = do ...@@ -107,7 +107,7 @@ triggerInterrupts (Just ints) = do
decision <- decisionNumber decision <- decisionNumber
return $ return $
" if (_decisionMaker("<> T.pack (show decision) <> ")) {\n" " if (_decisionMaker("<> T.pack (show decision) <> ")) {\n"
<> " _print_os_state(\"IRQ" <> T.pack (show int) <> "\", __LINE__);\n" <> " _print_os_state(\"IRQ" <> T.pack (show int) <> "\", __func__);\n"
<> " Machine::trigger_interrupt_from_user(" <> T.pack (show int) <> ");\n" <> " Machine::trigger_interrupt_from_user(" <> T.pack (show int) <> ");\n"
<> " }\n" <> " }\n"
...@@ -132,7 +132,7 @@ instrToC interrupts kind (Call ident True) = do ...@@ -132,7 +132,7 @@ instrToC interrupts kind (Call ident True) = do
else return mempty else return mempty
return $ return $
ints ints
<> "_print_os_state(\"" <> ident <> "\", __LINE__);\n" <> "_print_os_state(\"" <> ident <> "\", __func__);\n"
<> ident <> "();" <> ident <> "();"
instrToC _ _ Return = return "return;" instrToC _ _ Return = return "return;"
......
...@@ -19,8 +19,22 @@ import System.Process ...@@ -19,8 +19,22 @@ import System.Process
import System.IO import System.IO
import Data.Foldable import Data.Foldable
-- | (Syscall, Statehash) data Metadata = Metadata
type Vertex = (Text, Text) { metaFunc :: Text -- | Function Name
, metaSyscall :: Text -- | Next Syscall
}
-- | (Statehash, Metadata)
data Vertex = Vertex
{ vertState :: Text
, vertMeta :: Metadata
}
instance Eq Vertex where
Vertex x meta1 == Vertex y meta2 = (x, metaSyscall meta1) == (x, metaSyscall meta2)
instance Ord Vertex where
compare (Vertex x meta1) (Vertex y meta2) = compare (x, metaSyscall meta1) (y, metaSyscall meta2)
type Graph = Map Vertex (Set Vertex) type Graph = Map Vertex (Set Vertex)
...@@ -36,7 +50,7 @@ data State = State ...@@ -36,7 +50,7 @@ data State = State
, curTrace :: [Bool] , curTrace :: [Bool]
} }
addVertex :: (Text, Text ) -> State -> State addVertex :: Vertex -> State -> State
addVertex vert s = s addVertex vert s = s
{ graph = case currentVertex s of { graph = case currentVertex s of
Just old Just old
...@@ -69,7 +83,7 @@ findOpenDecision = listToMaybe . mapMaybe isHalf . M.elems . decisions ...@@ -69,7 +83,7 @@ findOpenDecision = listToMaybe . mapMaybe isHalf . M.elems . decisions
driver :: FilePath driver :: FilePath
-> Bool -- ^ Identify states on different locations? -> Bool -- ^ Identify states on different locations?
-> IO () -> IO ()
driver prog identStates = driver' prog identStates ("", "start") driver prog identStates = driver' prog identStates (Vertex "start" (Metadata "" ""))
--driver prog True = driver' prog (Vertex ("", "start") :: Vertex 'OnlyState) --driver prog True = driver' prog (Vertex ("", "start") :: Vertex 'OnlyState)
driver' :: FilePath -> Bool -> Vertex -> IO () driver' :: FilePath -> Bool -> Vertex -> IO ()
...@@ -142,8 +156,8 @@ parseLine handle = do ...@@ -142,8 +156,8 @@ parseLine handle = do
T.hPutStrLn stderr $ "Found line: " <> line T.hPutStrLn stderr $ "Found line: " <> line
case T.words line of case T.words line of
("Decision":num:_) -> return $ Decision (read $ T.unpack num) ("Decision":num:_) -> return $ Decision (read $ T.unpack num)
["Line",linum,"before","syscall",call,"in","state",state] ["Function",func,"before","syscall",call,"in","state",state]
-> return $ NewState (call, state) -> return $ NewState $ Vertex state (Metadata func call)
handleLine :: Handle -> IORef State -> IO LineOut handleLine :: Handle -> IORef State -> IO LineOut
handleLine pstdin state = parseLine pstdin >>= \case handleLine pstdin state = parseLine pstdin >>= \case
...@@ -160,7 +174,7 @@ graph2Dot is graph = ...@@ -160,7 +174,7 @@ graph2Dot is graph =
where where
nodeStr from tos = mconcat $ map (arrow from) $ S.toList tos nodeStr from tos = mconcat $ map (arrow from) $ S.toList tos
arrow from to = " " <> nodeId is from <> " -> " arrow from to = " " <> nodeId is from <> " -> "
<> nodeId is to <> " [label=\"" <> edgeLabel (fst from) <> "\"];\n" <> nodeId is to <> " [label=\"" <> edgeLabel (metaSyscall $ vertMeta from) <> "\"];\n"
-- | Generate readable edge label from syscall name -- | Generate readable edge label from syscall name
-- --
...@@ -176,12 +190,17 @@ dotNodes :: Bool -> Graph -> Text ...@@ -176,12 +190,17 @@ dotNodes :: Bool -> Graph -> Text
dotNodes is = foldMap formatNode . allNotes dotNodes is = foldMap formatNode . allNotes
where where
allNotes m = M.keysSet m `S.union` fold m allNotes m = M.keysSet m `S.union` fold m
formatNode (call, state) = nodeId is (call,state) formatNode vert = nodeId is vert
<> " [label=\"" <> " [label=\""
<> "State: " <> state <> "State: " <> vertState vert
<> "\\nFunction: " <> stripPrefix' "OSEKOS_" (metaFunc (vertMeta vert))
<> "\", shape=box];\n" <> "\", shape=box];\n"
nodeId :: Bool -> Vertex -> Text nodeId :: Bool -> Vertex -> Text
nodeId False (call, state) = "node" <> state <> "_" <> call nodeId False vert = "node" <> vertState vert <> "_" <> metaSyscall (vertMeta vert)
nodeId True (_, state) = "node" <> state nodeId True vert = "node" <> vertState vert
-- | Strip prefix but return original string if it doesn't begin with the prefix
stripPrefix' :: Text -> Text -> Text
stripPrefix' pref (T.stripPrefix pref -> Just txt) = txt
stripPrefix' _ txt = txt
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment