iOS- resolve Ben collapse log (pit)

Ben collapse log parsing the article has a lot, but really very little to meet my needs, I'm here to write the main point I encountered the pit to collect.

Ben collapse acquiring a log symbol table address stack (Base Address)

static NSString *GetLoadAddres(void) {
    NSString *imageLoadAddress = @"";
    for (uint32_t i = 0; i < _dyld_image_count(); i++) {
        const struct mach_header* imageHeader = _dyld_get_image_header(i);
        if (imageHeader == NULL) {
            continue;
        }
        
        if (imageHeader->filetype == MH_EXECUTE) {
            imageLoadAddress = [NSString stringWithFormat:@"0x%llX", (uint64_t)imageHeader];
            break;
        }
    }
    return imageLoadAddress;
}

How to verify 符号表堆栈地址correct:
When you receive a message as follows Ben collapse

5 Demo 0x0000000100bd15ac Demo + 21932

This can be seen that the stack address and the offset value information Ben collapse.
Stack Address: 0x0000000100bd15ac
offset: 21932
符号表堆栈地址= 堆栈地址- 偏移值
so that you can validate your 符号表堆栈地址correctness of the.

2 get CPU Type

iPhone device CPU instructions

#include <mach/mach_host.h>
- (NSString *)cpuType {
    host_basic_info_data_t hostInfo;
    mach_msg_type_number_t infoCount;
    
    infoCount = HOST_BASIC_INFO_COUNT;
    host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
    NSString *architecture = @"";
    if (hostInfo.cpu_type == CPU_TYPE_ARM64)
        architecture = @"arm64";
    else if (hostInfo.cpu_type == CPU_TYPE_ARM)
    {
        ///WJDeviceInfo 这个库我自己封装的 这边只是获取设备名如: iPhone5,1 等等自己搜
        NSString* device = WJDeviceInfo.currentDevice.deviceName;
        NSInteger modelNo = [[device substringFromIndex:device.length - 1] integerValue];
        if (([device hasPrefix:@"iPhone5,"] && modelNo >= 1 && modelNo <= 4)  ||
            ([device hasPrefix:@"iPad3,"]   && modelNo >= 4 && modelNo <= 6))
            architecture = @"armv7s";
        else
            architecture = @"armv7";
    }
    return architecture;
}

3 log parsing single

Roughly describes the command
can use dwarfdumpcheck out the app and dSYM, are the same.

> dwarfdump --uuid <dSYM地址> 

It can be used atosto resolve Ben collapse log

> atos -o <dSYM地址> -arch <CPUType> -l <符号表堆栈地址 > <奔溃堆栈地址>

Guess you like

Origin blog.csdn.net/weixin_33720956/article/details/90844696