Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

macos - lldb objc_msgSend tracing on OS X

I'm tracing a OS X application, I hope can find a way like this way on iOS:

lldb Xcode: error: 'printf' is not a valid command

Is there a way to do like this? I tried

expr -- (void)printf("[%s, %s]
",(char *) object_getClassName(*(long*)($esp+4)), (char *) *(long *)($esp+8) )

I think OS X is used 64bit registers. So this command cann't work(Indeed, it doesn't work). How should I write this command? Or there is a simple way to do the same? Just tracing the class and method called

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The command you quote above is only correct for iOS Simulator apps which run as i386 processes on the Mac. $esp+4 means the first argument, $esp+8 means the second argument passed in the i386 ABI. On x86_64 and arm, the first few arguments are passed in registers with the $arg1, $arg2 convenience names. So try

p (void)printf("[%s, %s]
", (char*)object_getClassName($arg1), $arg2)

for arm/x86_64 architectures. (of course, p is an alias for expr -- here - same thing, just less typing.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...