How do I use breakpoints in F# interactive?

≯℡__Kan透↙ 提交于 2019-12-08 14:39:57

问题


I've started researching some ideas in algorithms using VS2010 and F# interactive.

So, I've created a DebugScript.fsx, I write some code there and eventually send it to F#Int to test it.

At some some moment I need to catch a bug. But I can't place a breakpoint even in a simple for loop:

for i in stringarray do
    printfn "%s" i

When I press F9 to set a breakpoint, the VS show a red circle with a warning sign. The hint for it is "The breakpoint will not currently be hit".

Surely, I did open Debug menu -> Attach to process ... -> Fsi.exe previously

I tried placing Debugger.Break() inside the loop, but that's the only line where debugger stops, giving me no option to proceed with debugging lines inside the loop. I also don't have any local variables available :(

Maybe I'm missing something obvious?


回答1:


in VS2015 is now much more easy: in Tools->Option->F# tools -> F# interactive-> Debugging -> Enable script debugging = True

then reset your interactive session and when you want to debug press CTRL+ALT+D and send command as usual

(or right click on the source file and choose "debug in interactive")




回答2:


You cannot debug the code that is part of your scripts, but you can debug external code referenced in your scripts by attaching the debugger to the Fsi.exe process as you describe. So if you really want to debug from the interactive window without wanting to write a console program, you can create an fs file with the function to debug and:

  1. Attach the debugger

  2. Either

    • reference the fs file with #load (*)
    • compile the code as a library and reference the resulting DLL with #r
  3. Set a breakpoint

  4. Call the function from a script

(*) worked on my VS Ultimate installation, but I haven't been able to reproduce on another machine with VS Shell install




回答3:


As far as I know, there's no way to do this. Instead, you'll want to use a .fs file and start debugging it in Visual Studio instead.




回答4:


In addition to kvb's answer: One could say that F# Interactive is already a type of debugger. You can feed code line by line (or region by region) and see intermediate results. You can also inspect the value of bindings just by evaluating them in the F# Interactive console.




回答5:


the interactive is for feeding it small pieces of code and evaluating intermediate results, think of it as micro-unit testing. i've had some success with using nunit with f#, it's no different than with c#, you decorate your testfixture and test cases in the same way and it will load up. i did have some issues with mixed-mode assemblies where nunit would barf, but overall, it's a better way imho to test a piece of code. also, i did not see a way to send a namespace to interactive, only modules.



来源:https://stackoverflow.com/questions/3654391/how-do-i-use-breakpoints-in-f-interactive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!