@@ -1711,6 +1711,200 @@ To run some common Cabal commands, just run:
1711
1711
1712
1712
Or @kbd {C-c c }. This is commonly used to do @code {install }, @code {haddock }, @code {configure }, etc.
1713
1713
1714
+ @section Haskell Interactive Mode Debugger
1715
+
1716
+ There is limited support for debugging in
1717
+ GHCi. [[Haskell Interactive Mode]] provides an interface for
1718
+ interacting with this.
1719
+
1720
+ @subsection Opening the debug buffer
1721
+
1722
+ To open the debug buffer run the following command from any buffer
1723
+ associated with a session:
1724
+
1725
+ @example
1726
+ M-x haskell-debug
1727
+ @end example
1728
+
1729
+ It will open a buffer that looks like this:
1730
+
1731
+ @example
1732
+ Debugging haskell
1733
+
1734
+ You have to load a module to start debugging.
1735
+
1736
+ g - refresh
1737
+
1738
+ Modules
1739
+
1740
+ No loaded modules.
1741
+ @end example
1742
+
1743
+
1744
+ @subsection Loading modules
1745
+
1746
+ To debug anything you need to load something into GHCi. Switch to a
1747
+ normal file, for example:
1748
+
1749
+ @example
1750
+ main = do putStrLn "Hello!"
1751
+ putStrLn "World"
1752
+ @end example
1753
+
1754
+ and load it into GHCi (@kbd {C-c C-l }). Now when you hit `g`
1755
+ (to refresh) in the debugging buffer, you'll see something like:
1756
+
1757
+ @example
1758
+
1759
+ Debugging haskell
1760
+
1761
+ b - breakpoint, g - refresh
1762
+
1763
+ Context
1764
+
1765
+ Not debugging right now.
1766
+
1767
+ Breakpoints
1768
+
1769
+ No active breakpoints.
1770
+
1771
+ Modules
1772
+
1773
+ Main - hello.hs
1774
+ @end example
1775
+
1776
+ @subsection Setting a breakpoint
1777
+
1778
+ To set a breakpoint hit `b` in the debugger buffer. It will prompt for
1779
+ a name. Enter `main` and hit `RET`.
1780
+
1781
+ Now the buffer will look like this:
1782
+
1783
+ @example
1784
+ Debugging haskell
1785
+
1786
+ s - step into an expression, b - breakpoint
1787
+ d - delete breakpoint, g - refresh
1788
+
1789
+ Context
1790
+
1791
+ Not debugging right now.
1792
+
1793
+ Breakpoints
1794
+
1795
+ 0 - Main (1:8)
1796
+
1797
+ Modules
1798
+
1799
+ Main - hello.hs
1800
+ @end example
1801
+
1802
+ @subsection Start stepping
1803
+
1804
+ Hit `s` to step through an expression: it will prompt for an
1805
+ expression to evaluate and step through. Enter `main` and hit
1806
+ @kbd {RET }. Now the buffer will look like this:
1807
+
1808
+ @example
1809
+ Debugging haskell
1810
+
1811
+ s - step into an expression, b - breakpoint
1812
+ d - delete breakpoint, a - abandon context, c - continue
1813
+ p - previous step, n - next step
1814
+ g - refresh
1815
+
1816
+ Context
1817
+
1818
+ main - hello.hs (stopped)
1819
+
1820
+ do putStrLn "Hello!"
1821
+ putStrLn "World"
1822
+
1823
+ _result :: IO () = _
1824
+
1825
+ 1 do putStrLn "Hello!" putStrLn "World"
1826
+
1827
+ Breakpoints
1828
+
1829
+ 0 - Main (1:8)
1830
+
1831
+ Modules
1832
+
1833
+ Main - hello.hs
1834
+ @end example
1835
+
1836
+ What we see here is the current expression being evaluated:
1837
+
1838
+ @example
1839
+ do putStrLn "Hello!"
1840
+ putStrLn "World"
1841
+ @end example
1842
+
1843
+ And we see the type of it:
1844
+
1845
+ @example
1846
+ _result :: IO () = _
1847
+ @end example
1848
+
1849
+ And we see a backtrace of steps so far:
1850
+
1851
+ @example
1852
+ 1 do putStrLn "Hello!" putStrLn "World"
1853
+ @end example
1854
+
1855
+ @subsection Continue stepping
1856
+
1857
+ To continue stepping, just hit `s` again. Now the context will change
1858
+ to:
1859
+
1860
+ @example
1861
+ main - hello.hs (stopped)
1862
+
1863
+ putStrLn "Hello!"
1864
+
1865
+ _result :: IO () = _
1866
+
1867
+ 1 do putStrLn "Hello!" putStrLn "World"
1868
+ @end example
1869
+
1870
+
1871
+ Hitting `s` once more, we see the context change to:
1872
+
1873
+ @example
1874
+ putStrLn "World"
1875
+
1876
+ _result :: IO () = _
1877
+
1878
+ 2 putStrLn "Hello!"
1879
+ 1 do putStrLn "Hello!" putStrLn "World"
1880
+ @end example
1881
+
1882
+ Finally hitting `s` again will say "Computation finished". Hitting `s`
1883
+ a final time will change the display back to:
1884
+
1885
+ @example
1886
+ Debugging haskell
1887
+
1888
+ s - step into an expression, b - breakpoint
1889
+ d - delete breakpoint, g - refresh
1890
+
1891
+ Context
1892
+
1893
+ Finished debugging.
1894
+
1895
+ 2 putStrLn "Hello!"
1896
+ 1 do putStrLn "Hello!" putStrLn "World"
1897
+
1898
+ Breakpoints
1899
+
1900
+ 1 - Main (1:8)
1901
+
1902
+ Modules
1903
+
1904
+ Main - hello.hs
1905
+ @end example
1906
+
1907
+ And you're done debugging.
1714
1908
1715
1909
1716
1910
@node Editing Cabal files
0 commit comments