C++ lldb:最派生类型上的条件断点

C++ lldb:最派生类型上的条件断点,c++,xcode,lldb,C++,Xcode,Lldb,典型的调试模式: 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 cond

典型的调试模式:

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
}
class按钮:公共MyBaseViewClass
{ 
...
};
....
void MyBaseViewClass::Resized()
{

// 在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.edDynamicDonTruntTarget
,它告诉lldb获取“动态”变量的类型,而不是静态类型。作为一个补充,我也可以使用<代码> LLDB.EdyAmiCiRunTale< /Cord>。但是我碰巧知道LLDB不必运行目标GO获取C++动态类型。 这种解决问题的方法很好,因为您不必使用RTTI来工作(尽管这样,我们只能获得具有某种虚拟方法的类的类型,因为我们使用vtable来实现这一神奇的功能)它也比需要在被调试对象中运行代码的方法要快,因为您的表达式必须这样做

顺便说一句,如果您喜欢这个技巧,还可以将断点代码放入某个python文件中的python函数中(只需复制上面的def),然后使用:

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

因此,您不必一直重新键入它。

很高兴通过python获得支持,但我想这类东西应该真正嵌入到调试器本身中。请使用lldb.llvm.org的bug tracker或提交一个bug请求。有没有一种方便的方法可以将附加参数传递给上面的my_functions.function?显然,我可以包装c好的,但是写太多的代码会有味道,理想情况下应该是:>breakpoint命令add-F my_functions.function yourclassname这里应该作为第四个参数或在这个内部命令中
(lldb) command script import my_functions.py
(lldb) breakpoint command add -F my_functions.function