在x64平台上用x86模式run托管程序debug的方法

被一件事儿困惑了许久:

我们使用的TFS 2008做源代码,使用CruiseControl.net做持续集成,由于ccnet1.5还不是release的,所以需要使用vsts.cruisecontrol.net这个插件,而这个插件只能以32bit方式运行,所以ccnet在x64上启动后默认就是以64bit方式运行,是无法加载32bit only的assembly的,因为处理的方式使用corflags,使ccnet按照32bit的方式运行。

问题是ccnet不断的报告中断。查看log等也没找到问题所在,无奈,抓包。头疼开始了:

0:025> .loadby sos mscorwks
0:025> .reload
..........................WARNING: mscorjit overlaps mscoree
..............................WARNING: wldap32 overlaps dnsapi
........
..WARNING: rasapi32 overlaps dnsapi
...WARNING: tapi32 overlaps rasapi32
.WARNING: rtutils overlaps rasman
..............WARNING: setupapi overlaps winsta
....
0:025> !clrstack
Failed to load data access DLL, 0x80004005
Verify that 1) you have a recent build of the debugger (6.2.14 or newer)
            2) the file mscordacwks.dll that matches your version of mscorwks.dll is
                in the version directory
            3) or, if you are debugging a dump file, verify that the file
                mscordacwks_<arch>_<arch>_<version>.dll is on your symbol path.
            4) you are debugging on the same architecture as the dump file.
                For example, an IA64 dump file must be debugged on an IA64
                machine.

You can also run the debugger command .cordll to control the debugger's
load of mscordacwks.dll.  .cordll -ve -u -l will do a verbose reload.
If that succeeds, the SOS command should work on retry.

If you are debugging a minidump, you need to make sure that your executable
path is pointing to mscorwks.dll as well.

又是Failed to load data access DLL,0x80004005。这个问题到是常见,可是我是在同一台机器上做debug,提示里说的4个问题我应该不存在才对。

有点无奈了,不过,这是一个-crash模式的dump,一打开的时候应该会有些提示内容的,让我们回过头去看看:

Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.

Loading Dump File [D:\Crash_Mode__Date_12-05-2009__Time_15-54-2727\PID-4056__CCNET.EXE__2nd_chance_NET_CLR__full_13d0_2009-12-06_00-32-58-375_0fd8.dmp]
User Mini Dump File with Full Memory: Only application data is available

