0

I set the breakpoint at line 29, and I want to modify the value through LLDB to let him enter the == 1 situation, but I found that this breakpoint jumped to line 33 without hitting it, which is very strange.

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let v = UIView.init(frame: CGRect(x: 100, y: 100, width: 300, height: 300))
        v.backgroundColor = .yellow
        view.addSubview(v)
    }


    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        let value = test()
        print(value)
    }

    func test() -> Bool {
        let m = 3
   29     if m == 1 {
            print(m)
            return true
        } else {
   33        print(m)
            return false
        }
    }
}

Where the breakpoint hit 29 but But the breakpoint jumped to line 33 without hitting

When I set the value of m to a random number, the breakpoint can stay at line 29, and the value can be modified to make him enter a different state, which makes me very confused

   func test() -> Bool {
        let m = arc4random()
        if m == 1 {
            print(m)
            return true
        } else {
            print(m)
            return false
        }
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Zuqiu
  • 9
  • 1

1 Answers1

2

It is strange that you did not notice the following warning

enter image description here

knowing that the compiler just thrown that part of code from built executable away and debug info, for those lines so is absent, as a result debugger just jump through it to existed part of code.

Asperi
  • 228,894
  • 20
  • 464
  • 690
  • I can understand that as long as this warning pops up, the bottom layer of the program will not compile and generate that code, and directly enter the else, right? – Zuqiu Feb 26 '20 at 17:26
  • @Zuqiu, I would say there is no `else` at all, just `let m = 3; print(m); return m;` – Asperi Feb 26 '20 at 17:32
  • There is also a very strange thing, I have `20` lines on your picture, execute the LLDB command `e m = 10`, and then execute the `po m` result is 10, but after executing 20 lines, the result is `printed as 3`, it seems that LLDB has not changed this Value, if you don't reproduce it, you can change `let` to `var`。Do you know why this is – Zuqiu Mar 02 '20 at 08:05