Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set conditional breakpoint while debugging F# in Visual Studio

Consider this:

let hank = "hank"
let bill = "bill"
printfn "%A" hank  // for breakpoint

Now if I set a conditional breakpoint in VS2015, condition being "hank = bill" (assuming F# expression) I get the following error:

The condition for a breakpoint failed to execute. The condition was 'hank = bill'. The error returned was 'The breakpoint condition must evaluate to a boolean operation'.

When the condition is "hank == bill" (maybe try C# expression?) the error is:

The condition for a breakpoint failed to execute. The condition was 'hank == bill'. The error returned was 'The runtime has refused to evaluate the expression at this time.'.

like image 982
dudeNumber4 Avatar asked Dec 12 '16 21:12

dudeNumber4


People also ask

How do you set a conditional breakpoint?

To set a conditional breakpointOn the Home tab, in the Breakpoints group, choose Set/Clear Condition. In the Debugger Breakpoint Condition window, enter a condition. On the Home tab, in the Breakpoints group, choose List. In the Debugger Breakpoint List window, enter a condition in the Condition column.

How do you use breakpoints in debugging?

To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.

How do you set a breakpoint in a function?

You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called.


1 Answers

The debugger uses C# syntax for conditions in breakpoints (in all versions of F# in Visual Studio, as far as I know), so the expression to use is hank == bill. I certainly used conditional breakpoints in F# with VS 2015 - some assorted thoughts on what might help:

  • I think the debugger sometimes starts behaving oddly when you do too many things. Did you try to set the breakpoint in the second way after restarting the debugger?

  • Sometimes, setting breakpoints immediately on let is a bit odd (the compiled code first initializes the variable to defaultof<'T>). Can you try adding some no-op statement like printfn "test" and setting conditional breakpoint on that?

like image 119
Tomas Petricek Avatar answered Nov 07 '22 23:11

Tomas Petricek