Advanced Debugging and the Address Sanitizer
A debug trick
在异常端点处运行 po $arg1,找出异常信息。

Address Sanitizer
概述
- 是一个运行时检测工具
- 发现内存问题
- 可以用于模拟器和设备
可以发现的问题
- Use after free
- Heap buffer overflow
- Stack buffer overflow
- Global variable overflow
- Overflows in C++ containers
- Use after return
原理
当打开这个功能时,在编译时传入了一个参数,在运行时链接了一个动态库 asan dylib。

系统为所有内存维护了一个 shadow memory,标记了那些是可以正常使用的,那些是不可以访问的。

在上图中,红色区域是不可以访问的,因为不是预分配的地址。
为了达到这个目的,系统预留了部分内存地址做为 shadow memory,把每 8 个字节的状态用 1 个比特来代表。

在访问内存时,只需要做一个偏移来查看比特位的状态即可。
bool IsPoisoned(Addr) {
Shadow = Addr >> 3 + Offset
return (*Shadow) != 0
}
检测堆的内存错误原理
复写了系统的 malloc 函数,把分配好的内存区域周围标记为 posioned。这样子在越界时,可以检测出来。

可以检测出来下面的错误:
- Heap underflows/overflows
- Use-after-free
- double free
检测栈上内存错误
类似,在栈上分配的内存周围标记为 posioned,并在访问内存之前做检查。

这样子也可以检测出全局变量内存错误。
复写了很多内存函数
不限于 memcpy, memset, strcpy, strlen, fwrite, printf, getline, ...
增加的负载

Advanced Debugging and the Address Sanitizer的更多相关文章
- Linux高级调试与优化——Address Sanitizer
Address Sanitizer ASAN最早可以追溯到 LLVM 的 sanitizers项目(https://github.com/google/sanitizers),这个项目包含了Addre ...
- Xcode 7 调试野指针利器 Address sanitizer
Xcode 7 调试野指针利器 Address sanitizer 什么是Address Sanitizer? AddressSanitizer is a fast memory error dete ...
- ubuntu 13.04 编译 安装 升级 gcc 4.9.0 address sanitizer
@ 前记: 最近查一个线上项目的crash,review代码无果,crash几率低,不可在本地环境重现.之后在线上好几个服务器跑valgrind就不crash了.个人猜测可能是跑valgrind后性能 ...
- (转)在Xcode 7上直接使用Clang Address Sanitizer
原文地址: http://www.cocoachina.com/ios/20150730/12830.html WWDC 2015上,除了Swift 2.0外,还有一个令人激动的消息:可以直接在Xco ...
- Xcode 8 的 Debug 新特性
Contents OverView Static Analyzer Localizability Instance Cleanup Nullablility Runtime Issue View De ...
- Xcode 8 的 Debug 新特性 —- WWDC 2016 Session 410 & 412 学习笔记
Contents OverView Static Analyzer Localizability Instance Cleanup Nullablility Runtime Issue View De ...
- Java Debugging with Eclipse - Tutorial
1.1. What is debugging? Debugging allows you to run a program interactively while watching the sourc ...
- 如何看iOS崩溃日志
重点:Triggered by Thread这句话后边的线程号,快速定位问题出现在那个线程,是否是你的锅:Triggered by Thread所指的线程表示导致异常.崩溃的线程 下边内容转自简书 简 ...
- 现在的 Linux 内核和 Linux 2.6 的内核有多大区别?
作者:larmbr宇链接:https://www.zhihu.com/question/35484429/answer/62964898来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...
随机推荐
- $.post 提示错误: Uncaught SyntaxError: Unexpected token :
$.post("addRecommond",{"productId":productId,"categoryCode":categoryCo ...
- 2018.10.20 bzoj1068: [SCOI2007]压缩(区间dp)
传送门 这题转移很妙啊. f[l][r][1/0]f[l][r][1/0]f[l][r][1/0]表示对于区间[l,r][l,r][l,r]有/无重复的机会时压缩的最小值. 那么可以从三种情况转移过来 ...
- PHP compact函数
$firstname = "Peter"; $lastname = "Griffin"; $age = "41"; $data = comp ...
- js继承——扩展Object方式实现继承
function Parent(name,sex){ this.name = name; this.sex = sex; this.sayName = function(){ console.log( ...
- iOS中清除缓存的方法 以及SDWebimage自带的清除缓存方法
1 SDWebimage中 (1) 计算缓存的大小 单位 : (MB) CGFloat size = [[SDImageCache sharedImageCache] getSize] / 102 ...
- afx_msg解释
以前一直不知道AFX_MSG是什么意思,只是觉得它应该是个消息映射函数,但是具体代表什么意思,会返回一个什么样的值是一点都不清楚,今天查了下资料,把查到的东西放这,以免以后忘了还得再查. 在头文件(D ...
- POJ3104 Drying 2017-05-09 23:33 41人阅读 评论(0) 收藏
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15604 Accepted: 3976 Descripti ...
- MAC将 /etc/sudoers文件修改错后的几种解决方法
文件修改错误后难以再次修改的原因: 1.修改此文件必须是root权限 2.此文件出现问题时sudo命令不可用 3.默认情况下MAC系统不启用root用户 解决的方法: 一.启用root用户,使用roo ...
- Code Review Checklist and Guidelines for C# Developers
Checklist1. Make sure that there shouldn't be any project warnings.2. It will be much better if Code ...
- [ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]
Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, where keys ...