当前位置:网站首页>代码调试core-踩内存
代码调试core-踩内存
2022-07-06 19:03:00 【帅气滴点C】
定位方法:
- gdb:
- 通过gdb对内存打断点(watch) ,看看谁非法访问了该内存区域。然后逐步缩小范围。直到找到对应的函数段,比如:
- 比如发现0x800 地址被踩。
- 首先判断该地址是否合法,也就是0x800是否应该存在,如果不应该存在,则可以watch这个地址,也可以代码不断运行,期间不断打印该地址,看哪段代码修改了。
- 比如发现0x800 地址被踩。
- 局限
- 问题出现在启动阶段,来不及设断点,不好定位,
- 有些系统不支持gdb
- 被踩地址不固
- 通过gdb对内存打断点(watch) ,看看谁非法访问了该内存区域。然后逐步缩小范围。直到找到对应的函数段,比如:
- 类似内存泄漏的问题,先定界,后定位,通过内存proc信息(meminfo/media-mem)判断是具体的模块,内存段。也可以用MMU(linux下可以用mrotect)对特定区域进行保护
- 局限
- MMU保护的最小单位是一个内存页,有可能被踩区域较小,无法用mmu进行保护
- 局限
- 减法缩小范围,裁剪模块,修改应用程序,找到最小场景
- 加打印,打印出异常和怀疑的地址;也可以dump出被踩地址的数据,查看数据特征,根据数据特征分析从哪里来。
- valgrind+effence+ksan等工具
常见的问题
- 类型转换出错
- 比如小转大,包括常见的char和int,以及自定义结构体
- 包括形参
- 使用已经释放的地址
- 比如malloc或者没有申请控件就使用
- 申请的内存太小,不够用,类似与越界
如何避免
- 函数嵌套不要太深
- 代码要对称,malloc对应的位置一定要释放
- 数组大小要注意
边栏推荐
- Lumion 11.0 software installation package download and installation tutorial
- Detailed explanation of line segment tree (including tested code implementation)
- Untiy文本框的代码换行问题
- Summer Challenge database Xueba notes (Part 2)~
- STM32 project -- Topic sharing (part)
- Real project, realized by wechat applet opening code (end)
- How to build a 32core raspberry pie cluster from 0 to 1
- Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
- PCL 常用拟合模型及使用方法
- Introduction to the internal structure of the data directory of PostgreSQL
猜你喜欢

Argo workflows source code analysis

Application analysis of face recognition

Web3's need for law

【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity

Douban average 9 x. Five God books in the distributed field!
![[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files](/img/20/f7fc2204ca165dcea4af25cb054e9b.png)
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files

3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP

go swagger使用

服装企业部署MES管理系统的五个原因

C#/VB. Net to delete watermarks in word documents
随机推荐
Leetcode:minimum_ depth_ of_ binary_ Tree solutions
Increase 900w+ playback in 1 month! Summarize 2 new trends of top flow qiafan in station B
差异与阵列和阵列结构和链表的区别
Application analysis of face recognition
Lumion 11.0软件安装包下载及安装教程
用全连接+softmax对图片的feature进行分类
The panel floating with the mouse in unity can adapt to the size of text content
MySQL --- 常用函数 - 字符串函数
哈希表及完整注释
CSDN summer camp course project analysis
How to build a 32core raspberry pie cluster from 0 to 1
如何从0到1构建32Core树莓派集群
运维管理系统有哪些特色
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
Use of pgpool II and pgpooladmin
牛客编程题--必刷101之双指针篇
如何设计好接口测试用例?教你几个小技巧,轻松稿定
C#/VB.NET 删除Word文档中的水印
MMDetection3D加载毫米波雷达数据
KYSL 海康摄像头 8247 h9 isapi测试