Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 311 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
In Clion's debugger, how do I show the entire contents of an int array

#1
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.
Reply

#2
The answer by [cubuspl42][1] 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!

[1]:

[To see links please register here]

Reply

#3
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
Reply

#4
Any syntax understood by the underlying debugger should work, actually. In the case of GDB, for example, you could use `*array@size`, where `array` can be any pointer expression and `size` can be any (positive) integer expression, and both can include variables, function calls, registers, anything that GDB understands. Something like this would be valid, for example:
```
*((int*)$rsp - 0x100)@get_size(data)
```
Reply

#5
I had the same problem today, but instead, I had an array of pointers;


pthread_t** pthreads = (pthread_t**) malloc(//malloc args)
thread_count = 0;

while(thread_count < 10) {
pthread_t* myThread = (pthread_t*) malloc(//malloc args)
pthreads[thread_count] = myThread;
thread_count++;
}

I had trouble seeing the allocation of this memory in CLion gdb because it looked at a pointer to a pointer.

I solved this by targetting the first element of my array (pthreads[0]) and then looking at the next `n` elements from there.

To do this you need to cast the type (pthread_t*[<PLACE NUMBER HERE>]) and then use the target memory, which is pthreads[0] (i.e first element)

Note: I used `calloc` with 0 to set my `pthreads` array. This photo shows how memory was allocated correctly at position 0 in the CLion debugger.


I made this post because none of the posts above led me to the conclusion that I wrote here.

Example: [![clion gdb feature][1]][1]


[1]:
Reply

#6
Unfortunately, CLion doesn't currently support such feature. As suggested [by JetBrains employee][1], 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


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through