1.将.m文件转换成 c++底层命令
xcrun -sdk iphoneos clang -arch arm64 -rewrite-objc -main.m -o main-arm64.cpp
NSObject *object = [[NSObject alloc] init];
NSLog(@"%zd",class_getInstanceSize([NSObject class]));//<获取NSObject类的实例对象的大小 8个
NSLog(@"%zd",malloc_size(CFBridgingRetain(object)));///< 获取object指针 所指向内存的大小 16个
size_t instanceSize(size_t extraBytes) {
size_t size = alignedInstanceSize() + extraBytes;
// CF requires all objects be at least 16 bytes.
if (size < 16) size = 16;
return size;
}
size_t size = cls->instanceSize(extraBytes);
obj = (id)calloc(1, size);
2.常用的lldb命令
p
po
读取内存
memory read /数量格式字节数 内存地址
x/数量格式字节数 内存地址
x/3xw 0x10010
格式:
x16进制,f是浮点,d是10进制
字节大小
b:byte 1个字节
h:half world 2个字节
w:word 4个字节
g:giant word 8个字节
修改内存
memory write 内存地址 数值
memory write 0x1000010 10