gpt4 book ai didi

c++ - LLDB 数据格式化程序和 C 数组

转载 作者:行者123 更新时间:2023-11-28 04:58:59 26 4
gpt4 key购买 nike

我想为我自己的对象编写一个 LLDB 数据格式化程序,如下所示:

template <typename T, int n>
class StaticArray {
T data_[n];
}

到目前为止,这是我的合成数据格式化程序的样子:

class StaticArrayProvider:
def __init__(self, valobj, internal_dict):
self.valobj = valobj
self.data = self.valobj.GetChildMemberWithName('data_').GetChildAtIndex(0)
self.data_type = self.data.GetType()
self.type_size = self.data_type.GetByteSize()
self.size = # ???

def num_children(self):
return self.size

def get_child_index(self, name):
try:
return int(name.lstrip('[').rstrip(']'))
except:
return -1

def get_child_at_index(self, index):
if index < 0:
return None
if index >= self.num_children():
return None
try:
offset = index * self.type_size
return # ???
except:
return None

我不知道如何填补空白 # ???。你有什么解决办法吗?

最佳答案

在 lldb 值系统中,GetNumChildren 返回静态大小数组的元素数,而 GetChildAtIndex 获取该数组元素。由于每个模板实例 data_ 都是静态大小的数组,因此您的数据格式化程序可以在提供子项时转发 data_。 IE。你可以这样做:

self.data = self.valobj.GetChildMemberWithName('data_')

然后 num_children 只返回 self.data.GetNumChildren()get_child_at_index 返回 self.data.GetChildAtIndex().

您只需要在 lldb 无法为您计算出来时计算偏移量和大小(例如,如果您有一个动态大小的数组或指向您视为数组的类型的指针。)

关于c++ - LLDB 数据格式化程序和 C 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46527634/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com