5

I want to have a bit more of a look at the resulting ASM (F#->IL->ASM) that is generated for certain functions, purely out of curiosity & learning.

Answer in my mind is to use SOS.dll, but I have run into a bit of a hurdle...

Let us start with the most basic code in F#. File is named test.fs.

[<EntryPoint>]
  let main _ = 
    stdin.ReadLine()
    1

We are defining an entry point that takes 'a (constrained without telling us (?) to string array for obvious reasons (trivia: can't use "'a" in an entrypoint function?)). We then wait for user input. This makes it a lot easier to break manually in windbg. compile test.fs to produce test.exe

Open windbg, open test.exe inside windbg:

>!load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll
>g

Windbg will run our code and wait for the readline loop, we can then type something into the console window and windbg will exit.

Now, how do we place a breakpoint on main so that we can break before the readline loop?

>!bpmd test.exe Test.main; g

windbg will then enter the readline loop... I was expecting it to break before the readline loop, the breakpoint must be ill-defined. Following this I tried many variations of breakpoints: !bpmd test.exe Test.main; !bpmd test.exe Test; !bpmd test.exe main; !bpmd test.exe Main; !bpmd test.exe Main.test !bpmd test.exe Test... ect (but may have missed one) it is quite obvious I am doing something wrong, I have also tried using module xx = ...,

Question: Could anyone let me know how to place a breakpoint in F# managed code from within windbg using SOS extensions?

References:

http://winterdom.com/2011/06/having-fun-with-windbg

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/a0ab6170-d53b-4c95-8f5e-efaf4e014fcd

http://blogs.msdn.com/b/vancem/archive/2006/09/05/742062.aspx

1 Answers1

5

Try !sosex.mbm, which takes a method filter with */? wildcard syntax like the command line. Also try !sosex.mbp, which takes a source file, line number and optional column number. To disassemble, use !sos.dumpil or !sos.U. For an interleaved disassembly of source/IL/native, try out !sosex.muf.

Steve Johnson
  • 2,958
  • 13
  • 15
  • Steve, thank you for replying, I didn't know about SosEx, very cool. Edit: I went on a rampage trying !mbm \*main\*; !mbm \*test\*; but I couldn't get it to break, am I misinterpreting the wildcard requirement? Edit2: fixed wildcard. –  May 11 '12 at 03:45
  • hurrah, !mbm *!Test.main works!, now, why doesn't this work with !bpmd? (Also do you have the source available for SosEx?) –  May 11 '12 at 04:13
  • 1
    For various reasons, some personal, some legal, I'm keeping the source closed. Although I wrote sosex before I worked at MS, now that I'm here and continue to work on sosex, I can't take the chance that confidential details get into the source and into the wild. – Steve Johnson May 11 '12 at 12:25
  • Understood, if someone were interested in learning about writing dbg extensions for managed code, is there available public resources? Would be cool if there was a .net library to view post jit asm like your extension but outside of a debugger!! Edit: typo –  May 12 '12 at 01:03
  • 1
    Unfortunately, the methods for debugging managed code are all undocumented. I learned from the Rotor sources. Rotor contains the source code for an old version of SOS. The interfaces and data structures have changed significantly since Rotor, so I had to rely on reverse engineering to fill in some gaps. – Steve Johnson Jun 05 '12 at 14:13