Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Say command on a breakpoint in Xcode

Tags:

xcode

I am using Xcode and would like to set a breakpoint that speaks an NSString from my code. What I am doing is setting the breakpoint, then editing it. I add a "Shell Command" action. The first argument is say and the second argument is where i'm having trouble.

 NSString *myString = @"This is a test";

If I put @myString@ as the second argument, it reads out the memory address. ex. 0x0b4be130

If I try @[myString UTF8String], it gives me a another memory address.

If I dereference myString, @*[myString UTF8String]@, it only gives me the first character of the string.

How do I do this properly?

like image 215
ohnit Avatar asked Aug 19 '13 17:08

ohnit


1 Answers

LLDB actually has an inbuilt Python interpreter, with the entire LLDB library exposed to it. You can access this with the script debugger command. With this, we can more easily grab a string representation of a variable in the frame, and send it to the OS say command. Add a debugger action:

script os.system("say " + lldb.frame.GetValueForVariablePath("myVariable").description)

to achieve what you want. You can even wrap up Python scripts as new LLDB "commands", so you can create a debugger command called say that explicitly says the underlying objects description; have a look at http://lldb.llvm.org/python-reference.html for an introduction on setting these type of scripts up.

like image 142
Adam Wright Avatar answered Dec 28 '22 18:12

Adam Wright