PLCrashReporter - How to convert .plcrash to .crash directly from Xcode itself and save it locally

5k Views Asked by At

I am currently working with PLCrashReporter and need some help with converting the plcrash directly to .crash file instead of using the plcrashutil.

What i currently do is -

I simulate a crash and it creates a myapp.plcrash file.

Once that is generated i use the following on command line -

plcrashutil convert --format=iphone myapp.plcrash > app.crash

This works perfectly - But is there a way I can dont have to do this extra step and convert it to .crash directly from my code probably by importing the library or something??

Any Solutions???

3

There are 3 best solutions below

4
On BEST ANSWER

Got the answer

Here is the solution if anyone else is looking for it..

PLCrashReportTextFormat textFormat = PLCrashReportTextFormatiOS;


    /* Decode data */

    PLCrashReport *crashLog = [[PLCrashReport alloc] initWithData: data error: &error];
    if (crashLog == nil) {
        NSLog(@"Could not decode crash file :%@",  [[error localizedDescription] UTF8String]);
    } else {
        NSString* report = [PLCrashReportTextFormatter stringValueForCrashReport: crashLog withTextFormat: textFormat];
        NSLog(@"Crash log \n\n\n%@ \n\n\n", report);

        NSString *outputPath = [documentsDirectory stringByAppendingPathComponent: @"app.crash"];
        if (![report writeToFile:outputPath atomically:YES encoding:NSUTF8StringEncoding error:nil]) {
            NSLog(@"Failed to write crash report");
        } else {
            NSLog(@"Saved crash report to: %@", outputPath);
        }

    }
0
On

Have you tried to symbolicate the .crash file in the new format?

0
On

You can run plcrashutil main.m processes in the project directory.

How ? enter image description here

Then, plcrashutil should be selected on the scheme and you can send arguments with manually.

Product > Scheme > Edit Scheme > plcrashutil

enter image description here

Finally, input_file = argv[0] in the 84. line of code; instead of code input_file = argv1; should be written on main.m file in directory of plcrashutil

static int convert_command (int argc, char *argv[]) {
    const char *format = "iphone";
    const char *input_file;
    FILE *output = stdout;

    /* options descriptor */
    static struct option longopts[] = {
        { "format",     required_argument,      NULL,          'f' },
        { NULL,         0,                      NULL,           0 }
    };    

    /* Read the options */
    char ch;
    while ((ch = getopt_long(argc, argv, "f:", longopts, NULL)) != -1) {
        switch (ch) {
            case 'f':
                format = optarg;
                break;
            default:
                print_usage();
                return 1;
        }
    }
    argc -= optind;
    argv += optind;

    /* Ensure there's an input file specified */
    if (argc < 1) {
        fprintf(stderr, "No input file supplied\n");
        print_usage();
        return 1;
    } else {
        input_file = argv[1];
    }

So you can run and debug code.