AddressSanitizer+cmake
1. AddressSanitizer+cmake(Linux)
编译指令:
CXXFLAGS通常需要加上
-fsanitize=address
-fno-omit-frame-pointer #打印函数调用路径
-fsanitize-recover=address #AddressSanitizer遇到错误时能够继续
-fsanitize=address-fno-omit-frame-pointer-fsanitize-recover=address### 2. 运行时动态链接
设置环境变量,如设置AddressSanitizer遇到错误时继续运行export ASAN_OPTIONS="halt_on_error=0:abort_on_error=0"
链接ASAN库
LD_PRELOAD=xxxxx/libasan.so ./out
sun@sun:~/nolo/asan_test$ g++ asan_test.cpp -o main -fsanitize=leak
sun@sun:~/nolo/asan_test$ ls
asan_test.cpp main
sun@sun:~/nolo/asan_test$ ./main =================================================================
==184528==ERROR: LeakSanitizer: detected memory leaksDirect leak of 40 byte(s) in 1 object(s) allocated from:#0 0x7fa1c10cc501 in operator new[](unsigned long) ../../../../src/libsanitizer/lsan/lsan_interceptors.cpp:231#1 0x5595b681319e in main (/home/sun/nolo/asan_test/main+0x119e)#2 0x7fa1c0ba50b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)SUMMARY: LeakSanitizer: 40 byte(s) leaked in 1 allocation(s).
sun@sun:~/nolo/asan_test$ cat asan_test.cpp
#include <iostream>int main()
{
int* p = new int[10];
p = NULL;
return 0;
}
3. 安装
AddressSanitizer(地址杀菌剂,简称 ASan) 是谷歌出品的内存检查工具,比 Valgrind 更高效。其由两部组成:编译器 instrumentation 模块
提供malloc()/free()替代项的运行时库
gcc 4.8 开始,AddressSanitizer 成为 gcc 的一部分,但不支持符号信息,无法显示出问题的函数和行数。从 4.9 开始,gcc 支持 AddressSanitizer 的所有功能。Ubuntu 一般不用安装,CentOS 一般需要安装。如果使用 AddressSanitizer 时报错:/usr/bin/ld: cannot find /usr/lib64/libasan.so.0.0.0
则需要先安装。Ubuntu 安装命令:sudo apt-get install libasan0
CentOS 安装命令:sudo yum install libasan
使用
在用 gcc 编译程序时,指定 -fsanitize=address 选项即可自动调用 AddressSanitizer。运行程序时,就可以看到相关信息。通过 -g 选项,可以看到报错的函数和行号。
3. 参考
博客园:https://www.cnblogs.com/kika/p/10851494.html
Github 地址:https://github.com/google/sanitizers
Wiki 地址:https://github.com/google/sanitizers/wiki/AddressSanitizer
基本使用:https://blog.csdn.net/c_lazy/article/details/80009627
输出信息的详细解释:https://www.jianshu.com/p/3a2df9b7c353
相关文章:

vibe前景提取改进算法
// improveVibeAlgorithm.h #ifndef IMPROVED_VIBE_ALGORITHM_H #define IMPROVED_VIBE_ALGORITHM_H#include <opencv2/opencv.hpp> using namespace std;#define WINSIZE 5 // Vibe改进算法, Barnich, Olivier & Droogenbroeck, Marc. (2009). // ViBE: A powerfu…

npm-debug.log文件出现原因
项目主目录下总是会出现这个文件,而且不止一个,原因是npm i 的时候,如果报错,就会增加一个此文件来显示报错信息,npm install的时候则不会出现。转载于:https://www.cnblogs.com/liuna/p/6558006.html

AutoFac Ioc依赖注入容器
本文原著:牛毅 原文路径 http://niuyi.github.io/blog/2012/04/06/autofac-by-unit-test/ 理解IOC容器请看下图: 没有使用IOC容器的情况下: 使用IOC容器的情况下: 去掉IOC容器的情况后: IOC容器又像一个插座,将电输送…

Linux安装App记录
Ubuntu18.04安装微信

