You can evaluate an Objective-C expression in a Swift frame by overriding the 
default language like so:

(lldb) expr -fx --language=objc++ -- $rax
(unsigned long) $0 = 0x00006080000c2ca0

… and then set a conditional breakpoint on free that tests the first argument 
to see if it matches:

(lldb) breakpoint set -n free -c "$arg1 == 0x00006080000c2ca0”

Of course this will slow down calls to free dramatically so you may need to be 
rather patient if there’s a lot of heap activity between setting the breakpoint 
and freeing the pointer you’re looking for.  I don’t think watchpoints are 
going to do you much good here because freeing an allocation doesn’t change the 
allocated memory, just the bookkeeping in malloc’s internal data structures.

Kate Stone [email protected] <mailto:[email protected]>
 Xcode Runtime Analysis Tools

> On May 23, 2015, at 12:37 PM, Jens Alfke <[email protected]> wrote:
> 
> I’m going nuts trying to debug a crash in which an object gets dealloced 
> prematurely (but enabling zombies doesn’t help, i.e. the object is freed 
> regardless, not turned into a zombie.) I’m trying to set a watchpoint on the 
> object’s memory to see what’s freeing it, but I can’t figure out how to do 
> it. 
> 
> Part of the problem is the object never appears as a named variable, only in 
> a register (it’s a temporary string created by the runtime function 
> swift_convertStringToNSString, apparently.)  At the breakpoint I’m at, the 
> object is pointed to by register rax, whose value I can see in the debugger 
> inspector pane. (This is a 64-bit Mac process, btw.) But trying to use $rax 
> from lldb doesn’t work when I’m in a Swift stack frame:
> 
> (lldb) x $rax
> error: invalid start address expression.
> error: address expression "$rax" evaluation failed
> (lldb) x rax
> error: invalid start address expression.
> error: address expression "rax" evaluation failed
> (lldb) watch set expression rax
> error: expression evaluation of address to watch failed
> expression evaluated: rax
> (lldb) watch set expression $rax
> error: expression evaluation of address to watch failed
> expression evaluated: $rax
> 
> Fine, whatever, I can read the hex value from the inspector pane and type it 
> into lldb by hand :-p. But even giving the raw address doesn’t work!
> 
> (lldb) watch set expression 0x60800b3bdfd0
> error: expression did not evaluate to an address
> 
> I’ve tried taking out the “0x”, parenthesizing, putting “(void*)” in front … 
> no dice.
> 
> (Oh, the handy “Watch” context menu item doesn’t work either. If I 
> right-click the “rax” register in the inspector and choose “Watch”, I get an 
> error alert saying "error: no variable named 'rax' found in this frame”. 
> ARGH.)
> 
> —Jens
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/xcode-users/katherine_stone%40apple.com
> 
> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to