简体   繁体   English

如何使用 LLDB 打印内存地址的内容?

[英]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.这将在调试器中打印。

  1. -s for bytes grouping so use 1 for uint8 for example and 4 for int -s 用于字节分组,例如 uint8 使用 1,int 使用 4
  2. -f for format. -f 格式。 I inherently forget the right symbol.我天生就忘记了正确的符号。 Just put the statement with -f and it will snap back at you and give you the list of all the options只需将语句与 -f 一起放置,它就会回复您并为您提供所有选项的列表
  3. -c is for count of bytes -c 用于字节数
  4. if you are printing more than 1024 bytes, append with --force如果您要打印超过 1024 个字节,请附加 --force

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM