簡體   English   中英

lldb:最派生類型上的條件斷點

[英]lldb: conditional breakpoint on a most derived type

典型的調試模式:

class Button : public MyBaseViewClass
{ 
...
};

....
void MyBaseViewClass::Resized()
{
//<---- here I want to stop in case MyBaseViewClass is really a Button, but not a ScrollBar, Checkbox or something else. I.e. I want a breakpoint condition on a dynamic (most derived) type
}

諸如strstr(typeid(* this).name(),“ Button”)上的斷點之類的簡單方法不起作用,因為在typeid lldb控制台上顯示:

(lldb) p typeid(*this)
error: you need to include <typeinfo> before using the 'typeid' operator
error: 1 errors parsing expression

肯定在呼叫之前#include在控制台中無濟於事

您可以在Python中輕松完成此操作。 設置斷點-說它是斷點1-然后執行以下操作:

(lldb) break command add -s python 1
Enter your Python command(s). Type 'DONE' to end.
def function (frame, bp_loc, internal_dict):
    """frame: the lldb.SBFrame for the location at which you stopped
       bp_loc: an lldb.SBBreakpointLocation for the breakpoint location information
       internal_dict: an LLDB support object not to be used"""
    this_value = frame.FindVariable("this", lldb.eDynamicDontRunTarget) 
    this_type = this_value.GetType().GetPointeeType().GetName() 
    if this_type == "YourClassNameHere": 
        return True 
    return False 
    DONE

這里唯一棘手的一點是,當調用FindVariable時,我傳遞了lldb.eDynamicDontRunTarget ,它告訴lldb獲取變量的“動態”類型,而不是靜態類型。 lldb.eDynamicRunTarget ,我本來也可以使用lldb.eDynamicRunTarget但是我碰巧知道lldb不必運行目標就可以獲取C ++動態類型。

這種解決問題的方法很好,因為您不必使用RTTI即可工作(盡管那樣,我們只能獲得具有某種虛擬方法的類的類型-因為我們使用vtable可以這樣做會比需要在被調試程序中運行代碼的方法更快,因為您的表達式必須這樣做。

順便說一句,如果您喜歡這個技巧,還可以將斷點代碼放入某些python文件中的python函數中(只需復制上面的def),然后使用:

(lldb) command script import my_functions.py
(lldb) breakpoint command add -F my_functions.function

因此您不必繼續重新輸入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM