在运行时打印Objective-C方法

时间:2023-01-15 23:06:23

Is it possible to print/log the implementation of a certain class method at runtime to the console screen? I am assuming the log will be in assembly which is fine by me.

是否可以在运行时将某个类方法的实现打印/记录到控制台屏幕?我假设日志将在汇编中,我很好。

1 个解决方案

#1


5  

You could add a breakpoint at the start of the line, step through line by line and call "disassemble" in the debugger:

您可以在行的开头添加断点,逐行逐步调用并在调试器中调用“反汇编”:

One line of my code (with private information replaced) for example produced this:

我的代码中的一行(替换了私有信息)产生了这样的结果:

-(void) method
{
    __weak typeof(self) selfReference = self; // <-- This call was disassembled.
    ...

Project`-[Class method] + 32 at Class.m:176:
-> 0x9c5cc:  ldr    r1, [sp, #304]
0x9c5ce:  add    r0, sp, #296
0x9c5d0:  blx    0x33abec                  ; symbol stub for: objc_initWeak
0x9c5d4:  ldr    r1, [sp, #304]

Edit

I can't verify it's working perfectly since I'm not too handy with assembly, but you can use the debugger (Clang I'm using) to just call

我无法验证它是否正常工作,因为我对组装不太方便,但你可以使用调试器(Clang我正在使用)来调用它

disassemble -n methodName

This claims to

这声称

Disassemble entire contents of the given function name.

反汇编给定函数名的全部内容。

NB: I did this with a breakpoint at the start of the method I was using to test

注意:我在我用来测试的方法开始时用断点做了这个

Try creating a symbolic breakpoint to stop at the method in question:

尝试创建符号断点以停止相关方法:

在运行时打印Objective-C方法

#1


5  

You could add a breakpoint at the start of the line, step through line by line and call "disassemble" in the debugger:

您可以在行的开头添加断点,逐行逐步调用并在调试器中调用“反汇编”:

One line of my code (with private information replaced) for example produced this:

我的代码中的一行(替换了私有信息)产生了这样的结果:

-(void) method
{
    __weak typeof(self) selfReference = self; // <-- This call was disassembled.
    ...

Project`-[Class method] + 32 at Class.m:176:
-> 0x9c5cc:  ldr    r1, [sp, #304]
0x9c5ce:  add    r0, sp, #296
0x9c5d0:  blx    0x33abec                  ; symbol stub for: objc_initWeak
0x9c5d4:  ldr    r1, [sp, #304]

Edit

I can't verify it's working perfectly since I'm not too handy with assembly, but you can use the debugger (Clang I'm using) to just call

我无法验证它是否正常工作,因为我对组装不太方便,但你可以使用调试器(Clang我正在使用)来调用它

disassemble -n methodName

This claims to

这声称

Disassemble entire contents of the given function name.

反汇编给定函数名的全部内容。

NB: I did this with a breakpoint at the start of the method I was using to test

注意:我在我用来测试的方法开始时用断点做了这个

Try creating a symbolic breakpoint to stop at the method in question:

尝试创建符号断点以停止相关方法:

在运行时打印Objective-C方法