在Clion的调试器中,如何显示int数组的全部内容

时间:2022-04-03 07:38:14

Right now it is only showing the first element of the array but I want a visual of all the elements in the array. I think Clion is using GDB.

现在它只显示数组的第一个元素,但我想要显示数组中的所有元素。我认为Clion正在使用GDB。

EDIT: I am referring specifically to arrays on the heap. Arrays on the stack can be visualised.

编辑:我指的是堆上的数组。可以可视化堆栈上的数组。

3 个解决方案

#1


16  

Unfortunately, CLion doesn't currently support such feature. As suggested by JetBrains employee, you can use a workaround. In Evaluate / Watches window use the following expression:

不幸的是,CLion目前不支持此类功能。根据JetBrains员工的建议,您可以使用解决方法。在“评估/监视”窗口中,使用以下表达式:

(MyType[128])myArray

You can use arbitrary array size; whatever works for you.

你可以使用任意数组大小;什么对你有用。

If you array is stored in void * variable, you need to do something more tricky:

如果数组存储在void *变量中,则需要做一些更棘手的事情:

(MyType[128])*(char*)myArray

Please upvote this issue, to increase the chance of getting a real solution. You do this by clicking the tiny thumb-up icon on the right side of the page.

请提出这个问题,以增加获得真正解决方案的机会。您可以通过单击页面右侧的小拇指向上图标来完成此操作。

#2


19  

The answer by cubuspl42 works for GDB. But if you're on a Mac using LLDB as your debugger, the correct method is

cubuspl42的答案适用于GDB。但是如果你使用LLDB作为调试器在Mac上,那么正确的方法是

(MyType(*)[128])myArray

Hope this helps!

希望这可以帮助!

#3


1  

You can use template and reference:

您可以使用模板和参考:

template<int N>
void foo1(int (&arr)[N])
{
    ...
}

If you want to pass the array to other function, the passed function should also use template and reference for array:

如果要将数组传递给其他函数,传递的函数也应该使用数组的模板和引用:

template<int N>
void foo2(int (&arr)[N])
{
    ...
}
template<int N>
void foo1(int (&arr)[N])
{
    foo2(arr);
}

This method allows you to see the entire contents of an int array in clion

此方法允许您在clion中查看int数组的全部内容

#1


16  

Unfortunately, CLion doesn't currently support such feature. As suggested by JetBrains employee, you can use a workaround. In Evaluate / Watches window use the following expression:

不幸的是,CLion目前不支持此类功能。根据JetBrains员工的建议,您可以使用解决方法。在“评估/监视”窗口中,使用以下表达式:

(MyType[128])myArray

You can use arbitrary array size; whatever works for you.

你可以使用任意数组大小;什么对你有用。

If you array is stored in void * variable, you need to do something more tricky:

如果数组存储在void *变量中,则需要做一些更棘手的事情:

(MyType[128])*(char*)myArray

Please upvote this issue, to increase the chance of getting a real solution. You do this by clicking the tiny thumb-up icon on the right side of the page.

请提出这个问题,以增加获得真正解决方案的机会。您可以通过单击页面右侧的小拇指向上图标来完成此操作。

#2


19  

The answer by cubuspl42 works for GDB. But if you're on a Mac using LLDB as your debugger, the correct method is

cubuspl42的答案适用于GDB。但是如果你使用LLDB作为调试器在Mac上,那么正确的方法是

(MyType(*)[128])myArray

Hope this helps!

希望这可以帮助!

#3


1  

You can use template and reference:

您可以使用模板和参考:

template<int N>
void foo1(int (&arr)[N])
{
    ...
}

If you want to pass the array to other function, the passed function should also use template and reference for array:

如果要将数组传递给其他函数,传递的函数也应该使用数组的模板和引用:

template<int N>
void foo2(int (&arr)[N])
{
    ...
}
template<int N>
void foo1(int (&arr)[N])
{
    foo2(arr);
}

This method allows you to see the entire contents of an int array in clion

此方法允许您在clion中查看int数组的全部内容