xcode 如何使用lldb在0xb0987654中打印内存?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19748866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:00:14  来源:igfitidea点击:

How to print memory in 0xb0987654 using lldb?

xcodelldb

提问by Adam Lee

I am using LLDB, I am wondering how to print the value in the memory 0xb0987654?

我正在使用 LLDB,我想知道如何打印内存 0xb0987654 中的值?

回答by Eric

Xcode has a very nice Memory Browserwindow, which will very nicely display the contents of memory addresses. It also lets you control byte grouping and number of bytes displayed, and move back or forward a memory page:

Xcode 有一个非常漂亮的Memory Browser窗口,它可以很好地显示内存地址的内容。它还允许您控制字节分组和显示的字节数,以及向后或向前移动内存页面:

enter image description here

在此处输入图片说明

You can access it by pressing ?^??M. After entering it, press enter to open the memory browser in the main editor.

您可以按 访问它?^??M。输入后按回车在主编辑器中打开内存浏览器。

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 中打开内存浏览器?

回答by Khaled Barazi

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
  2. -f for format. 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
  3. -c is for count of bytes
  4. if you are printing more than 1024 bytes, append with --force
  1. -s 用于字节分组,例如 uint8 使用 1,int 使用 4
  2. -f 格式。我天生就忘记了正确的符号。只需将语句与 -f 一起放置,它就会回复您并为您提供所有选项的列表
  3. -c 用于字节数
  4. 如果您要打印超过 1024 个字节,请附加 --force

Hope this helps.

希望这可以帮助。

回答by Michael Dautermann

"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 的文件中。

回答by lbsweek

for example, print memory of length 16x4 bytes.

例如,长度为 16x4 字节的打印内存。

x/16  0xb0987654

回答by Patrick Beard

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:

这是在 lldb 中显示固定长度的类型化数组的一个简单技巧。如果您的程序包含一个指向 9 个元素的 long* 变量,您可以声明一个包含 9 个 long 值的固定数组的结构类型,并将指针强制转换为该类型:

long *values = new long[9]{...};

(lldb) expr typedef struct { long values[9]; } l9; *(l9 *)values
(l9)  = {
  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++ 中不需要它。