0 Replies
      Latest reply on May 15, 2020 9:20 PM by Piasy
      Piasy Level 1 Level 1 (0 points)

        I create a simple project to demonstrate C++ code crash symbolication.

         

        The C++ code is crash.cpp:

         

         

        #include "crash.h"
        
        #include 
        
        int* newPtr() {
          return new int[1];
        }
        
        void resetPtr(int** ptr) {
          *ptr = nullptr;
        }
        
        void usePtr(int* ptr) {
          int var = *ptr;
          var++;
          *ptr = var;
        }
        
        void testCrash() {
          int* ptr = newPtr();
          usePtr(ptr);
          resetPtr(&ptr);
          usePtr(ptr);
          resetPtr(nullptr);
          usePtr(ptr);
        }

         

         

        The Objective-C code calling it is ViewController.mm:

         

         

        #import "ViewController.h"
        
        #import "crash.h"
        
        @interface ViewController ()
        
        @end
        
        @implementation ViewController {
            int _val;
        }
        
        - (void)viewDidLoad {
            [super viewDidLoad];
            // Do any additional setup after loading the view.
        
            // this could be symbolicated correctly
            //ViewController* vc = nil;
            //NSLog(@"%d", vc->_val);
        
            // this couldn't be symbolicated correctly
            testCrash();
            NSLog(@"test");
        }
        
        @end

         

        The line number above is the same as source code.

         

         

        It should crash at ViewController.mm:22 => crash.cpp:23 => crash.cpp:14, and that's exactly what I see in Xcode when I run the app in Xcode.

         

        But when I disconnect with Xcode, and launch the app from home screen, then get the crash log using Xcode menu Window - Devices and Simulators - View Device Logs, but the symbolicated crash is:

         

         

        Thread 0 name:  Dispatch queue: com.apple.main-thread
        Thread 0 Crashed:
        0   CrashExample                  0x000000010493230c usePtr(int*) + 25356 (crash.cpp:13)
        1   CrashExample                  0x000000010493234c testCrash() + 25420 (crash.cpp:24)
        2   CrashExample                  0x0000000104932480 -[ViewController viewDidLoad] + 25728 (ViewController.mm:23)
        3   UIKitCore                      0x000000018ea0a36c -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 104

         


         

        All 3 frames are wrong!

         

        I'm using Xcode 11.4.1 (11E503a), macOS 10.15.4 (19E287), iPhone 11 iOS 13.4.1.

         

        Here is my test project: https://imgs.piasy.com/2020-05-16-CrashExample.zip

         

        Please help me, thanks!