0

enter image description here

For example, if I want to know the return of [NSKeyedArchiver archiveRootObject:self.privateItems toFile:[self.itemArchPath absoluteString]];

What could I do ?

1
  • po [NSKeyedArchiver archiveRootObject:self.privateItems toFile:[self.itemArchPath absoluteString]] should return the bool result of the save but that would save again. If you wanted to see the result after the save (above your breakpoint), I think you'd need to capture the result somehow as: BOOL saveResult = [NSKeyedArchiver archiveRootObject:self.privateItems toFile:[self.itemArchPath absoluteString]] Commented Dec 17, 2015 at 16:02

3 Answers 3

3

In lldb and in Xcode, if you "step-out" of some function, when the step-out completes, we'll show the return value of the function you just left.

In Xcode, on stop after step out, the first element of the Locals view (called "Return Value") will be the return value of the function you just stepped out of.

If you are in command-line lldb the same thing will show up in the thread part of the stop printing:

(lldb) fin
Process 43838 stopped
* thread #1: tid = 0x849c80, 0x0000000100000f5b SimpleStepOut`main(argc=1, argv=0x00007fff5fbff5b8) + 27 at main.c:18, queue = 'com.apple.main-thread', stop reason = step out
Return value: (int) $0 = 5

    frame #0: 0x0000000100000f5b SimpleStepOut`main(argc=1, argv=0x00007fff5fbff5b8) + 27 at main.c:18
   15   
   16   int main(int argc, const char * argv[]) {
   17       // insert code here...
-> 18       printf("Hello, World - %d!\n", return_five());
   19       return 0;
   20   }

Note, if you've customized your frame-format, you may not have this element, it's thread.return-value.

It's a little harder to do this when a "step in/out" happens to step out of the function, so for now it only works if you leave the function by stepping out.

Sign up to request clarification or add additional context in comments.

1 Comment

BTW, since the function you want to know the return value of has no debug information, we won't know the return type. You can fix that - if you are using Xcode 7.x, by running the lldb command "expr @import Foundation". Also lldb by default won't "step in" to functions with no debug info, you'll have to use the lldb command "step -a false" to step in.
2

If you want to see the result of [NSKeyedArchiver archiveRootObject:self.privateItems toFile:[self.itemArchPath absoluteString]] you could just wrap its result in a simple conditional statement and print a message: that method returns a boolean, so it's either true or false.

Example:

bool result = [NSKeyedArchiver archiveRootObject:self.privateItems toFile:[self.itemArchPath absoluteString]];
if (result) {
    NSLog(@"It worked!");
} else {
    NSLog(@"It failed!");
}

If you mean you want to check what was saved, then you should probably either print the path you saved to and look at it in on your Mac (if you're using the simulator) or try re-loading the object to make sure it matches what you expected.

2 Comments

Is there any advanced or elegant way to do this? I thought xcode has something like visual studio or p @eax could work.
Well, you can place a breakpoint after the bool result line then inspect the contents using p result, but make sure the scope doesn't end (i.e., put int meh = 10 or something after just to be sure) otherwise Xcode might lose track of the value. There aren't many advanced ways to view a boolean :)
1

TwoStraws answer is correct.

If, however, you are looking to find the return value (result in TwoStraws's answer) while debugging and only while debugging, you can step into the call to archiveRootObject:toFile: and then hit F8. That'll step out of the function and (usually) include a pseudo-local variable named "return" that will hold the return value from the call.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.