KSCrash
debug模式下,KSCrash的线程回调线程
"backtrace": {
"contents": [
{
"object_name": "CoreFoundation",
"object_addr": 7134101504,
"symbol_name": "<redacted>",
"symbol_addr": 7135249460,
"instruction_addr": 7135249688
},
...
{
"object_name": "KSCrashLearnDemo",
"object_addr": 4367810560, //104578000
"symbol_name": "-[ViewController testArrayRangeException:]",
"symbol_addr": 4367835524, //10457e184
"instruction_addr": 4367835696 //10457e230
},
...
...
{
"object_name": "KSCrashLearnDemo",
"object_addr": 4367810560, //104578000
"symbol_name": "main",
"symbol_addr": 4367835828, // 10457e2b4
"instruction_addr": 4367835952 // 10457e330
},
{
"object_name": "libdyld.dylib",
"object_addr": 7129288704, // 1a8f05000
"symbol_name": "<redacted>",
"symbol_addr": 7129295068, //1a8f068dc
"instruction_addr": 7129295072 // 1a8f068e0
}
],
对应用Xcode解析出来的crash文件
Last Exception Backtrace:
0 CoreFoundation 0x1a94b4518 __exceptionPreprocess + 228
...
3 CoreFoundation 0x1a93c2484 -[__NSArrayM setObject:atIndexedSubscript:] + 703
4 KSCrashLearnDemo 0x10457e230 0x104578000 + 25136
5 UIKitCore 0x1d58eb230 -[UIApplication sendAction:to:from:forEvent:] + 95
...
22 KSCrashLearnDemo 0x10457e330 0x104578000 + 25392
23 libdyld.dylib 0x1a8f068e0 start + 3
KSCrash 学习知识点
1. 获取内存使用情况
static bool VMStats(vm_statistics_data_t* const vmStats, vm_size_t* const pageSize)
{
kern_return_t kr;
const mach_port_t hostPort = mach_host_self();
if((kr = host_page_size(hostPort, pageSize)) != KERN_SUCCESS)
{
KSLOG_ERROR(@"host_page_size: %s", mach_error_string(kr));
return false;
}
mach_msg_type_number_t hostSize = sizeof(*vmStats) / sizeof(natural_t);
kr = host_statistics(hostPort,
HOST_VM_INFO,
(host_info_t)vmStats,
&hostSize);
if(kr != KERN_SUCCESS)
{
KSLOG_ERROR(@"host_statistics: %s", mach_error_string(kr));
return false;
}
return true;
}
static uint64_t freeMemory(void)
{
vm_statistics_data_t vmStats;
vm_size_t pageSize;
if(VMStats(&vmStats, &pageSize))
{
return ((uint64_t)pageSize) * vmStats.free_count;
}
return 0;
}
static uint64_t usableMemory(void)
{
vm_statistics_data_t vmStats;
vm_size_t pageSize;
if(VMStats(&vmStats, &pageSize))
{
return ((uint64_t)pageSize) * (vmStats.active_count +
vmStats.inactive_count +
vmStats.wire_count +
vmStats.free_count);
}
return 0;
}