Home > OS >  How to break out of an assert in iOS / swift
How to break out of an assert in iOS / swift

Time:09-28

I've hit an assertion in code and wondering if there's a way to create a wrapper around the assert that would enable breaking out and continuing execution or some other function that would enable a way to suppress the assert through the lldb debugger.

assert(condition(), makeCriticalEvent().event.description, file: fileID, line: UInt(line))

This is the standard assertion in apples libraries here. When I hit this assertion I tried continuing execution but it stays stuck at the assertion. I'd like to silence the assertion (likely through the lldb debugger by typing some command). Anyone have an idea how to do this?

CodePudding user response:

You have to do two things. First, you have to tell lldb to suppress the SIGABRT signal that the assert delivers. Do this by running:

(lldb) process handle SIGABRT -p 0

in lldb. Normally SIGABRT is not maskable, so I was a little surprised this worked. Maybe because this is a SIGABRT the process sends itself? I don't think there's any guarantee suppressing SIGABRT's has to work in the debugger so YMMV, but it seems to currently. Anyway, do this when you've hit the assert.

Then you need to forcibly unwind the assert part of the stack. You can do that using thread return, which returns to the thread above the currently selected one w/o executing the code in that frame or any of the others below it. So just select the frame that caused the assert, go down one frame on the stacks and do thread return.

Now when you continue you won't hit the abort and you'll be back in your code.

  • Related