none
WinDbg x64 using SOS: Failed to find runtime DLL (clr.dll) RRS feed

  • Question

  • Hello, I'm new to using advanced Windows debugging tools. I just installed Debugging Tools for Windows 64-bit (6.12.2.633). I have .NET Framework 4.0 (4.0.30319) and Visual Studio 2010 (10.0.30319.1) on a Windows 7 x64 AMD machine.

    When I try to use SOS, and load clr.dll, sos.dll to debug a .NET 4.0 executable in WinDbg, this is what occurs in the WinDbg window:

    0:000> .chain
    Extension DLL search Path:
    Extension DLL chain:
     dbghelp: image 6.12.0002.633, API 6.1.6, built Mon Feb 01 15:15:44 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\dbghelp.dll]
     ext: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:46 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\winext\ext.dll]
     wow64exts: image 6.1.7650.0, API 1.0.0, built Mon Feb 01 15:15:14 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\WINXP\wow64exts.dll]
     exts: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:38 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\WINXP\exts.dll]
     uext: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:36 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\winext\uext.dll]
     ntsdexts: image 6.1.7650.0, API 1.0.0, built Mon Feb 01 15:15:18 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\WINXP\ntsdexts.dll]
    0:000> .load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
    0:000> .load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll
    0:000> !threads
    Failed to find runtime DLL (clr.dll), 0x80004005
    Extension commands need clr.dll in order to have something to do.
    0:000> .chain
    Extension DLL search Path:
    Extension DLL chain:
     C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll: image 4.0.30319.225, API 1.0.0, built Wed Feb 09 23:37:12 2011
     [path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll]
     C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll: image 4.0.30319.225, built Wed Feb 09 23:21:10 2011
     [path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll]
     dbghelp: image 6.12.0002.633, API 6.1.6, built Mon Feb 01 15:15:44 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\dbghelp.dll]
     ext: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:46 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\winext\ext.dll]
     wow64exts: image 6.1.7650.0, API 1.0.0, built Mon Feb 01 15:15:14 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\WINXP\wow64exts.dll]
     exts: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:38 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\WINXP\exts.dll]
     uext: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:36 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\winext\uext.dll]
     ntsdexts: image 6.1.7650.0, API 1.0.0, built Mon Feb 01 15:15:18 2010
     [path: C:\Program Files\Debugging Tools for Windows (x64)\WINXP\ntsdexts.dll]
    

     

    The error message I keep getting is "Failed to find runtime DLL (clr.dll), 0x80004005 Extension commands need clr.dll in order to have something to do."

    I searched around for questions like mine, but the issue described at

    http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2c5255a1-d5dd-4353-b4b0-ceb5a6cc232e/

    doesn't seem to apply since I only have 1 SOS.dll and 1 mscorwks.dll/clr.dll loaded.

    Or http://social.msdn.microsoft.com/forums/en-US/clr/thread/e609dc9b-bf6f-4f49-9f51-5c3a4a5efa2d doesn't apply here because I'm already specifying the full paths of the DLLs in the .load command. I did not copy the DLLs to the WinDbg directory.

    Also, if I debug the same .NET  program under Visual Studio debugger, and I run SOS from Immediate:

     

    	.load sos
    	extension C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.dll loaded
    	!Threads
    	PDB symbol for clr.dll not loaded
    	ThreadCount:  2
    	UnstartedThread: 0
    	BackgroundThread: 1
    	PendingThread: 0
    	DeadThread:  0
    
    Hosted Runtime: no

     

     Now SOS works, but I am debugging the same build of the same .NET 4.0 program, on the same 64-bit machine, but the extension of SOS loaded is from the Framework directory and not Framework64. If I attempt to use that non-x64 SOS.dll from Framework in WinDbg x64, WinDbg will show this:

     

    0:000> .load C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.dll
    The call to LoadLibrary(C:\Windows\Microsoft.NET\Framework\v4.0.30319\sos.dll) failed, Win32 error 0n193
     "%1 is not a valid Win32 application."
    Please check your debugger configuration and/or network access.
    

     

    Can someone explain how to get SOS working in WinDbg (x64) and why I'm getting this error?

    (I do not seem to run into these problems if I build the same .NET executable on a Windows XP SP3 x86 machine and run WinDbg x86 from there. On the Windows XP machine, I could even copy the DLLs from the Framework directory into the WinDbg directory and SOS would work as expected. I just do not know why SOS is not working on my Windows 7 x64 machine with  Debugging Tools for Windows 64-bit (6.12.2.633) installed.)

    Thanks.

     

     


    T. Webster

    Saturday, May 7, 2011 2:14 AM

