20

Since I do not have access to the complete source code of a library I'm using, but I do have the pdb files, is it possible to set a breakpoint in the "debugging source code"?

If so, how would I do that?

SamB
  • 9,039
  • 5
  • 49
  • 56
sebastiaan
  • 5,870
  • 5
  • 38
  • 68

1 Answers1

30

Yes, this is possible, you don't need the source code. Debug > New Breakpoint > Break at Function. Set the location to the name of the function. For example: "Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly". Turn the "Use Intellisense" checkbox off, you won't have any. Language is a guess if you don't know what it was written in, choose "Unknown" if you're not sure.

You'll want to keep an eye on the Debug + Windows + Breakpoints window to verify that the debugger could resolve the breakpoint. It won't be able to until the assembly gets loaded and the method gets JIT compiled.

This is of course not the greatest debugging experience. Once the breakpoint hits, you don't have anything to look at but the machine code generated by the JIT compiler. And the Call Stack window, your ultimate resource to see method names btw.

Jess
  • 23,901
  • 21
  • 124
  • 145
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • So how would you set a break to e.g. `System.DateTime.IsLeapYear()`? Tried this but it's not breaking. I have the 'Microsoft Symbols Servers' defined in Tools > Debugging > Symbols, but the Breakpoints window shows 'Symbol not found'. – Rubio Mar 07 '13 at 11:17
  • Works fine when I try it. Don't type the () – Hans Passant Mar 07 '13 at 11:20
  • 3
    Had 'Just my code' set (again, sigh) so the symbols didn't get loaded. Just need to load the source code. I understand John Robbins has a tool for that. – Rubio Mar 08 '13 at 13:17
  • 2
    VS almost always goes above my expectations. Setting a breakpoint to an external funcion and looking at the CallStack was I all needed to fix a complex issue. Thanks for the answer. – Ignacio Soler Garcia May 11 '16 at 09:01
  • For me, it worked best by including the the dll as well, like `Microsoft.AspNetCore.Authentication.Certificate.dll!Microsoft.AspNetCore.Authentication.Certificate.CertificateAuthenticationHandler.HandleAuthenticateAsync()`. You can copy this entire string from the callstack. – martinoss Oct 28 '20 at 14:23