Reputation: 44310
I have a breakpoint action and am using the Log option from the drop down. I'd like to print out the string (summary) value. I'm doing this:
the person name is: @p.name@
but that prints the memory address. I can switch to the Debugger Command option and do
po f.name
but then I lose my description, as used in the first option. Using the Log option, is there a way to print the string value and not the memory address?
Upvotes: 25
Views: 18072
Reputation: 2698
For Swift and Xcode 12.2 you can double click on the breakpoint and use Debugger Command
as an action and as a command whatever you usually time on the debugger.
In the example I use po
with a string as param (to avoid printing the memory address) which contains the values I am debugging. I also enable Automatically continue...
to avoid stopping the execution.
You can also add other text or other variables.
A thing to keep in mind though, running these takes some time, so for operations where timing is important, these are not good.
Upvotes: 1
Reputation: 7900
You don't need TWO actions in the breakpoint, you can just have ONE command (log message), where you put the message including the content of variables (see image). By clicking "automatically continues" it is just acting like having a print-command in code, but the good thing is, then you dont have print statements in your code.
Upvotes: 0
Reputation: 3091
Here is a solution using only one action, and using fewer characters than the expr
solution.
However, unless you add the void
like this:
po (void)NSLog(@"the person name is: %@", p.name)
you will get an annoying "nil" printed out with your log. for example:
(lldb) po NSLog(@"foo")
nil
2013-06-19 14:42:59.025 TheMove[95864:c07] foo
(lldb) po (void)NSLog(@"foo")
2013-06-19 14:43:10.758 TheMove[95864:c07] foo
If you can live with the nil (I can) it's faster to type and easier to remember just the po
Upvotes: 8
Reputation: 9579
You can use NSLog statements with breakpoints using "Debugger Command", but you need to add "expr"
expr (void)NSLog(@"The Person Name is %@", p.name)
-
Upvotes: 28
Reputation: 3704
I ended up using 2 different actions for the same breakpoint. First a Log and then a debugger command with po varName. Only downside it will print in 2 different rows.
Upvotes: 5
Reputation: 78353
There are a couple of things you can do. Add a Log function from the drop-down, then add another box and select Debugger Command
and enter po f.name
.
If you want your log to be more complicated, you could do something more like this:
the person name is: @(const char *)[(NSString*)[p.name description] UTF8String]@
You best bet is probably to just use the debugger's graphical interface to watch variables. If you want to log messages, use NSLog
.
Upvotes: 20