windows socket编程入门示例3
// Lock.h #ifndef _Lock_H #define _Lock_H #include <windows.h>class CriticalSection { private:CRITICAL_SECTION g_cs; //临界区 public:CriticalSection();~CriticalSection();void Lock();void UnLock(); }; #endif// Lock.cpp #include "Lock.h"…

游戏开发:js实现简单的板球游戏
js实现简单的板球游戏大家好,本次我们来使用js来实现一个简单的板球游戏。截图如下:首先,设计页面代码,页面代码很简单,因为整个几乎是使用js编写的,页面几乎没有代码,如下:<!DOC…

SLAM精度测评——EVO进阶
1. 基本概念 1.1 Umeyama算法 ATE: evo_ape tum state_groundtruth_estimate0/data.tum orb2/CameraTrajectory.txt -r trans_part -va --plot --plot_mode xy --save_results /home/sun/evo/v1_01_easy/orb2/ate.zip RPE: evo_rpe tum state_groun…

python读取图片并且显示
使用python-opencv读取图片,利用opencv或matplotlib显示图片。 # -*- coding: utf-8 -*-import numpy as np from matplotlib import pyplot as plt #import urllib import cv2def load_image1(file):# Load an color image in grayscaleimg cv2.imread(file,0)cv…

shiro认证
shiro权限认证: 具体的认证流程是这样的: 一般流程: 通过.ini的文件来初始化工厂,.ini的文件的好处是可以创建多个组,而.properties的文件只能创建一组。 系统默认有shiro.ini的文件,但是一般我们是自定义数…

小猿圈Linux基础面试题,看看你能答对几道?
最近身边的很多朋友都在学习linux,从最开始的安装软件都需要百度一天的他们,现在已经成长为了,不需要百度就可以把自己弄懵圈的了,接下来的几天小猿圈linux老师会为大家准备一些实用的linux技巧分析给大家,希望对你有所…

ORB-SLAM2 论文翻译
https://ug98gs7tbw.feishu.cn/docs/doccnKKOWAjkKv7AzAiEvbnM3Tf

mxnet教程1
import mxnet as mx #%matplotlib inline import os import subprocess import numpy as np import matplotlib.pyplot as plt import tarfileimport warnings warnings.filterwarnings("ignore", categoryDeprecationWarning)# 从内存中读取数据 def test1():data …

番外:Spring MVC环境搭建和Mybatis配置避坑篇
2019独角兽企业重金招聘Python工程师标准>>> web.xml引入对spring mvc的支持; spring-mvc配置spring-mvc; spring-mybatis配置mybatis支持,并指名mapper文件的位置; mybaits-config配置mybatis; jdbc.prope…

50个云终端只需一台服务器是怎么一回事
看到这个标题也许有人会说50个云终端只需要一台服务器这应该是不可能的吧,即使是真的那这个服务器的配置和价格应该也要非常高的吧。但是如果有人和你说50个云终端只需要一台中等配置和价格的服务器就可以的呢。而且这50个用户桌面都可以正常的使用不会出现卡顿等现…

SLAM学习,小白入门到殿堂级大牛资料整理
总结一下我接触过的SLAM算法吧,主要集中在visual slam: 特征法: ORB SLAM https://github.com/raulmur/ORB_SLAM2优势: 在静态环境下定位准确,稳定, 单目和双目版本都可以达到实时(高于10frames/s)。代码可读性强,易扩展, 网上也有实现和imu融合的版本。 劣势:建的地图…

