How to execute a block (identified by pointer) from lldb

可紊 提交于 2019-12-07 17:40:41

问题


I'm in the lldb debugger within the iOS simulator and I have the address for a block. I want to try to execute it. I tried the first thing that came to mind (see below) but it didn't work. Is there a way to do this?

(lldb) po 0x2c7140
(int) $2 = 2912576 <__NSGlobalBlock__: 0x2c7140>
(lldb) po 0x2c7140(NO, @"Test")
error: called object type 'int' is not a function or function pointer

I also tried call but apparently that is not a command in llvm? It was available in gdb.

(lldb) call (void)0x2c7140(NO, @"Test")
error: 'call' is not a valid command.

I realize just now that the first attempt would have failed anyhow since po isn't going to work with a void return value, but the question still stands...


回答1:


You need to cast your number to a block pointer.

expr ((void (^)(BOOL,NSString*))0x2c7140)(NO, @"Test")
       |        |    |          |        |
  Return type  Argument types  Address  Call

(expr is lldb's replacement for call)

I have not actually tested that this works, but have confirmed that lldb recognizes the cast. You may need to split it into two expr commands, one to do the cast and one to do the call:

expr (void (^)(BOOL,NSString*))0x2c7140
expr $n(NO, @"Test")

where $n is the identifier given to the result of the first expression, which will be a part of lldb's output. I believe you can simply use $ to mean "the previous result", but have not tested this.



来源:https://stackoverflow.com/questions/10304090/how-to-execute-a-block-identified-by-pointer-from-lldb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!