Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a symbolic breakpoint with Swift and lldb

Tags:

swift

lldb

How does one set a symbolic breakpoint in lldb when using Swift? For example, sometimes I use:

(lldb) b set -F '-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]'

But this no longer works:

Breakpoint 2: no locations (pending). WARNING: Unable to resolve breakpoint to any actual locations.

I've also tried

(lldb) b set -F 'UIView.updateConstraintsIfNeeded()'
(lldb) b set -F 'UIView.updateConstraintsIfNeeded'

But no love. I guess the question comes down to what lldb considers a "fully qualified function name" when using Swift. The docs say:

-F ( --fullname )

Set the breakpoint by fully qualified function names. For C++ this means namespaces and all arguments, and for Objective C this means a full function prototype with class and selector. Can be repeated multiple times to make one breakpoint for multiple names.

What about Swift?

like image 483
John Scalo Avatar asked Oct 04 '16 17:10

John Scalo


2 Answers

When lldb is setting breakpoints any of the fancier matching breakpoints (including -F), it needs to know the target language since the kinds of matching it does depends on that. By default, lldb chooses the language of the current frame, but you can override that. So for instance to break on an ObjC symbol when you are stopped in a Swift frame, do:

(lldb) break set -F '-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]' -L objc
Breakpoint 3: where = UIKit`-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded], address = 0x0000000100963acc

Or you can use the -n break option, which doesn't try to understand the symbols it matches, but just does a wide search for that string in the symbol names.

Note, in this case you need to break on the ObjC symbol not the way it appears in Swift, because the swift side is really just a shim into objc, and there isn't really a swift side symbol to hook onto.

like image 156
Jim Ingham Avatar answered Sep 27 '22 17:09

Jim Ingham


In the lldb console, you can give a partial name and get automatic lookup using regex:

br set -r updateConstraintsIfNeeded\]

The result is:

Breakpoint 4: where = UIKit`-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]

In current versions of Xcode, you can also use a partial name in the "add a symbolic breakpoint" UI, because there is now code completion to assist you.

enter image description here

like image 39
matt Avatar answered Sep 27 '22 16:09

matt