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

3

9

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???

Epistemology answered 16/11, 2011 at 14:49 Comment(0)
E
17

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);
        }

    }
Epistemology answered 16/11, 2011 at 18:35 Comment(4)
where do you symbolicate the data?Sartre
it took a while to try out, and yes, this new format could be symbolicated using symbolicatecrash, though it's looks different from the crash file generated from plcrashutils. And for my case, I just sent the report over the network (no need to post binary data).Holophrastic
vivianaranha please add the swift versionUnicycle
I did this but it still do not show the line number of errorGelid
F
0

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

Fidole answered 25/7, 2012 at 19:38 Comment(0)
J
0

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.

Jugoslavia answered 6/2 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.