Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stepping through a function line by line

This user guide:

http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html

advertises:

Execution can be single-stepped: the evaluator will suspend execution approximately after every reduction, allowing local variables to be inspected. This is equivalent to setting a breakpoint at every point in the program.

Yet, I can find nothing in the document that tells me how to do that. Under the heading:

2.5.2. Single-stepping

It describes how to step from breakpoint to breakpoint. But I don't want to have to set a breakpoint on every line. Was the advertisement false or is there a way to step through a program line by line?

Thanks.

like image 931
7stud Avatar asked May 20 '13 22:05

7stud


People also ask

How do you step through a function?

Stepping Into a FunctionSet a breakpoint at the function call line. Step through your code line by line until you reach the function call. While the program is paused at the function call line, click the Step Into button.

What does it mean to step into a line of code?

Stepping through code means executing the code one line at a time. Stepping allows you to see the exact sequence of execution and the value of the various variables at each step. This can be invaluable when your script is not giving the results that you expect.

What does it mean to step into or step out of a function?

"Step into" will stop on the first executable line inside the function. Note, if you have optimisation enabled, the "first executable line" may not be the one you expect. 8/15/2021. 1and0. There is also a "Step Out" allowing you to step out of a function which you are currently stepping through.

Which command used run the next line of the program by stepping into function?

The step up command returns the program to the caller function after you have stepped into a function.


2 Answers

After having set and reached a breakpoint, you can call :step from the debugger.

There are other single-step possibilities. Typing :help once at a breakpoint would tell you more about what you can do.

like image 97
tomferon Avatar answered Nov 05 '22 15:11

tomferon


Okay, I figured it out:

ghci> :step function_name arg1 arg2
...
...
ghci> :step   
...
...
ghci> :step

If you forget the function arguments, then you will get the cryptic error message:

<interactive>:138:1:
    No instance for (Show (String -> Double))
      arising from a use of `print'
    Possible fix:
      add an instance declaration for (Show (String -> Double))
    In a stmt of an interactive GHCi command: print it

...which might lead you to tear your hair out. And if you want to skip to the end:

ghci> :continue
like image 40
7stud Avatar answered Nov 05 '22 14:11

7stud