Release 版本调试错误--VC

 for ( int i = 0; Pos != NULL; i++ )
 {
  str = Dlg.m_StrList.GetNext(Pos);
  
  m_CtrlMulicList.InsertItem( i,  str); 
  m_CtrlMulicList.SetItemText( i , 1, Dlg.m_strRotateCount );  
  m_CtrlMulicList.SetItemText( i , 2, Dlg.m_strPlayData+';'+ Dlg.m_strPlayTime );
 }

上面的源代码 在调试器中的汇编代码为:

下面的汇编代码明显出现了错误, 整个调试过程遇到的问题也非常奇怪.  

 Release 模式的反汇编代码为


   226:  Pos = Dlg.m_StrList.GetHeadPosition() ;
00403AD2 8B 84 24 5C 02 00 00 mov         eax,dword ptr [esp+25Ch]
   227:  
   228:  for ( int i = 0; Pos != NULL; i++ )
00403AD9 3B C5            cmp         eax,ebp
00403ADB 75 69            jne            $LN103+0B7h (403B46h)
   222:  Dlg.DoModal();
   223:
   224:  m_CtrlMulicList.SetRedraw( FALSE );
   225:
   226:  Pos = Dlg.m_StrList.GetHeadPosition() ;
   227:  
   228:  for ( int i = 0; Pos != NULL; i++ )
   229:  {
   230:   str = Dlg.m_StrList.GetNext(Pos);
   231:   
   232:   m_CtrlMulicList.InsertItem( i,  str); 
   233:   m_CtrlMulicList.SetItemText( i , 1, Dlg.m_strRotateCount );  
   234:   m_CtrlMulicList.SetItemText( i , 2, Dlg.m_strPlayData+';'+ Dlg.m_strPlayTime );
   235:  }

   236:
   237:
   238:  m_CtrlMulicList.SetRedraw(TRUE);
00403ADD 8B 8E E8 02 00 00 mov         ecx,dword ptr [esi+2E8h]
00403AE3 6A 00            push        0   
00403AE5 6A 01            push        1   
00403AE7 6A 0B            push        0Bh 
00403AE9 51               push        ecx 
00403AEA FF 15 44 F5 43 00 call        dword ptr [__imp__SendMessageA@16 (43F544h)]
   239: }
00403AF0 8D 4C 24 2C      lea         ecx,[esp+2Ch]
00403AF4 C6 84 24 E0 02 00 00 00 mov         byte ptr [esp+2E0h],0
00403AFC E8 3F 08 00 00   call        CDlgAddMusic::~CDlgAddMusic (404340h)
00403B01 83 C3 F0         add         ebx,0FFFFFFF0h
00403B04 C7 84 24 E0 02 00 00 FF FF FF FF mov         dword ptr [esp+2E0h],0FFFFFFFFh
00403B0F 8D 53 0C         lea         edx,[ebx+0Ch]
00403B12 83 C8 FF         or          eax,0FFFFFFFFh
00403B15 F0 0F C1 02      lock xadd   dword ptr [edx],eax
00403B19 48               dec         eax 
00403B1A 85 C0            test        eax,eax
00403B1C 7F 0A            jg          $LN103+99h (403B28h)
00403B1E 8B 0B            mov         ecx,dword ptr [ebx]
00403B20 8B 11            mov         edx,dword ptr [ecx]
00403B22 8B 42 04         mov         eax,dword ptr [edx+4]
00403B25 53               push        ebx 
00403B26 FF D0            call        eax 
00403B28 8B 8C 24 D8 02 00 00 mov         ecx,dword ptr [esp+2D8h]
00403B2F 64 89 0D 00 00 00 00 mov         dword ptr fs:[0],ecx
00403B36 59               pop         ecx 
00403B37 5F               pop         edi 
00403B38 5E               pop         esi 
00403B39 5D               pop         ebp 
00403B3A 5B               pop         ebx 
00403B3B 81 C4 D0 02 00 00 add         esp,2D0h
00403B41 C3               ret             
   227:  
   228:  for ( int i = 0; Pos != NULL; i++ )
