如何“观看”使用gdb的C ++动态数组? [英] How to "watch" a C++ dynamic array using gdb?

查看:143
本文介绍了如何“观看”使用gdb的C ++动态数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下示例:

int size = 10, *kk = new int[size];

for (int i = 0; i < size; i++) {
    kk[i] = i;
}

delete [] kk;

如何为整个数组添加手表?我可以逐一添加一个手表( kk [0] ,* kk [1] * ...),但是因为我知道数组的长度是有办法自动做吗?我的意思是像 kk [0..size-1] 等。

How can I add a watch for the whole array? I can add a watch one by one (kk[0],*kk[1]*...), but since I know the array's length is there a way to do it automatically? I mean something like kk[0..size-1] or so.

我使用NetBeans IDE和cygwin g ++和gdb。

I'm using NetBeans IDE together with cygwin g++ and gdb.

推荐答案

尝试 display * kk @< size> 从打印命令的文档:

Try display *kk@<size> From the doc for the print command:


@是一个二进制运算符,用于将连续数据对象
处理为内存中的任何位置作为数组。 FOO @ NUM给出一个数组,其第一个
元素是FOO,其第二个元素存储在
之后的空间中,其中存储FOO等。FOO必须是其值
驻留在存储器中的表达式。

@ is a binary operator for treating consecutive data objects anywhere in memory as an array. FOO@NUM gives an array whose first element is FOO, whose second element is stored in the space following where FOO is stored, etc. FOO must be an expression whose value resides in memory.

这篇关于如何“观看”使用gdb的C ++动态数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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