Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Clion's debugger, how do I show the entire contents of an int array

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.

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

like image 857
Embedded_Mugs Avatar asked Oct 30 '16 08:10

Embedded_Mugs


2 Answers

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

(MyType(*)[128])myArray 

Hope this helps!

like image 134
Miguel Alonso Jr Avatar answered Sep 19 '22 09:09

Miguel Alonso Jr


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:

(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:

(MyType[128])*(char*)myArray 
like image 20
cubuspl42 Avatar answered Sep 20 '22 09:09

cubuspl42