Skip to content
Martijn Bastiaan edited this page Jun 15, 2015 · 4 revisions

Because a Sprockell runs entirely in software, it is easy to set breakpoints and even debug it interactively. The main README of martijnbastiaan/sprockell suggests simulating the sprockells using run (defined in System.hs). This function, however, doesn't produce any output unless your Sprockell is manually set to use the Put instruction. Not very helpful! Luckily, runDebug also exists which also takes a function of type SystemState -> String. This function is called on every cycle (which is synchronised across all running Sprockells).

A very simple debugging function might look like:

debug :: SystemState -> String
debug _ = "Hello world!\n"

For a program consisting of two instructions this would print "Hello world" twice. More complex debugging functions can use pattern matches on SystemState to add breakpoints on specific system states. (Various example programs use this functionality, make sure to look there!)

For more powerful debugging features you might want to change the debug signature to SystemState -> IO (). You'd need to change signatures in System.hs accordingly, of course. From that point you can use real (blocking) breakpoints:

debug :: SystemState -> IO ()
debug _ = do 
    putStr "Blocking. Press any key..\n"
    getChar
    return ()

Obviously, you might do something useful with the user input (like pressing m for showing shared memory).

Clone this wiki locally