如何在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 的一般参考。

最新更新