如何在私有接口方法上设置gdb断点

时间:2012-07-28 17:54:25

标签: objective-c gdb

让我们说Apple使用私有框架DictationServices.framework,它具有@interface SODictationPreferences和symbol / method dictationEnabled。如何能够以编程方式在该方法上设置断点(使用ObjectiveC)?

2 个答案:

答案 0 :(得分:0)

以下是如何以非编程方式执行此操作:

root:~/DictationServices.framework$ ps -Afw | grep Preferences
  501 44726 44621   0  7:46PM ??         0:02.60 /Applications/System Preferences.app/Contents/MacOS/System Preferences
// pid of /Applications/System Preferences.app == 44726 
(gdb) attach 44726 
Attaching to process 44726.
Reading symbols for shared libraries + done
Reading symbols for shared libraries +++.+.+.+.+++++++..+++++++ done
Reading symbols for shared libraries + done
0x00007fff8befe686 in mach_msg_trap ()
(gdb) b dictationEnabled
Breakpoint 3 at 0x10e57bc93
(gdb) c
Continuing.
Breakpoint 3, 0x000000010e57bc93 in -[SODictationPreferences dictationEnabled] ()
(gdb) 

答案 1 :(得分:0)

可能是通过ptrace?

 ptrace -- process tracing and debugging

概要      #包括      #include

 int
 ptrace(int request, pid_t pid, caddr_t addr, int data);

说明      ptrace()提供跟踪和调试功能。它允许一个进程(跟踪进程)控制另一个进程(跟踪进程)。