0

Following this answer I was able to create a breakpoint in code.

func sayHello() {

    raise(SIGTRAP) // programmatic breakpoint
    kill(getpid(), SIGSTOP)  // programmatic breakpoint

    print("say hello")
}

Using either of those 2 functions stops execution and "say hello" never gets printed.

The same way I was able to programmatically create the breakpoints is there a way that I can programmatically create something else so that the execution can continue after either of those 2 breakpoints is hit?

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
  • 1
    Wouldn't it be better to do this the right way by having LLDB make a genuine breakpoint? That sort of breakpoint can be very powerful, including proceeding automatically after printing if desired. – matt Oct 14 '19 at 23:50
  • Those aren't breakpoints - You are terminating your app. You can't continue from that point. Even if you could, what code would be executing to perform the "continue" - You have stopped execution. What are you trying to do? You can create breakpoints in Xcode that take some action and automatically continue. – Paulw11 Oct 14 '19 at 23:50
  • @Paulw11 oh I didn't know that it terminated the app, the answer to that says it's an "in code" breakpoint (look at it). Thanks for the information. I'm having a problem with an avcapturesession with a fg notification. It only triggers when i put a breakpoint on the bg notification. It's really weird. My idea was just to use a programmatic breakpoint and let it continue. No sure if it'll work but it's worth a shot. – Lance Samaria Oct 14 '19 at 23:54
  • @matt can you send me a link to with your suggestion? – Lance Samaria Oct 14 '19 at 23:54
  • Just do it. In the code editor, put a breakpoint, double-click to edit it, tell it to print and continue. It's trivial. – matt Oct 15 '19 at 00:01

1 Answers1

1

The feature you're looking for is built in. Here's a breakpoint that prints "here" and continues:

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • quick questions, what happens to break points in apps that are live, do they still trigger or are they ignored? My main concern is if I went live with this will the breakpoint still trigger (I want it to). – Lance Samaria Oct 15 '19 at 00:24
  • No, breakpoints only execute when running under the debugger. If you have a timing related issue you need to solve that rather than trying to do something like this – Paulw11 Oct 15 '19 at 00:58
  • I agree, I feel like this is an x-y question. You should be concerned about the actual problem, not breakpoints. :) – matt Oct 15 '19 at 01:52
  • @Paulw11 thanks for help. I wasn’t sure about breakpoints and a live app. You are correct about this being a bandaid on a broken arm. Luckily I solved problem. Take care! – Lance Samaria Oct 19 '19 at 03:32
  • @matt this was definitely a temporary fix. I solved the main issue though and was able to push on. Thanks for you help! – Lance Samaria Oct 19 '19 at 03:34