lldb - 如何在 lldb 中打印一系列 std::vector 元素?
问题描述
如何在 lldb 中打印 std::vector 中介于 1000 - 1073 之间的条目。
例如在以下代码中:
1
2 #include <numeric>
3 #include <vector>
4
5 using namespace std;
6
7 int main() {
8 vector<int> v(100000);
9 std::iota(v.begin(), v.end(), 3);
-> 10 return 0;
11 }
(lldb)
我想看看 v[1000] - v[1073] 中有什么
解决方案
lldb 变量打印中没有子范围运算符。但是您可以使用 Python API 非常简单地完成这类事情。例如:
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> for i in range(2,6):
... print(lldb.frame.GetValueForVariablePath("int_vec[%d]"%(i)))
...
(int) [2] = 3
(int) [3] = 4
(int) [4] = 5
(int) [5] = 6
您也可以编写一个小命令来轻松完成此操作。看:
https://lldb.llvm.org/use/python-reference.html#create-a-new-lldb-command-using-a-python-function
有关这样做的详细信息,以及:
https://lldb.llvm.org/python_reference/index.html
对 Python API 的一般参考。
推荐阅读
- react-native - 捕捉反应原生警告
- excel - 使用VBA循环从a到C的终端值
- c# - 用于闪烁图像的 Unity 3d Invokerepeating
- xaml - 如何在 Xamarin iOS、Android 中以 Xamarin 形式设计以下网格视图
- python - Keras CNN 问题
- reactjs - 功能组件的钩子中的生命周期转换
- linux - 仅删除目录和子目录中的文件
- ios - 多个 SwiftUI 视图共享数据成员
- azure - AzureDevOps+Terraform - 创建代理作业和作业任务
- elasticsearch - Elastic Search Get index API 以获取超过 30 天的索引