Answers

  • If we launch an exe file from WinDbg, WinDbg will break the execution before the executable get to run, in another words, the run time (clr.dll) hasn't been loaded; but SOS extension needs clr.dll (or mscorwks.dll) to interactive with managed debuggee process, so we can use "g" command to let the managed process continue to run, an use Ctrl + Break to break the process after clr.dll was loaded.

     

    You can make some change to your code, add "Console.ReadLine();" to keep the process waiting there:

     

    namespace Advanced.NET.Debugging.Chapter2

    {

        class Simple

        {

            static void Main(string[] args)

            {

                Console.WriteLine("Welcome to Advanced .NET Debugging!");

                Console.ReadLine();

            }

        }

    }

     

    Launch 02Sample.exe from WinDbg, and then input "g" command to let debuggee process to run, after receive output "Welcome to Advanced .NET Debugging!" from 02Sample.exe, back to WinDbg, press Ctrl + Break, and then input command ".loadby sos clr" to load sos extension.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by T. Webster Tuesday, May 10, 2011 8:05 PM
    Tuesday, May 10, 2011 1:35 AM

All replies

  • Processes on 64bit OS are divided into two categories: 32bit process and 64bit process; To debug 32bit process, you may want to use x86 version of WinDbg, in the other hand, you may use x84 WinDbg to debug 64bit process.

     

    You can check the Platform Target of your project to determine whether the process will run as 32bit or 64bit on 64bit OS:

     

    X86 --> 32bit

    AnyCPU, X64 --> 64bit


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 9, 2011 2:48 AM
  • Hello Eric thanks for your response to my question,

    The executable I am running is a 64-bit process. In its MSBuild/.csproj file, the platform target is x64. Also, I know that the executable is running as a 64-bit process because WinDbg 64-bit will not run a 32-bit/x86 executable.

    Additionally, the dumpbin output of the .exe shows:

    File Type: EXECUTABLE IMAGE

    FILE HEADER VALUES
                8664 machine (x64)

    Please see this link to the zip file I put on my SkyDrive to verify this is correct. The .zip file contains the source file (.cs), the executable, the build.xml MSBuild file, and the dumpbin output .txt file.

    Therefore I know I am running a x64 process in WinDbg, yet WinDbg still fails to find runtime DLL (clr.dll)

    Again the commands I enter into WinDbg immediately after opening the executable, and the output from WinDbg are the following:

     

    0:000> .load clr
    The call to LoadLibrary(clr) failed, Win32 error 0n2
        "The system cannot find the file specified."
    Please check your debugger configuration and/or network access.
    0:000> .load clr.dll
    The call to LoadLibrary(clr.dll) failed, Win32 error 0n2
        "The system cannot find the file specified."
    Please check your debugger configuration and/or network access.
    0:000> .load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
    0:000> .load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll
    0:000> .chain
    Extension DLL search Path:

    Extension DLL chain:
        C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll: image 4.0.30319.225, API 1.0.0, built Wed Feb 09 23:37:12 2011
            [path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll]
        C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll: image 4.0.30319.225, built Wed Feb 09 23:21:10 2011
            [path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll]
        dbghelp: image 6.12.0002.633, API 6.1.6, built Mon Feb 01 15:15:44 2010
            [path: C:\Program Files\Debugging Tools for Windows (x64)\dbghelp.dll]
        ext: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:46 2010
            [path: C:\Program Files\Debugging Tools for Windows (x64)\winext\ext.dll]
        exts: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:38 2010
            [path: C:\Program Files\Debugging Tools for Windows (x64)\WINXP\exts.dll]
        uext: image 6.12.0002.633, API 1.0.0, built Mon Feb 01 15:15:36 2010
            [path: C:\Program Files\Debugging Tools for Windows (x64)\winext\uext.dll]
        ntsdexts: image 6.1.7650.0, API 1.0.0, built Mon Feb 01 15:15:18 2010
            [path: C:\Program Files\Debugging Tools for Windows (x64)\WINXP\ntsdexts.dll]
    0:000> !dumpheap
    Failed to find runtime DLL (clr.dll), 0x80004005
    Extension commands need clr.dll in order to have something to do. 

     


    Also, even if I set the target platform to x86, I will still get the following from WinDbg (now 32-bit):

    0:000> .load C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
    0:000> .load C:\Windows\Microsoft.NET\Framework\v4.0.30319\SOS.dll
    0:000> !dumpheap
    Failed to find runtime DLL (clr.dll), 0x80004005
    Extension commands need clr.dll in order to have something to do.
    0:000> .chain
    Extension DLL search Path:
    Extension DLL chain:
        C:\Windows\Microsoft.NET\Framework\v4.0.30319\SOS.dll: image 4.0.30319.225, API 1.0.0, built Wed Feb 09 23:49:57 2011
            [path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\SOS.dll]
        C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll: image 4.0.30319.225, built Wed Feb 09 23:24:43 2011
            [path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll]
        dbghelp: image 6.11.0001.404, API 6.1.6, built Wed Feb 25 20:55:30 2009
            [path: C:\Program Files (x86)\Debugging Tools for Windows (x86)\dbghelp.dll]
        ext: image 6.11.0001.404, API 1.0.0, built Wed Feb 25 20:55:30 2009
            [path: C:\Program Files (x86)\Debugging Tools for Windows (x86)\winext\ext.dll]
        wow64exts: image 6.1.7015.0, API 1.0.0, built Wed Feb 25 20:54:36 2009
            [path: C:\Program Files (x86)\Debugging Tools for Windows (x86)\WINXP\wow64exts.dll]
        exts: image 6.11.0001.404, API 1.0.0, built Wed Feb 25 20:55:24 2009
            [path: C:\Program Files (x86)\Debugging Tools for Windows (x86)\WINXP\exts.dll]
        uext: image 6.11.0001.404, API 1.0.0, built Wed Feb 25 20:55:26 2009
            [path: C:\Program Files (x86)\Debugging Tools for Windows (x86)\winext\uext.dll]
        ntsdexts: image 6.1.7015.0, API 1.0.0, built Wed Feb 25 20:54:43 2009
            [path: C:\Program Files (x86)\Debugging Tools for Windows (x86)\WINXP\ntsdexts.dll]

     


    Also, I am running WinDbg as Administrator.
    • Edited by T. Webster Monday, May 9, 2011 11:55 PM formatting
    Monday, May 9, 2011 11:53 PM
  • If we launch an exe file from WinDbg, WinDbg will break the execution before the executable get to run, in another words, the run time (clr.dll) hasn't been loaded; but SOS extension needs clr.dll (or mscorwks.dll) to interactive with managed debuggee process, so we can use "g" command to let the managed process continue to run, an use Ctrl + Break to break the process after clr.dll was loaded.

     

    You can make some change to your code, add "Console.ReadLine();" to keep the process waiting there:

     

    namespace Advanced.NET.Debugging.Chapter2

    {

        class Simple

        {

            static void Main(string[] args)

            {

                Console.WriteLine("Welcome to Advanced .NET Debugging!");

                Console.ReadLine();

            }

        }

    }

     

    Launch 02Sample.exe from WinDbg, and then input "g" command to let debuggee process to run, after receive output "Welcome to Advanced .NET Debugging!" from 02Sample.exe, back to WinDbg, press Ctrl + Break, and then input command ".loadby sos clr" to load sos extension.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by T. Webster Tuesday, May 10, 2011 8:05 PM
    Tuesday, May 10, 2011 1:35 AM
  • Thanks Eric that helped. Now after I load mscorwks.dll, sos.dll the commands e.g. !dumpheap, !threads now work.

    Just missing a simple detail like knowing to input "g" before clr.dll/mscorwks.dll will load has made a world of difference for me in getting past this point, as I'm new to WinDbg and advanced .NET debugging.


    T. Webster
    Tuesday, May 10, 2011 8:05 PM