@JimIngham 的回答非常好。下面的示例说明了一些其他有用的命令和 Jim 的回答。目的是强调如何处理衰减为指针的 C 数组。
void foo_void ( float *input )
{
printf("Pointer: %p.\n", input); <-- breakpoint here
}
int main ( void ) {
float tiny_array[4];
tiny_array[0] = 1.0;
tiny_array[1] = 2.0;
tiny_array[2] = 3.0;
tiny_array[3] = 4.0;
foo_void ( tiny_array );
return 0;
}
LLDB-Python指令:
(lldb) fr v -L
0x00007ffeefbff4c8: (float *) input = 0x00007ffeefbff4f0
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()'.
>>> ptr = lldb.frame.FindVariable('input')
>>> print(ptr.GetValue())
0x00007ffeefbff4f0
>>> ptr_type = ptr.GetType().GetPointeeType()
>>> print(ptr_type)
float
>>> ptr_size_type = ptr_type.GetByteSize()
>>> print(ptr_size_type)
4
>>> for i in range (0, 4):
... offset = ptr.GetValueAsUnsigned() + i * ptr_size_type
... val = lldb.target.CreateValueFromAddress("temp", lldb.SBAddress(offset, lldb.target), ptr_type)
... print(offset, val.GetValue())
...
(140732920755440, '1')
(140732920755444, '2')
(140732920755448, '3')
(140732920755452, '4')