在 xcode C++ (lldb) 中查看动态数组的内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19328996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
view contents of a dynamic array in xcode C++ (lldb)
提问by user1673892
How to view the contents of a dynamically created array in xcode debugger (C++)?
如何在 xcode 调试器 (C++) 中查看动态创建的数组的内容?
int main(int argc, const char * argv[])
{
int *v;
int size;
cout << "Enter array size" << endl;
cin >> size;
v = new int [size];
for (int i=0; i<size; i++){
cin >> v [size];
}
// see array contents
return 0;
}
I want to view contents of v.
我想查看 v 的内容。
回答by Jim Ingham
We didn't add some syntax in the expression parser like the gdb "@" syntax because we want to keep the language syntax as close to C/ObjC/C++ as possible. Instead, since the task you want to perform is "read some memory as an array of N elements of type T", you would do this using:
我们没有在表达式解析器中添加一些语法,如 gdb "@" 语法,因为我们希望保持语言语法尽可能接近 C/ObjC/C++。相反,由于您要执行的任务是“将一些内存读取为 T 类型的 N 个元素的数组”,因此您可以使用:
(lldb) memory read -t int -c `size` v
(lldb) 内存读取 -t int -c `size` v
In general, -t tells the type, and -c the number of elements, and I'm using the fact that option values in back ticks are evaluated as expressions and the result substituted into the option.
通常,-t 表示类型,-c 表示元素的数量,我使用的事实是,反勾号中的选项值被评估为表达式,并将结果替换到选项中。
回答by Nyon
There is a better answer over at another thread.
在另一个线程中有一个更好的答案。
https://stackoverflow.com/a/26303375/767039
https://stackoverflow.com/a/26303375/767039
I think this is easier to use and remember.
我认为这更容易使用和记住。