How to print the contents of a memory address using LLDB?

后端 未结 5 1262
一生所求
一生所求 2020-12-22 23:08

I am using LLDB and wondering how to print the contents of a specific memory address, for example 0xb0987654.

5条回答
  •  醉话见心
    2020-12-22 23:40

    Here's a simple trick for displaying typed arrays of fixed-length in lldb. If your program contains a long* variable that points to 9 elements, you can declare a struct type that contains a fixed array of 9 long values and cast the pointer to that type:

    long *values = new long[9]{...};
    
    (lldb) expr typedef struct { long values[9]; } l9; *(l9 *)values
    (l9) $1 = {
      values = {
        [0] = 0
        [1] = 1
        [2] = 4
        [3] = 9
        [4] = 16
        [5] = 25
        [6] = 36
        [7] = 49
        [8] = 64
      }
    }
    

    I use the typedef when I'm coding in C, it's not needed in C++.

提交回复
热议问题