All exception break point is stopping for no reason on simulator

前端 未结 7 940
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 19:03

This is very annoying, every time I\'m trying to debug on the simulator with \"all exception break point\", app stops for no reason on this line:

return UIAp         


        
相关标签:
7条回答
  • 2020-12-12 19:48

    There's a more accurate way of tracking down the suspect font in your app using the debugger and the fact that it's conveniently stopped at the call.

    Step 1: Reproduce the __cxa_throw breakpoint

    Usually this happens when instantiating one of (or possibly the first) UIView object in your app. You'll see your debugger has broken and you'll have a stack such as this:

    Step 2: Select the entry in the stack trace with the symbol FPFontCreateFontsWithPath

    In my case, this entry was line 7 in the stack.

    If you take a look at the disassembly, you'll notice the function signature of this entry:

    Ah, cool! Looks like it takes some C strings. I betcha one of those is a filepath too!

    Step 3: Locate that string in the app memory

    I'm running this in a (x86_64) simulator, which on my computer stores the function arguments in some of the registers beginning with r. More details on registers here.

    Either press Shift+Command+M or select the "Debug > Debug Workflow > View Memory" option from the menu.

    At the bottom of this view, go through the registers one by one and enter the addresses. In my case, r14 contained the path of the file.

    Alright, so now I know the font that's messed up. It's looking for HelveticaNeue.ttc. Let's find the reference to that in the project.

    Open a terminal, navigate to your project and run:

    $ ~/W/X/project> grep -R "HelveticaNeue" ./
    .//MyProject/Main.Storyboard:        <array key="HelveticaNeue.ttc">
    .//MyProject/Main.Storyboard:            <string>HelveticaNeue</string>
    .//MyProject/Main.Storyboard:                                <fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="18"/>
    

    Awesome, now either switch those to system by replacing name="HelveticaNeue" family="Helvetica Neue" with type="system", open the storyboard and manually edit them or add a reference to the missing font to your app (info.plist and target).

    Step 4: Celebrate

    0 讨论(0)
提交回复
热议问题