2011-09-02 79 views
4

我試圖調試崩潰。 (ACCESS_VIOLATION)分析崩潰 - 將反彙編指令翻譯爲C++等效

下面是一個反彙編代碼片段。我標記了發生異常的行。 它對應於下面顯示的實際C++代碼中的那條指令嗎?

拆卸:

420: for(Uint32 i = 0; i < m_children.size(); ++i){ 
    06A923D3 8B 46 0C    mov   eax,dword ptr [esi+0Ch] 
    06A923D6 57     push  edi 
    06A923D7 33 FF    xor   edi,edi 
--> 06A923D9 39 38    cmp   dword ptr [eax],edi 
    06A923DB 76 59    jbe   ICategoryNode::iterate+66h (6A92436h) 
    06A923DD 53     push  ebx 
    06A923DE 55     push  ebp 
    06A923DF 8B 2D 04 60 B0 06 mov   ebp,dword ptr [__imp_::AssertionFailure::logAssert (6B06004h)] 
    06A923E5 33 DB    xor   ebx,ebx 
421: bool keepGoing = CategoryImp::recursiveIterator(handler, *m_children[i]); 

實際C++代碼:

void ICategoryNode::iterate(ICategoryHandler& handler) const { 
    for(Uint32 i = 0; i < m_children.size(); ++i) { 
     bool keepGoing = CategoryImp::recursiveIterator(handler, *m_children[i]); 
     if(!keepGoing) 
      return; 
    } 
} 

回答

8

貌似cmp dword ptr [eax],edi對應於<尺寸()檢查 - 注意,大小部件的非關聯化內聯到小於支票。

很可能,您的this指針無效。您可能調用了空指針或刪除對象或其他東西(如果eax的值非常低,它可能是一個空指針,但在任何情況下,檢查上面的堆棧框架,你應該能夠得到被調用對象的錯誤地址)。

+0

您是否暗示'this'必須爲空,因爲使用'm_children'會導致異常?我編輯了代碼以明確它已經進入成員函數的事實(因此'this'是有效的)。 –

+0

不,我的意思是'這個'是無效的。即,你調用了'ptr-> iterate(something)',其中'ptr'爲NULL,或者未初始化,或者已經被刪除,否則無效。 m_children不是一個指針,所以它不能爲NULL。 – bdonlan

+0

@dominus:你爲什麼聲稱'this'只有在你進入成員函數時纔有效?成員函數是虛擬的嗎?如果沒有,你沒有理由相信你的'this'指針。我同意bdonlan。 – TonyK