python解析json
“data.json”文件内容如下: {"id":"1220562","alt":"http:\/\/book.douban.com\/book\/1220562","rating":{"max":10, "average":"7.0", "numRaters":282, "min…

8.改进应用程序
2019独角兽企业重金招聘Python工程师标准>>> ##8.1数字格式设置(storyboard) ##8.1.2可选类型拆封 import Cocoa extension Double{var dollars : String{let formatter : NumberFormatter NumberFormatter()//NSNumberFormatter弃用var re…

小猿圈Linux学习-Linux种搜索的命令
做Linux工程师的每天都不能少的工作就是搜索文件,这是他们的日常活动,很繁琐很枯燥,所以我们就需要知道一些搜索的命令,这些命令更高效更快捷,今天小猿圈就给大家分享4个可以搜索的Linux命令。。 方法 1:使…
SURF与SIFT比较分析
opencv3.2 SURF实现特征点匹配 opencv3.2中SurfFeatureDetector、SurfDescriptorExtractor、BruteForceMatcher这三个的使用方法已经和原先2.4版本前不一样了。 使用方法示例如下: Ptr<SURF> detector SURF::create(minHessian);detector->detect(img_1…

python文件和目录
# -*- coding: utf-8 -*-import osdef printFile(rootDir):allFiles os.listdir(rootDir) #列出文件夹下所有文件和目录for i in range(0, len(allFiles)):# print(rootDir allFiles[i])path os.path.join(rootDir, allFiles[i])if not os.path.isfile(path):print(path, &q…

你不怕他离职吗?
图片来自“wikiart” 这是我同事在晚上11点多跟我聊微信时问起的一个问题,我觉得这个问题还是挺有代表性的,所以我还是决定就这个问题展开聊聊我对这句话的看法。 我同事之所以这么说,是因为他的组员,也就是问题中的那个他&#x…

tensorflow 1
import tensorflow as tf import numpy as np import matplotlib.pylab as pltdef tfDemo1():#create datax_data np.random.rand(100).astype(np.float32)y_data x_data * 0.1 0.3#create tensorflow structureWeightstf.Variable(tf.random_uniform([1],-1.0,1.0)) #一维&…

SLAM资源整理
资源整理 浙大3D Group VINS orbslam2 orbslam2 video study https://www.bilibili.com/video/BV1bK4y197kB/?spm_id_fromautoNext orbslam2 csdn https://blog.csdn.net/ncepu_chen/category_9874746.html https://www.zhihu.com/column/c_1114864226103037952 https:…

Golang微服务开发实践
github: github.com/yun-mu/Micr… 微服务概念学习:可参考 Nginx 的微服务文章 微服务最佳实践:可参考 微服务最佳实践 demo 简介 服务: consignment-service(货运服务)user-service(用户服务)l…

Linux ssh/scp/docker学习
文章目录Linux ssh/scp/docker使用学习1. ssh 登录2. scp传输文件3. docker4. git checkout 替换指定分支的单个文件Linux ssh/scp/docker使用学习 1. ssh 登录 sudo ssh fireflyip (登录账号密码) scp -r company/data_depthfill/ firefly192.168.105.6:/tmp/ 2…

tensorflow mnist 1
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import keras.backend.tensorflow_backend as KTFdef add_layer(inputs,in_size,out_size,activation_functionNone):#Weights是一个矩阵,[行,列]为[in_size,out_s…

framework7使用笔记
2019独角兽企业重金招聘Python工程师标准>>> myApp.addView(.view-main, {}); 以上这句代码一定要添加 ,否则链接的页面不能正常加载 --------------------------------------------- 如果初始化时定义了preprocess,则页面上链接的自动加载将…

Linux:检查当前运行级别的五种方法
2019独角兽企业重金招聘Python工程师标准>>> 运行级就是Linux操作系统当前正在运行的功能级别。存在七个运行级别,编号从0到6。系统可以引导到任何给定的运行级别。运行级别由数字标识。每个运行级别指定不同的系统配置,并允许访问不同的进程…

概率机器人资料整理
机器人算法仿真 https://atsushisakai.github.io/PythonRobotics/ 最大熵对应的概率分布及其优化推导 https://www.cnblogs.com/yychi/p/9401807.html 矩阵计算网址 http://www.yunsuan.info/matrixcomputations/index.html

LLVM官方文档翻译---- LLVM原子指令与并发指引
英文原文地址:http://llvm.org/docs/Atomics.html 译文原文地址:http://blog.csdn.net/wuhui_gdnt/article/details/52485591 注:该文章转载已经得到译者授权。 --------------------------------------------------------------------------…