如何在F#交互式中使用断点? [英] How do I use breakpoints in F# interactive?

查看:217
本文介绍了如何在F#交互式中使用断点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



所以,我创建了一个 DebugScript.fsx ,我在那里编写一些代码,最终将其发送到F#Int进行测试。



在某些时候,我需要捕获一个错误。但是,即使在循环的简单中,我也不能放置断点:

  for i in stringarray do 
printfn%si

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



当然我打开了Debug菜单 - >附加到进程... - > Fsi.exe以前



我尝试在循环中放置 Debugger.Break(),但这是调试器停止的唯一行,让我没有选择在循环内进行调试线。我也没有任何本地变量可用:(



也许我错过了一些明显的东西?

解决方案

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


  1. 附加调试器






    • 将代码编译为一个库,并使用#r


  2. 设置断点


  3. 从脚本调用函数

(*)在我的VS Ultimate安装上工作,但是我没有能够使用VS Shell安装在另一台机器上复制


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?

解决方案

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

这篇关于如何在F#交互式中使用断点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