[英]How to print the contents of a memory address using LLDB?
我正在使用 LLDB 并想知道如何打印特定内存地址的内容,例如 0xb0987654。
Xcode has a very nice Memory Browser window, which will very nicely display the contents of memory addresses. Xcode 有一个非常漂亮的Memory Browser窗口,它可以很好地显示内存地址的内容。 It also lets you control byte grouping and number of bytes displayed, and move back or forward a memory page:
它还允许您控制字节分组和显示的字节数,以及向后或向前移动内存页面:
You can access it by pressing ⌘^⌥⇧M
.您可以按
⌘^⌥⇧M
访问它。 After entering it, press enter to open the memory browser in the main editor.输入后按回车在主编辑器中打开内存浏览器。
or或者
Debug --> Debug Workflow --> View Memory调试 --> 调试工作流 --> 查看内存
Notice the field on its bottom left corner where you can paste the memory address you want to inspect!请注意其左下角的字段,您可以在其中粘贴要检查的内存地址!
Documentation here: https://developer.apple.com/library/ios/recipes/xcode_help-debugger/articles/viewing_memory.html此处的文档: https : //developer.apple.com/library/ios/recipes/xcode_help-debugger/articles/viewing_memory.html
Related answer here: How do I open the memory browser in Xcode 4?相关答案在这里: 如何在 Xcode 4 中打开内存浏览器?
To complement Michael's answer.补充迈克尔的回答。
I tend to use:我倾向于使用:
memory read -s1 -fu -c10000 0xb0987654 --force
That will print in the debugger.这将在调试器中打印。
Hope this helps.希望这可以帮助。
" me
" is the command you're looking for. “
me
”是您要查找的命令。
For example, this lldb command:例如,这个 lldb 命令:
me -r -o /tmp/mem.txt -c512 0xb0987654
will copy 512 bytes from your memory address into a file at /tmp/mem.txt.将从您的内存地址复制 512 个字节到 /tmp/mem.txt 的文件中。
例如,长度为 16x4 字节的打印内存。
x/16 0xb0987654
Here's a simple trick for displaying typed arrays of fixed-length in lldb.这是在 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:
如果您的程序包含一个指向 9 个元素的 long* 变量,您可以声明一个包含 9 个 long 值的固定数组的结构类型,并将指针强制转换为该类型:
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++.我在用 C 编码时使用 typedef,在 C++ 中不需要它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.