如何在f#交互中使用断点?

时间:2022-10-14 20:57:55

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

我已经开始研究使用VS2010和f#交互算法的一些算法。

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

我创建了一个调试脚本。fsx,我在那里写了一些代码,最后把它发送给f# Int进行测试。

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

在某个时刻,我需要捕捉一只虫子。但是我不能在简单的for循环中放置断点:

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".

当我按F9设置断点时,VS显示一个带有警告标志的红色圆圈。提示是“断点目前不会被击中”。

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

当然,我确实打开了调试菜单——>附加到进程……- > Fsi。exe之前

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 :(

我尝试在循环中放置debug . break(),但这是调试器停止的惟一一行,使我无法继续在循环中调试行。我也没有可用的局部变量:(

Maybe I'm missing something obvious?

也许我漏掉了什么明显的东西?

5 个解决方案

#1


11  

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:

不能调试作为脚本一部分的代码,但是可以通过将调试器附加到Fsi来调试脚本中引用的外部代码。正如您所描述的exe过程。因此,如果您真的想从交互式窗口进行调试,而不需要编写控制台程序,那么您可以创建一个具有调试功能的fs文件:

  1. Attach the debugger

    将调试器

  2. Either

    要么

    • reference the fs file with #load (*)
    • 使用#load(*)引用fs文件
    • compile the code as a library and reference the resulting DLL with #r
    • 将代码编译为库并使用#r引用结果DLL
  3. Set a breakpoint

    设置一个断点

  4. Call the function from a script
  5. 从脚本调用函数

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

(*)在我的VS终极安装上工作,但是我还不能在另一台安装VS Shell的机器上复制

#2


9  

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

在VS2015中更容易:在Tools->选项-> f# Tools-> f# interactive->调试->启用脚本调试= True

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

然后重置您的交互式会话,当您想要调试时按CTRL+ALT+D并像往常一样发送命令

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

(或右键单击源文件,选择“交互式调试”)

#3


2  

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.

据我所知,这是不可能的。相反,您需要使用.fs文件并在Visual Studio中调试它。

#4


1  

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.

除了kvb的答案之外:可以说f# Interactive已经是一种调试器了。您可以逐行输入代码(或逐区域输入)并查看中间结果。您还可以通过在f#交互控制台中评估绑定的值来检查它们。

#5


0  

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.

交互是为了给它提供一小段代码,并评估中间结果,把它看作是微单元测试。我已经成功地使用了nunit和f#,这和c#没什么不同,你用同样的方式装饰你的测试夹具和测试用例,它就会加载。我确实有一些混合模式程序集的问题,其中nunit会barf,但总的来说,这是一个更好的方法来测试一段代码。另外,我没有看到将名称空间发送到交互式的方法,只有模块。

#1


11  

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:

不能调试作为脚本一部分的代码,但是可以通过将调试器附加到Fsi来调试脚本中引用的外部代码。正如您所描述的exe过程。因此,如果您真的想从交互式窗口进行调试,而不需要编写控制台程序,那么您可以创建一个具有调试功能的fs文件:

  1. Attach the debugger

    将调试器

  2. Either

    要么

    • reference the fs file with #load (*)
    • 使用#load(*)引用fs文件
    • compile the code as a library and reference the resulting DLL with #r
    • 将代码编译为库并使用#r引用结果DLL
  3. Set a breakpoint

    设置一个断点

  4. Call the function from a script
  5. 从脚本调用函数

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

(*)在我的VS终极安装上工作,但是我还不能在另一台安装VS Shell的机器上复制

#2


9  

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

在VS2015中更容易:在Tools->选项-> f# Tools-> f# interactive->调试->启用脚本调试= True

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

然后重置您的交互式会话,当您想要调试时按CTRL+ALT+D并像往常一样发送命令

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

(或右键单击源文件,选择“交互式调试”)

#3


2  

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.

据我所知,这是不可能的。相反,您需要使用.fs文件并在Visual Studio中调试它。

#4


1  

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.

除了kvb的答案之外:可以说f# Interactive已经是一种调试器了。您可以逐行输入代码(或逐区域输入)并查看中间结果。您还可以通过在f#交互控制台中评估绑定的值来检查它们。

#5


0  

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.

交互是为了给它提供一小段代码,并评估中间结果,把它看作是微单元测试。我已经成功地使用了nunit和f#,这和c#没什么不同,你用同样的方式装饰你的测试夹具和测试用例,它就会加载。我确实有一些混合模式程序集的问题,其中nunit会barf,但总的来说,这是一个更好的方法来测试一段代码。另外,我没有看到将名称空间发送到交互式的方法,只有模块。