0

我有一个自定义 C++ 容器类型,并希望更改 Xcode 变量视图中的外观方式。需要做一些类似的方式NSArray或者std::vector看看那里。

到目前为止,a 只能将摘要字符串更改为输出容器大小,并且不知道如何将容器的子项排列在具有索引的树中。默认视图输出容器 ivars。

是否可以使用 LLDB Python 脚本在树中输出容器子项?

4

1 回答 1

0

是的,确实如此。

您正在寻找的功能称为“合成子代”,它本质上涉及将 Python 类绑定到您的数据类型。然后,当需要出售子对象(容器中的元素)时,LLDB 将继续询问您的类,而不是像当前那样信任调试信息。稍有不同 [1] 这与 LLDB 对 NSArray、std::vector 和其他几个所做的相同

[1] 著名系统类型的合成子提供程序是用 C++ 编写的,并且是 LLDB 核心的一部分,主要是出于性能原因

为了滚动你自己的,你需要实现一个遵守这个规范的类:

class SyntheticChildrenProvider:
    def __init__(self, valobj, internal_dict):
        this call should initialize the Python object using valobj as the variable to provide synthetic children for 
    def num_children(self): 
        this call should return the number of children that you want your object to have 
    def get_child_index(self,name): 
        this call should return the index of the synthetic child whose name is given as argument 
    def get_child_at_index(self,index): 
        this call should return a new LLDB SBValue object representing the child at the index given as argument 
    def update(self): 
        this call should be used to update the internal state of this Python object whenever the state of the variables in LLDB changes.[1]
    def has_children(self): 
        this call should return True if this object might have children, and False if this object can be guaranteed not to have children.[2]

[1] 此方法是可选的。此外,它可以选择返回一个值(从 SVN rev153061/LLDB-134 开始)。如果它返回一个值,并且该值为 True,LLDB 将被允许缓存其先前获得的子项和子项计数,并且不会返回提供程序类询问。如果没有返回任何内容、None 或 True 以外的任何内容,LLDB 将丢弃缓存的信息并询问。无论如何,必要时 LLDB 将调用更新。[2] 此方法是可选的(从 SVN rev166495/LLDB-175 开始)。虽然根据 num_children 实现它是可以接受的,但鼓励实现者在合理的情况下寻找优化的编码替代方案。

详细信息位于http://lldb.llvm.org/varformats.html,包括指向几个示例实现的链接,您可以将其用作起点。

如果您有任何其他问题或需要更多指导,请随时回复!

于 2013-10-01T17:22:09.233 回答