如何在 Xcode 控制台中打印反汇编寄存器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7812281/
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-14 22:10:34  来源:igfitidea点击:

How to print disassembly registers in the Xcode console

objective-cxcodegdbdisassembly

提问by Nate

I'm looking at some disassembly code and see something like 0x01c8f09b <+0015> mov 0x8(%edx),%ediand I am wondering what the value of %edxor %ediis.

我正在查看一些反汇编代码并看到类似的东西0x01c8f09b <+0015> mov 0x8(%edx),%edi,我想知道%edxor的价值是什么%edi

Is there a way to print the value of %edxor other assembly variables? Is there a way to print the value at the memory address that %edxpoints at (I'm assuming edxis a register containing a pointer to ... something here).

有没有办法打印%edx或其他程序集变量的值?有没有办法在%edx指向的内存地址处打印值(我假设edx是一个寄存器,其中包含一个指向……某物的指针)。

For example, you can print an objet by typing poin the console, so is there a command or syntax for printing registers/variables in the assembly?

例如,您可以通过po在控制台中键入来打印对象,那么是否有用于打印程序集中寄存器/变量的命令或语法?

Background:

背景:

I'm getting EXC_BAD_ACCESSon this line and I would like to debug what is going on. I'm aware this error is related to memory management and I'm looking at figuring out where I may be missing/too-many retain/release/autorelease calls.

我正在EXC_BAD_ACCESS这条线上,我想调试正在发生的事情。我知道这个错误与内存管理有关,我正在寻找可能丢失/太多保留/释放/自动释放调用的地方。

Additional Info:

附加信息:

This is on IOS, and my application is running in the iPhone simulator.

这是在 IOS 上,我的应用程序在 iPhone 模拟器中运行。

回答by duskwuff -inactive-

You can print a register (e.g, eax) using:

您可以使用以下方法打印寄存器(例如,eax):

print $eax

Or for short:

或者简称:

p $eax

To print it as hexadecimal:

要将其打印为十六进制:

p/x $eax

To display the value pointed to by a register:

显示寄存器指向的值:

x $eax

Check the gdb help for more details:

查看 gdb 帮助以获取更多详细信息:

help print
help x

回答by G Huxley

Depends up which Xcode compiler/debugger you are using. For gcc/gdb it's

取决于您使用的 Xcode 编译器/调试器。对于 gcc/gdb,它是

info registers

but for clang/lldb it's

但对于 clang/lldb 来说

register read

回答by chown

(gdb) info reg
eax            0xe  14
ecx            0x2844e0 2639072
edx            0x285360 2642784
ebx            0x283ff4 2637812
esp            0xbffff350   0xbffff350
ebp            0xbffff368   0xbffff368
esi            0x0  0
edi            0x0  0
eip            0x80483f9    0x80483f9 <main+21>
eflags         0x246    [ PF ZF IF ]
cs             0x73 115
ss             0x7b 123
ds             0x7b 123
es             0x7b 123
fs             0x0  0
gs             0x33 51

From Debugging with gdb:

使用 gdb 调试

You can refer to machine register contents, in expressions, as variables with names starting with `$'. The names of registers are different for each machine; use info registers to see the names used on your machine.

info registers

Print the names and values of all registers except floating-point registers (in the selected stack frame).

info all-registers

Print the names and values of all registers, including floating-point registers.

info registers regname ...

Print the relativized value of each specified register regname. regname may be any register name valid on the machine you are using, with or without the initial `$'.

您可以在表达式中将机器寄存器内容称为名称以“$”开头的变量。每台机器的寄存器名称不同;使用信息寄存器查看您机器上使用的名称。

info registers

打印除浮点寄存器之外的所有寄存器的名称和值(在选定的堆栈帧中)。

info all-registers

打印所有寄存器的名称和值,包括浮点寄存器。

info registers regname ...

打印每个指定寄存器 regname 的相对值。regname 可以是您正在使用的机器上有效的任何寄存器名称,带或不带初始的“$”。

回答by Hola Soy Edu Feliz Navidad

If you are using LLDB instead of GDB you can use register read

如果您使用的是 LLDB 而不是 GDB,您可以使用 register read

回答by Macmade

Those are not variables, but registers.

这些不是变量,而是寄存器。

In GDB, you can see the values of standard registers by using the following command:

在 GDB 中,您可以使用以下命令查看标准寄存器的值:

info registers

Note that a register contains integer values (32bits in your case, as the register name is prefixed by e). What it represent is not known. It can be a pointer, an integer, mostly anything.

请注意,寄存器包含整数值(在您的情况下为 32 位,因为寄存器名称以 为前缀e)。它代表什么尚不得而知。它可以是一个指针,一个整数,几乎任何东西。

If pocrashes when you try to print a register's value as a pointer, it's likely that the value is not a pointer (or an invalid one).

如果po当您尝试将寄存器的值打印为指针时崩溃,则该值很可能不是指针(或无效指针)。