使用 Xcode 调试器查看动态分配的数组? [英] Viewing a dynamically-allocated array with the Xcode debugger?

查看:20
本文介绍了使用 Xcode 调试器查看动态分配的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个 C++ 数组:

Let's say I have an array in C++:

double* velocity = new double[100];

使用 GDB 命令行,我可以通过以下命令查看这个数组:

Using the GDB command line, I can view this array with the command:

> print *velocity @ 100

它会打印出数组中所有双精度值的格式正确的列表.

and it will print a nicely-formatted list of all the double values inside the array.

但是,当使用 Xcode 调试器时,它最多会将其视为指向单个双精度值的指针,并在变量列表中显示 velocity[0].

However, when using the Xcode debugger, the most it will do is treat this as a pointer to a single double value, and display velocity[0] in the variable list.

这使它成为调试包含大型动态分配数组的程序的真正 PITA.必须有某种方法来告诉 Xcode这是一个指向长度为 100 的数组的指针",并让它这样显示.有人知道是什么吗?

This makes it a real PITA to debug programs that contain large dynamically allocated array. There has got to be some way to tell Xcode "This is a pointer to an array of length 100", and have it display the thing as such. Anyone know what it is?

推荐答案

可以使用gdb语法作为表达式:

You can use gdb syntax as expressions:

  1. 使用 Run/Show/Expressions... 菜单显示表达式窗口
  2. 在窗口底部输入'*velocity @ 100'(表达式:)
  1. Use Run/Show/Expressions... menu to show the expressions window
  2. Enter '*velocity @ 100' at the bottom of the window (Expression:)

这篇关于使用 Xcode 调试器查看动态分配的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