00403B42 8B 44 24 18      mov         eax,dword ptr [esp+18h]
   229:  {
   230:   str = Dlg.m_StrList.GetNext(Pos);
00403B46 85 C0            test        eax,eax
00403B48 0F 84 3A 01 00 00 je          $LN103+1F9h (403C88h)
00403B4E 8B 08            mov         ecx,dword ptr [eax]
00403B50 89 4C 24 18      mov         dword ptr [esp+18h],ecx
00403B54 8B 48 08         mov         ecx,dword ptr [eax+8]
00403B57 8D 41 F0         lea         eax,[ecx-10h]
00403B5A 8D 7B F0         lea         edi,[ebx-10h]
00403B5D 3B C7            cmp         eax,edi
00403B5F 74 51            je          $LN103+123h (403BB2h)
00403B61 83 7F 0C 00      cmp         dword ptr [edi+0Ch],0
00403B65 8D 5F 0C         lea         ebx,[edi+0Ch]
00403B68 7C 36            jl          $LN103+111h (403BA0h)
00403B6A 8B 10            mov         edx,dword ptr [eax]
00403B6C 3B 17            cmp         edx,dword ptr [edi]
00403B6E 75 30            jne         $LN103+111h (403BA0h)
00403B70 50               push        eax 
00403B71 E8 EA 03 00 00   call        ATL::CSimpleStringT<char,0>::CloneData (403F60h)
00403B76 89 44 24 24      mov         dword ptr [esp+24h],eax
00403B7A 83 C4 04         add         esp,4
00403B7D 83 C8 FF         or          eax,0FFFFFFFFh
00403B80 F0 0F C1 03      lock xadd   dword ptr [ebx],eax
00403B84 48               dec         eax 
00403B85 85 C0            test        eax,eax
00403B87 7F 0A            jg          $LN103+104h (403B93h)
00403B89 8B 0F            mov         ecx,dword ptr [edi]
00403B8B 8B 11            mov         edx,dword ptr [ecx]
00403B8D 8B 42 04         mov         eax,dword ptr [edx+4]
00403B90 57               push        edi 
00403B91 FF D0            call        eax 
00403B93 8B 5C 24 20      mov         ebx,dword ptr [esp+20h]
00403B97 83 C3 10         add         ebx,10h
00403B9A 89 5C 24 14      mov         dword ptr [esp+14h],ebx
00403B9E EB 12            jmp         $LN103+123h (403BB2h)
00403BA0 8B 41 F4         mov         eax,dword ptr [ecx-0Ch]
00403BA3 50               push        eax 
00403BA4 51               push        ecx 
00403BA5 8D 4C 24 1C      lea         ecx,[esp+1Ch]
00403BA9 E8 A2 04 00 00   call        ATL::CSimpleStringT<char,0>::SetString (404050h)
00403BAE 8B 5C 24 14      mov         ebx,dword ptr [esp+14h]
   216:
   217:
   218:  CString str;
   219:  POSITION Pos;
   220:
   221:  CDlgAddMusic Dlg;
   222:  Dlg.DoModal();
   223:
   224:  m_CtrlMulicList.SetRedraw( FALSE );
   225:
   226:  Pos = Dlg.m_StrList.GetHeadPosition() ;
   227:  
   228:  for ( int i = 0; Pos != NULL; i++ )
   229:  {
   230:   str = Dlg.m_StrList.GetNext(Pos);

   231:   
   232:   m_CtrlMulicList.InsertItem( i,  str); 
00403BB2 6A 00            push        0   
00403BB4 6A 00            push        0   
00403BB6 6A 00            push        0   
00403BB8 6A 00            push        0   
00403BBA 53               push        ebx 
00403BBB 55               push        ebp 
00403BBC 81 C6 C8 02 00 00 add         esi,2C8h
00403BC2 6A 01            push        1   
00403BC4 8B CE            mov         ecx,esi
00403BC6 E8 5A 1F 01 00   call        CListCtrl::InsertItem (415B25h)
   233:   m_CtrlMulicList.SetItemText( i , 1, Dlg.m_strRotateCount );  
00403BCB 8B 8C 24 74 02 00 00 mov         ecx,dword ptr [esp+274h]
00403BD2 51               push        ecx 
00403BD3 6A 01            push        1   
00403BD5 55               push        ebp 
00403BD6 8B CE            mov         ecx,esi
00403BD8 E8 E3 1D 01 00   call        CListCtrl::SetItemText (4159C0h)
   234:   m_CtrlMulicList.SetItemText( i , 2, Dlg.m_strPlayData+';'+ Dlg.m_strPlayTime );
00403BDD 8D 54 24 24      lea         edx,[esp+24h]
00403BE1 52               push        edx 
00403BE2 8D BC 24 80 02 00 00 lea         edi,[esp+280h]
00403BE9 E8 E2 01 00 00   call        ATL::operator+ (403DD0h)
00403BEE 8D 8C 24 7C 02 00 00 lea         ecx,[esp+27Ch]
00403BF5 51               push        ecx 
00403BF6 50               push        eax 
00403BF7 8D 54 24 34      lea         edx,[esp+34h]
00403BFB 52               push        edx 
00403BFC C6 84 24 F0 02 00 00 02 mov         byte ptr [esp+2F0h],2
00403C04 E8 07 01 00 00   call        ATL::operator+ (403D10h)
00403C09 83 C4 10         add         esp,10h
00403C0C C6 84 24 E0 02 00 00 03 mov         byte ptr [esp+2E0h],3
00403C14 8B 00            mov         eax,dword ptr [eax]
00403C16 50               push        eax 
00403C17 6A 02            push        2   
00403C19 55               push        ebp 
00403C1A 8B CE            mov         ecx,esi
00403C1C E8 9F 1D 01 00   call        CListCtrl::SetItemText (4159C0h)
00403C21 C6 84 24 E0 02 00 00 02 mov         byte ptr [esp+2E0h],2
00403C29 8B 44 24 28      mov         eax,dword ptr [esp+28h]
00403C2D 83 C0 F0         add         eax,0FFFFFFF0h
00403C30 8D 48 0C         lea         ecx,[eax+0Ch]
00403C33 83 CA FF         or          edx,0FFFFFFFFh
00403C36 F0 0F C1 11      lock xadd   dword ptr [ecx],edx
00403C3A 4A               dec         edx 
00403C3B 85 D2            test        edx,edx
00403C3D 7F 0A            jg          $LN103+1BAh (403C49h)
00403C3F 8B 08            mov         ecx,dword ptr [eax]
00403C41 8B 11            mov         edx,dword ptr [ecx]
00403C43 50               push        eax 
00403C44 8B 42 04         mov         eax,dword ptr [edx+4]
00403C47 FF D0            call        eax 
00403C49 C6 84 24 E0 02 00 00 01 mov         byte ptr [esp+2E0h],1
00403C51 8B 44 24 24      mov         eax,dword ptr [esp+24h]
00403C55 83 C0 F0         add         eax,0FFFFFFF0h
00403C58 8D 48 0C         lea         ecx,[eax+0Ch]
00403C5B 83 CA FF         or          edx,0FFFFFFFFh
00403C5E F0 0F C1 11      lock xadd   dword ptr [ecx],edx
00403C62 4A               dec         edx 
00403C63 85 D2            test        edx,edx
00403C65 7F 0A            jg          $LN103+1E2h (403C71h)
00403C67 8B 08            mov         ecx,dword ptr [eax]
00403C69 8B 11            mov         edx,dword ptr [ecx]
00403C6B 50               push        eax 
00403C6C 8B 42 04         mov         eax,dword ptr [edx+4]
00403C6F FF D0            call        eax 
00403C71 8B 74 24 1C      mov         esi,dword ptr [esp+1Ch]
00403C75 83 C5 01         add         ebp,1
00403C78 83 7C 24 18 00   cmp         dword ptr [esp+18h],0
00403C7D 0F 85 BF FE FF FF jne         $LN103+0B3h (403B42h)
   229:  {
   230:   str = Dlg.m_StrList.GetNext(Pos);
00403C83 E9 55 FE FF FF   jmp         $LN103+4Eh (403ADDh)
00403C88 E9 09 1C 01 00   jmp         AfxThrowInvalidArgException (415896h)

Debug 模式的反汇编代码为


下面的汇编代码是在 debug 模式下调试提取, 同样源代码的反汇编代码在 debug 和 release 模式下确实不同。


   227:  
   228:  for ( int i = 0; Pos != NULL; i++ )
00505F1B C7 85 14 FD FF FF 00 00 00 00 mov         dword ptr [i],0
00505F25 EB 0F            jmp         CDialogMusicList::OnBnClickedButMusiclistAdd+0A6h (505F36h)
00505F27 8B 85 14 FD FF FF mov         eax,dword ptr [i]
00505F2D 83 C0 01         add         eax,1
00505F30 89 85 14 FD FF FF mov         dword ptr [i],eax
00505F36 83 7D D4 00      cmp         dword ptr [ebp-2Ch],0
00505F3A 0F 84 00 01 00 00 je          CDialogMusicList::OnBnClickedButMusiclistAdd+1B0h (506040h)
   229:  {
   230:   str = Dlg.m_StrList.GetNext(Pos);
00505F40 8D 45 D4         lea         eax,[ebp-2Ch]
00505F43 50               push        eax 
00505F44 8D 8D 4C FF FF FF lea         ecx,[ebp-0B4h]
00505F4A E8 74 3A FE FF   call        CStringList::GetNext (4E99C3h)
00505F4F 50               push        eax 
00505F50 8D 4D E0         lea         ecx,[ebp-20h]
00505F53 E8 9F 33 FE FF   call        ATL::CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> > >::operator= (4E92F7h)
   231:   
   232:   m_CtrlMulicList.InsertItem( i,  str); 
00505F58 8D 4D E0         lea         ecx,[ebp-20h]
00505F5B E8 C7 76 FE FF   call        ATL::CSimpleStringT<char,0>::operator char const * (4ED627h)
00505F60 50               push        eax 
00505F61 8B 85 14 FD FF FF mov         eax,dword ptr [i]
00505F67 50               push        eax 
00505F68 8B 4D EC         mov         ecx,dword ptr [ebp-14h]
00505F6B 81 C1 C8 02 00 00 add         ecx,2C8h
00505F71 E8 89 94 FE FF   call        CListCtrl::InsertItem (4EF3FFh)
   233:   m_CtrlMulicList.SetItemText( i , 1, Dlg.m_strRotateCount );  
00505F76 8D 8D 68 FF FF FF lea         ecx,[ebp-98h]
00505F7C E8 A6 76 FE FF   call        ATL::CSimpleStringT<char,0>::operator char const * (4ED627h)
00505F81 50               push        eax 
00505F82 6A 01            push        1   
00505F84 8B 85 14 FD FF FF mov         eax,dword ptr [i]
00505F8A 50               push        eax 
00505F8B 8B 4D EC         mov         ecx,dword ptr [ebp-14h]
00505F8E 81 C1 C8 02 00 00 add         ecx,2C8h
00505F94 E8 8C E1 FE FF   call        CListCtrl::SetItemText (4F4125h)
   234:   m_CtrlMulicList.SetItemText( i , 2, Dlg.m_strPlayData+';'+ Dlg.m_strPlayTime );
00505F99 8D 85 6C FF FF FF lea         eax,[ebp-94h]
00505F9F 50               push        eax 
00505FA0 6A 3B            push        3Bh 
00505FA2 8D 8D 70 FF FF FF lea         ecx,[ebp-90h]
00505FA8 51               push        ecx 
00505FA9 8D 95 3C FC FF FF lea         edx,[ebp-3C4h]
00505FAF 52               push        edx 
00505FB0 E8 97 51 FE FF   call        ATL::operator+ (4EB14Ch)
00505FB5 83 C4 0C         add         esp,0Ch
00505FB8 89 85 34 FC FF FF mov         dword ptr [ebp-3CCh],eax
00505FBE 8B 85 34 FC FF FF mov         eax,dword ptr [ebp-3CCh]
00505FC4 89 85 30 FC FF FF mov         dword ptr [ebp-3D0h],eax
00505FCA C6 45 FC 02      mov         byte ptr [ebp-4],2
00505FCE 8B 8D 30 FC FF FF mov         ecx,dword ptr [ebp-3D0h]
00505FD4 51               push        ecx 
00505FD5 8D 95 48 FC FF FF lea         edx,[ebp-3B8h]
00505FDB 52               push        edx 
00505FDC E8 27 4A FE FF   call        ATL::operator+ (4EAA08h)
00505FE1 83 C4 0C         add         esp,0Ch
00505FE4 89 85 2C FC FF FF mov         dword ptr [ebp-3D4h],eax
00505FEA 8B 85 2C FC FF FF mov         eax,dword ptr [ebp-3D4h]
00505FF0 89 85 28 FC FF FF mov         dword ptr [ebp-3D8h],eax
00505FF6 C6 45 FC 03      mov         byte ptr [ebp-4],3
00505FFA 8B 8D 28 FC FF FF mov         ecx,dword ptr [ebp-3D8h]
00506000 E8 22 76 FE FF   call        ATL::CSimpleStringT<char,0>::operator char const * (4ED627h)
00506005 50               push        eax 
00506006 6A 02            push        2   
00506008 8B 8D 14 FD FF FF mov         ecx,dword ptr [i]
0050600E 51               push        ecx 
0050600F 8B 4D EC         mov         ecx,dword ptr [ebp-14h]
00506012 81 C1 C8 02 00 00 add         ecx,2C8h
00506018 E8 08 E1 FE FF   call        CListCtrl::SetItemText (4F4125h)
0050601D C6 45 FC 02      mov         byte ptr [ebp-4],2
00506021 8D 8D 48 FC FF FF lea         ecx,[ebp-3B8h]
00506027 E8 FE 6D FE FF   call        ATL::CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> > >::~CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> > > (4ECE2Ah)
0050602C C6 45 FC 01      mov         byte ptr [ebp-4],1
00506030 8D 8D 3C FC FF FF lea         ecx,[ebp-3C4h]
00506036 E8 EF 6D FE FF   call        ATL::CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> > >::~CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> > > (4ECE2Ah)
   235:  }
0050603B E9 E7 FE FF FF   jmp         CDialogMusicList::OnBnClickedButMusiclistAdd+97h (505F27h)
   236:
   237:
   238:  m_CtrlMulicList.SetRedraw(TRUE);
00506040 6A 01            push        1   
00506042 8B 4D EC         mov         ecx,dword ptr [ebp-14h]
00506045 81 C1 C8 02 00 00 add         ecx,2C8h
0050604B E8 33 6F FE FF   call        CWnd::SetRedraw (4ECF83h)
   239: }

这是在 Realse 模式下调试程序 不是在Debug 模式下调试程序.

从上面2种模式的反汇编代码可以看出,      debug 模式下每条源代码都有对应的汇编代码且正确,   Release 模式却出现了混乱。

可能原因: 
      (1)里面缺少了调试信息致使调试程序出错
      (2) Release 模式下对代码进行了优化,不能和源代码相对应。

我想出错的原因最有可能是 编译器对代码进行了优化 . 使当前源代码后不再有相应的汇编代码.

你可能感兴趣的:(Release 版本调试错误--VC)