After loading a managed program in WinDbg ( File -> Open Executable ... ) when trying to load extensions from sos.dll , the following error occurs:

 0:000> .loadby sos clr Unable to find module 'clr' 

SOS commands ( !bpmd , etc.) do not work. How can I fix this error and get access to the commands?

    1 answer 1

    The fact is that WinDbg stops the program execution at the early stage of the process initialization, in the LdrpDoDebuggerBreak function of the LdrpDoDebuggerBreak module. At this moment, the clr.dll runtime has not yet been loaded into its address space, therefore, it is not possible to connect the SOS extension.

    It is necessary to set a breakpoint at the time of loading the clr module, and even better at the time of loading the clrjit JIT compiler, since in the first case (as I suppose), the program’s metadata has not yet been read, and part of the SOS commands, for example !bpmd , will not work.

    The moment of loading the module is caught by the sxe ld command:

     0:000> sxe ld clrjit 0:000> g 

    After this, the extension connects without errors:

     0:000> .loadby sos clr 0:000> !bpmd test.exe Test.Main Found 1 methods in module 00007ff8efe740c0... MethodDesc = 00007ff8efe75980 Adding pending breakpoints...