Search code examples
swiftxcodelldb

breakpoint with debugger Commend jump in xcode


I made a breakpoint in Xcode with the jump commend to force passing some condition, but when it execute to line 168 it crash with message

"Thread 1: EXC_BAD_ACCESS (code=1, address=0x1)"

enter image description here

enter image description here

why did that happen?

the console logged:

warning: MoreMultitypeCollectionViewCell.swift:178 appears multiple times in this function, selecting the first location:

MoreMultitypeCollectionViewCell.(updateButtonStateCkeck in _9A12557DCAB30EEB52DC7C2EA09487CD)() -> () + 1580 at MoreMultitypeCollectionViewCell.swift:178

MoreMultitypeCollectionViewCell.(updateButtonStateCkeck in _9A12557DCAB30EEB52DC7C2EA09487CD)() -> () + 1600 at MoreMultitypeCollectionViewCell.swift:178

my questions are:

  1. How should I type in lldb to select location?
  2. Is there a better way to force passing into If Statement without change code and rebuild project?
  3. sometimes when I type 'po' in lldb or click print description in variable view, it will show fail message, how is that?

Solution

  • 1) In lldb, the equivalent command is thread jump and you can specify an address as well as a line number there.

    2) thread jump or the Xcode equivalent is an inherently dangerous operation. If you jump over the initialization of some variable, you will be dealing with bad data now and will likely crash. That sort of thing you can sometimes spot by eye - though Swift is lazy about initialization so the actual initialization of a variable may not happen where you think it does in the source. There are more subtle problems as well. For instance, if you jump over some code that as a byproduct of its operation retains or releases an object, the object will end up under or over retained. The former will cause crashes, the latter memory leaks. These retains & releases are generated by the compiler, so you can't see them in your source code, though you could if you look at the disassembly of the code you are jumping over.

    Without looking at the code in question, I can't tell why this particular jump caused a crash.

    But you can't 100% safely skip some of the code the compiler choose to emit. Looking at the disassembly you might be able to spot either (a) a better place to stop before the jump - i.e. stop past some retain or release that is causing a problem or jump to an address in the middle of a line so you still call a retain that's needed. You'll have to figure this out by hand.

    3) There's not enough info to answer this question.

    BTW, your image links don't seem to resolve.