内存检查工具Valgrind
官网介绍:http://www.valgrind.org/
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.
The Valgrind distribution currently includes six production-quality tools: a memory error detector, two thread error detectors, a cache and branch-prediction profiler, a call-graph generating cache and branch-prediction profiler, and a heap profiler. It also includes three experimental tools: a stack/global array overrun detector, a second heap profiler that examines how heap blocks are used, and a SimPoint basic block vector generator. It runs on the following platforms: X86/Linux, AMD64/Linux, ARM/Linux, ARM64/Linux, PPC32/Linux, PPC64/Linux, PPC64BE/Linux, S390X/Linux, MIPS32/Linux, MIPS64/Linux, ARM/Android (2.3.x and later), X86/Android (4.0 and later), MIPS32/Android, X86/Darwin and AMD64/Darwin (Mac OS X 10.9, with limited support for 10.8).
Stack OverFlow 栈溢出 - stack smashing detected
在改造一个ota_ts_generator工具时,调试时,发生如下错误:
./app
|
1
2
3
|
**** stack smashing detected ***: ./app terminated**======= Backtrace: =========**/lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)Aborted* |
Stack Smashing is actually a protection mechanism used by gcc to detect buffer overflow attacks.
#include <stdio.h>void func(){ char array[10]; gets(array);}int main(int argc, char **argv){ func();}【注释:】 An input of string greater than size 10 causes corruption of gcc inbuilt protection canary variable followed by SIGABRT to terminate the program.
You can disable this protection of gcc using option -fno-stack-protector while compiling.
In that case you will get a segmentation fault if you try to access illegal memory location. and of course you can detect the point of overflow say for example using valgrind.
另外一个例子:
#include <string.h> void fn(void) { char a[100]; char *p = a; bzero(p, 1000); } int main(int argc, char *argv[]) { fn(); return 0; }这里,数组a就会保存在栈中。当越界访问a[100]及后面的数据时,发生栈溢出,最容易出现的问题是返回指针被修改,进而函数返回时会发现返回的代码段指针错误,提示:“stack smashing detected...":
很多时候,当内存溢出问题不严重时,并不会直接终止我们程序的运行。但是,我们会在调试程序中碰到非常奇怪的问题,比如某一个变量无缘无故变成乱码,不管是在堆中,还是栈中。这便很有可能是指针的错误使用导致的。这种情况出现时,一种调试方法是:使用gdb加载程序,并用watch锁定被改成乱码的变量。这样,如果这个变量被修改,程序便会停下来,我们就可以看到底是哪条语句修改了这个程序。
总结:栈溢出,常常程序abort的地方并不是出问题的地方有,而是离产生问题的地方有一定距离,所以难以调试。
内存检查工具Valgrind的更多相关文章
- 【c++】内存检查工具Valgrind介绍,安装及使用以及内存泄漏的常见原因
转自:https://www.cnblogs.com/LyndonYoung/articles/5320277.html Valgrind是运行在Linux上一套基于仿真技术的程序调试和分析工具,它包 ...
- 【调试】Linux下超强内存检测工具Valgrind
[调试]Linux下超强内存检测工具Valgrind 内容简介 Valgrind是什么? Valgrind的使用 Valgrind详细教程 1. Valgrind是什么? Valgrind是一套Lin ...
- 内存检测工具valgrind
valgrind --tool=memcheck --leak-check=full --error-limit=no --trace-children=yes ./server valgrind ...
- 不只是内存分析工具~valgrind
体系结构:原理介绍·参考好文:应用 Valgrind 发现 Linux 程序的内存问题 简单组一个摘要: Valgrind包括如下一些工具: Memcheck.这是valgrind应用最广泛的工具,一 ...
- Linux 内存泄漏检查工具 valgrind
抄自<从零开始的JSON库教程>,先mark一下,以后再慢慢研究. ======== 引用分割线 ======== 在 Linux.OS X 下,我们可以使用 valgrind 工具(用 ...
- C/C++内存检测工具Valgrind
内存检测Valgrind简介 Valgrind是运行在Linux上一套基于仿真技术的程序调试和分析工具,作者是获得过Google-O'Reilly开源大奖的Julian Seward, 它包含一个内核 ...
- c程序内存检测工具 - Valgrind
常用C程序内存泄露检测工具 https://blog.csdn.net/u012662731/article/details/78652651
- Yosimite10.10(Mac os)安装c/c++内存检测工具valgrind
1.下载支持包m4-1.4.13.tar.gz $ curl -O http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz 2. 解压m4-1.4.13.t ...
- linux内存排查工具valgrind
官网:http://valgrind.org/info/about.html 百科介绍:http://baike.baidu.com/link?url=ZdXzff0omzoPpE_yZUlNW9lJ ...
随机推荐
- 【BZOJ】1492: [NOI2007]货币兑换Cash(cdq分治)
http://www.lydsy.com/JudgeOnline/problem.php?id=1492 蒟蒻来学学cdq神算法啊.. 详见论文 陈丹琦<从<Cash>谈一类分治算法 ...
- strust2自定义interceptor的基本方法及操作
需求:制作一个网站需要用户登陆后才能查看,即一个权限的问题 1.首先明确在用户没登陆前有两个Action请求是可以通过的,即注册和登陆. 2.创建拦截器,如UserLoginInterceptor.j ...
- UVa 11178:Morley’s Theorem(两射线交点)
Problem DMorley’s TheoremInput: Standard Input Output: Standard Output Morley’s theorem states that ...
- OEM无法启动:oracle/product/10.2.0/dbhome_1/oc4j/j2ee/OC4J_DBConsole_localhost.localdomain_orcl not found.
配置OEM环境变量 ORACLE_UNQNAME=$ORACLE_SID 要想打开OEM的web管理程序,必须先启动Database listener,再启动Datebase Control端口监控程 ...
- K-mean聚类算法汇聚有用信息——学习笔记
无监督-无标签 聚类,难点在于评估和调参. k-means最简单实用 基本概念 K值:数据聚成多少类. 质心:各个维度算平均数.Centroid 相似度量:距离来算(欧式距离——直线距离,余弦距离) ...
- 模板,BFS
#include <stdio.h> #include <string.h> #include <queue> using namespace std; struc ...
- 编程之美 set 20 构造数独
1. 朴素 DFS 遍历效率太低, 即便是预先设定 9 个数放到数组再去 DFS, 同样并不高效 2. 在生成一个可行解后, 随机删除一些数字, 删除的数字越多, 数独的难度就越大 3. 正解二. 3 ...
- ios开发之--使用AFNetWorking 3.1.0 ,简单的请求封装类
从苹果系统自带的请求类,到ASIHttpRequest第三方请求类,再到AFNetWorking第三方请求类,目前只要牵扯到数据请求,基本上都是用AFN,所以,这里纯粹是记录下: hRequestTo ...
- 修改UE4的deriveddatacache目录位置,扩大C盘空间
按照默认安装目录,UE4会装在C盘 C:\Program Files\Epic Games\UE_4.15 DerivedDataCache缓存目录在 C:\Users\你的用户名\AppData\L ...
- Spring JDBC样例
这里介绍一下通过Spring JDBC的方式进行数据库的增删改查的操作.在进行程序的编写之前我们需要在本地MySQL数据库中创建一张User表,如下所示: create database user_d ...