Search code examples
androidandroid-ndkandroid-studio-3.0lldbmemoryview

Does Android Studio have an NDK memory viewer?


I am porting a C library code for windows into android

When I create a dynamically allocated array in the NDK C code, the variables viewer window only shows me the address of the first element, and the value of the first element

I would like to see all the array's members in the phone's memory

Is there a memory viewer or something similar for NDK in android studio?

Or as an alternative, can I do some kind of memory dump in the lldb console?


Solution

  • You can print a dynamically allocated int array using LLDB print (in short p) command like below:(modify the size and type according to your own case)

    (lldb) print *(int (*)[5])foo2
    

    It will give output all the elements of the int array. See below screenshot:

    enter image description here

    For a GUI style, you can select Variables tab and add a new watch using similar statement as command line said above, see below screenshot:

    enter image description here

    And then:

    enter image description here

    Unfold the watched statement, you will see all the elements as below:

    enter image description here


    Edit #1

    Using parray command is simpler:

    (lldb) parray 5 foo2
    (int *) $5 = 0x000072e200e2da70 {
      (int) [0] = 20
      (int) [1] = 8
      (int) [2] = 55
      (int) [3] = 6
      (int) [4] = 52
    }