如何在调试器中访问 pybind11 array_t<> 数据指针
How to access pybind11 array_t<> data pointer in debugger
我想在进入调试器时访问 pybind11::array_t<T>
类型的 NumPy 数组包装器的数据指针。如下所示,调试器不知道 array_t<T>
的类型,因此 data(...)
/mutable_data(...)
访问器不可用。
(lldb) p o
(pybind11::array_t<unsigned long long, 16>) = {
pybind11::array = {
pybind11::buffer = {
pybind11::object = {
pybind11::handle = (m_ptr = '0x10872fe40')
}
}
}
}
(lldb) p o.data()
error: no member named 'data' in 'pybind11::array_t<unsigned long long, 16>'
(lldb) p o.data(0)
error: no member named 'data' in 'pybind11::array_t<unsigned long long, 16>'
基于pybind11的numpy.h
中array_t::data
的实现,解决方案是使用pybind11::detail::array_proxy
访问数据指针:
(lldb) p ((uint64_t*)pybind11::detail::array_proxy(o.m_ptr)->data)[652]
(uint64_t) = 87112
我想在进入调试器时访问 pybind11::array_t<T>
类型的 NumPy 数组包装器的数据指针。如下所示,调试器不知道 array_t<T>
的类型,因此 data(...)
/mutable_data(...)
访问器不可用。
(lldb) p o
(pybind11::array_t<unsigned long long, 16>) = {
pybind11::array = {
pybind11::buffer = {
pybind11::object = {
pybind11::handle = (m_ptr = '0x10872fe40')
}
}
}
}
(lldb) p o.data()
error: no member named 'data' in 'pybind11::array_t<unsigned long long, 16>'
(lldb) p o.data(0)
error: no member named 'data' in 'pybind11::array_t<unsigned long long, 16>'
基于pybind11的numpy.h
中array_t::data
的实现,解决方案是使用pybind11::detail::array_proxy
访问数据指针:
(lldb) p ((uint64_t*)pybind11::detail::array_proxy(o.m_ptr)->data)[652]
(uint64_t) = 87112