Comment: '2nd_chance_NET_CLR_exception_in_CCNET.EXE_running_on_TEST218'
Symbol search path is: srv*
Executable search path is:
Windows Server 2003 Version 3790 (Service Pack 2) MP (2 procs) Free x64
Product: Server, suite: Enterprise TerminalServer SingleUserTS
Machine Name:
Debug session time: Sun Dec  6 00:33:00.000 2009 (GMT+8)
System Uptime: 32 days 12:43:50.773
Process Uptime: 0 days 8:44:23.000
..........................WARNING: mscorjit overlaps mscoree
..............................WARNING: wldap32 overlaps dnsapi
........
..WARNING: rasapi32 overlaps dnsapi
...WARNING: tapi32 overlaps rasapi32
.WARNING: rtutils overlaps rasman
..............WARNING: setupapi overlaps winsta
....
This dump file has an exception of interest stored in it.
The stored exception information can be accessed via .ecxr.
(fd8.15fc): CLR exception - code e0434f4d (first/second chance not available)
wow64!Wow64NotifyDebugger+0x9:
00000000`6b006369 b001            mov     al,1

wow64,这里给了点啥说法呢,在我们的32bit程序中的64bit部分,那么我应该只关心32bit部分去:

0:025> !load wow64exts
0:025> !sw
Switched to 32bit mode
0:025:x86> !clrstack
OS Thread Id: 0x15fc (25)
Failed to start stack walk: 80070057
0:025:x86> !threads
ThreadCount: 36
UnstartedThread: 0
BackgroundThread: 15
PendingThread: 0
DeadThread: 0
Hosted Runtime: no

正常了,这样就可以继续了:

0:025:x86> kb
ChildEBP RetAddr  Args to Child             
07c9f10c 79eda99c e0434f4d 00000001 00000001 kernel32!RaiseException+0x53
07c9f16c 7a097d91 0fd28d98 00000000 00000000 mscorwks!RaiseTheExceptionInternalOnly+0x2a8
07c9f184 7a097e03 0fd28d98 00000000 07c9f30c mscorwks!RaiseTheException+0x4e
07c9f1ac 7a097e34 00000000 06246750 f1880ba3 mscorwks!RaiseTheException+0xc0
07c9f1d8 7a097e42 0fd28d98 00000000 07c9f318 mscorwks!RealCOMPlusThrow+0x30
07c9f1e8 7a1080af 0fd28d98 53e77d3f 79f38888 mscorwks!RealCOMPlusThrow+0xd
07c9f318 7a10a245 00000000 07c9f350 07c9f3c0 mscorwks!Thread::RaiseCrossContextException+0x41f
07c9f3cc 79fd882b 00000002 79fd87f6 07c9f4c4 mscorwks!Thread::DoADCallBack+0x2a2
07c9f3e8 79e9846b 07c9f4c4 07c9f470 79f7762b mscorwks!Thread::DoADCallBack+0x310
07c9f47c 79e98391 07c9f4c4 53e77a9f 00000000 mscorwks!Thread::ShouldChangeAbortToUnload+0xe3
07c9f4b8 79e9851d 07c9f4c4 00000002 00000000 mscorwks!Thread::ShouldChangeAbortToUnload+0x30a
07c9f4e0 79f3d654 00000002 79f3d769 07c9f550 mscorwks!Thread::ShouldChangeAbortToUnload+0x33e
07c9f4f8 79f3d72e 00000002 79f3d769 07c9f550 mscorwks!ManagedThreadBase::KickOff+0x13
07c9f594 79f920a5 06246df8 07c9f5d4 7d6251f0 mscorwks!ThreadNative::KickOffThread+0x269
07c9ffb8 7d4dfe37 062397e8 00000000 00000000 mscorwks!Thread::intermediateThreadProc+0x49
07c9ffec 00000000 79f9205f 062397e8 00000000 kernel32!BaseThreadStart+0x34
0:025:x86> !pe
Exception object: 000000000fd28d98
Exception type:
System.Threading.ThreadInterruptedException
Message: Thread was interrupted from a waiting state.
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80131519
0:025:x86> !do 000000000fd28d98
Name: System.Threading.ThreadInterruptedException
MethodTable: 000000007994f930
EEClass: 00000000791721c4
Size: 72(0x48) bytes
(C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
Fields:
      MT    Field   Offset                 Type VT     Attr    Value Name
0000000079330a00  40000b5        4        System.String  0 instance 000000000fd29c3c _className
000000007932fe74  40000b6        8 ...ection.MethodBase  0 instance 0000000000000000 _exceptionMethod
0000000079330a00  40000b7        c        System.String  0 instance 000000000fd2a260 _exceptionMethodString
0000000079330a00  40000b8       10        System.String  0 instance 000000000fd29d94 _message
000000007932a35c  40000b9       14 ...tions.IDictionary  0 instance 0000000000000000 _data
0000000079330b94  40000ba       18     System.Exception  0 instance 0000000000000000 _innerException
0000000079330a00  40000bb       1c        System.String  0 instance 0000000000000000 _helpURL
000000007933061c  40000bc       20        System.Object  0 instance 0000000000000000 _stackTrace
0000000079330a00  40000bd       24        System.String  0 instance 0000000000000000 _stackTraceString
0000000079330a00  40000be       28        System.String  0 instance 000000000fd2ab34 _remoteStackTraceString
0000000079332c4c  40000bf       34         System.Int32  1 instance        0 _remoteStackIndex
000000007933061c  40000c0       2c        System.Object  0 instance 0000000000000000 _dynamicMethods
0000000079332c4c  40000c1       38         System.Int32  1 instance -2146233063 _HResult
0000000079330a00  40000c2       30        System.String  0 instance 000000000fd2a4c8 _source
00000000793332c8  40000c3       3c        System.IntPtr  1 instance 367c6d400000000 _xptrs
0000000079332c4c  40000c4       40         System.Int32  1 instance        0 _xcode
0:025:x86> !do 000000000fd2ab34
Name: System.String
MethodTable: 0000000079330a00
EEClass: 00000000790ed64c
Size: 772(0x304) bytes
(C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
String:    at System.Threading.Thread.SleepInternal(Int32 millisecondsTimeout)
   at
ThoughtWorks.CruiseControl.Core.ProjectIntegrator.Run()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Fields:
      MT    Field   Offset                 Type VT     Attr    Value Name
0000000079332c4c  4000096        4         System.Int32  1 instance      378 m_arrayLength
0000000079332c4c  4000097        8         System.Int32  1 instance      377 m_stringLength
00000000793316e0  4000098        c          System.Char  1 instance       20 m_firstChar
0000000079330a00  4000099       10        System.String  0   shared   static Empty
    >> Domain:Value  00000000002e7e68:0000000002731198 00000000003157a0:0000000002731198 <<
0000000079331630  400009a       14        System.Char[]  0   shared   static WhitespaceChars
    >> Domain:Value  00000000002e7e68:000000000273176c 00000000003157a0:0000000002733938 <<

好,查看一下ProjectIntegrator::Run方法:

   1:          /// <summary>
   2:          /// Main integration loop, intended to be run in its own thread.
   3:          /// </summary>
   4:          private void Run()
   5:          {
   6:              Log.Info("Starting integrator for project: " + project.Name);
   7:              try
   8:              {
   9:                  // loop, until the integrator is stopped
  10:                  while (IsRunning)
  11:                  {
  12:                      try
  13:                      {
  14:                          Integrate();
  15:                      }
  16:                      catch (Exception ex)
  17:                      {
  18:                          Log.Error(ex);
  19:                      }
  20:                      // sleep for a short while, to avoid hammering CPU
  21:                      Thread.Sleep(100);
  22:                  }
  23:              }
  24:              catch (ThreadAbortException)
  25:              {
  26:                  // suppress logging of ThreadAbortException
  27:                  Thread.ResetAbort();
  28:              }
  29:              finally
  30:              {
  31:                  Stopped();
  32:              }
  33:          }
 
To be continued …
posted @ 2009-12-20 23:17  new 维生素C.net()  阅读(1398)  评论(0编辑  收藏  举报