Search code examples
c#debuggingvisual-studio-2017clr

Why can't I set breakpoints in the c# code from the CudaFy library?


I have downloaded an open source library named CudaFy and have been using it for a while now. The project seems to have been abandoned, so when I run into problems, I get to fix them myself. Mostly this isn't a problem, but one of the c# libraries in the project refuses to let me set breakpoints, making debugging irritatingly difficult.

If I try to set the breakpoint before running the app, the red dot gets added, but as soon as I run the app, the circle gets hollowed out, and never gets re-enabled. I know the code where I'm trying to set the breakpoint is executing, because I can change it to things that show (throw new Exception("foo") for example).

Looking at the VS output window, I see:

'Opt.exe' (CLR v4.0.30319: Opt.exe): Loaded 'C:\vss\cudafy2\Opt\bin\x64\Debug\CUDA.NET.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Symbols for the module 'CUDA.NET.dll' were not loaded.

Clearly this is a clue. However, looking at the project settings it definitely is NOT being built with optimizations. I've turned optimizations on and back off again, and I've fiddled with the CSPROJ file but nothing helps.

I've tried RebuildAll, cleaning the folders, shouting profanities, and banging my fist on the table. All to no avail.

Environment:

  • Windows 7 x64
  • Visual Studio 2017 (15.8.0 P5)
  • Building Debug/x64
  • Framework 4.7.2

Solution

  • I'm posting this as a Q&A style answer, since both google and SO let me down on this one. But now that I've found the answer, I'm posting it in the hope that it helps the next guy.

    The trick turned out to be in the assembly.cs file for the library in question. It contains this line:

    [assembly: System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
    

    I've read the docs for this attribute, but I still don't quite understand what it does. I also don't understand why the project felt the need to add it.

    • Is there some functional reason this needs to be there? Things seem to run without it, but perhaps there's some obscure feature that requires it?
    • Was someone just trying to make their code undebuggable?
    • Is this supposed to be debuggable but isn't due to a bug in VS or clr?
    • This project is intended to support a number of environments. Perhaps some other platform required it?

    I don't know the answers to any of these questions. But for the moment, I don't need to. Commenting out this line allows breakpoints to be set again and the code which calls it continues to run, which is all I needed.

    If someone has some light to shine, I'd be interested. But in the meantime, if someone else experiences this, now you have someplace to look.