当前位置:网站首页>BUG消灭者!!实用调试技巧超全整理
BUG消灭者!!实用调试技巧超全整理
2022-07-31 04:00:00 【vpurple__】
目录
1.什么是bug?
第一次被发现的导致计算机错误的飞蛾,也是第一个计算机程序错误。
2.调试
2.1什么是调试
找bug的过程就是调试
调试(英语:Debugging / Debug),又称除错,是发现和减少计算机程序或电子仪器设备中程序 错误的一个过程。
2.2调试的基本步骤
1.发现程序错误的存在。
2.以隔离、消除等方式对错误进行定位。
3.确定错误产生的原因。
4.提出纠正错误的解决办法。
5.对程序错误予以改正,重新测试。
2.3.debug和release的介绍。
Debug 通常称为调试版本,它包含调试信息,可以一步一步调试并且不作任何优化,便于程序员调试程序。
Release 称为发布版本,它往往是没有调试信息,不能一步一步调试进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以便用户很好地使用。
3.windows环境调试介绍
3.1调试准备
在环境中选择 debug 选项,才能使代码正常调试。
3.2学会快捷键
最常使用的几个快捷键:
F5
启动调试,经常用来直接跳到下一个断点处。
F9
创建断点和取消断点, 断点的重要作用,可以在程序的任意位置设置断点。 这样就可以使得程序在想要的位置随意停止执行,继而一步步执行下去。(F5+F9常常搭配使用)
条件断点
F10
逐过程,通常用来处理一个过程,一个过程可以是一次函数调用(遇到函数直接过去,不进入函数内部),或者是一条语句。
F11
逐语句,就是每次都执行一条语句,但是这个快捷键可以使我们的执行逻辑进入函数内部(这是最常用的)。
CTRL + F5
开始执行不调试,直接执行。如果你想让程序直接运行起来而不调试就可以直接使用
vs2022调试快捷键截图如下:
如果想要了解更多的快捷键,可以点下面博文的链接:(16条消息) VS中常用的快捷键_MrLisky的博客-CSDN博客_vs快捷键https://blog.csdn.net/mrlisky/article/details/72622009
3.3 调试的时候查看程序当前信息
推荐使用监视窗口。
观察内存
函数调用堆栈
查看汇编代码
可以调试的时候,右键转到反汇编
查看寄存器信息
4.多多动手,尝试调试,才能有进步。
一定要熟练掌握调试技巧。
初学者可能80%的时间在写代码,20%的时间在调试。
但是一个程序员可能20%的时间在写 程序,但是80%的时间在调试。
我们所讲的都是一些简单的调试。
以后可能会出现很复杂调试场景:多线程程序的调试等。
多多使用快捷键,提升效率。
4.1一些调试的实例(含栈区内存、数组元素内存存放相关知识
#include <stdio.h>
int main()
{
int i = 0;
int arr[10] = {0};
for(i=0; i<=12; i++)
{
arr[i] = 0;
printf("hehe\n");
}
return 0;
}//死循环 在vs2019下
5.常见的coding技巧:
5.1注意事项
1. 使用assert
2. 尽量使用const修饰
3. 养成良好的编码风格
4. 添加必要的注释
5. 避免编码的陷阱
5.2示范,实现函数strcpy
/***
*char *strcpy(dst, src) - copy one string over another
*
*Purpose:
* Copies the string src into the spot specified by
* dest; assumes enough room.
*
*Entry:
* char * dst - string over which "src" is to be copied
* const char * src - string to be copied over "dst"
*
*Exit:
* The address of "dst"
*
*Exceptions:
*******************************************************************************/
char * strcpy(char * dst, const char * src)
{
char * cp = dst;
assert(dst && src);
while( *cp++ = *src++ )
; /* Copy src over dst */
return( dst );
}
5.3补充const修饰指针变量
const修饰指针变量的时候:
1. const如果放在*的左边,修饰的是指针指向的内容。
const int *p;
保证指针指向的内容不能通过指针来改 变。但是指针变量本身的内容可变。
2. const如果放在*的右边,修饰的是指针变量本身。
int *const p;
保证了指针变量的内容不能修改,但是指 针指向的内容,可以通过指针改变。
6. 编程常见的错误
6.1 编译型错误
语法错误。
直接看错误提示信息(双击),解决问题。或者凭借经验就可以搞定。相对来说简单。
6.2 链接型错误
出现在链接期间。
看错误提示信息,主要在代码中找到错误信息中的标识符,然后定位问题所在。一般是标识符名不 存在或者拼写错误。
6.3 运行时错误
借助调试,逐步定位问题。最难搞。
大家好,这里是媛仔!!欢迎来到媛仔c语言进阶之路(复习中~,希望这篇内容对你可以有所帮助,也欢迎大家和我多多交流!!
边栏推荐
- (tree) Last Common Ancestor (LCA)
- 已解决(最新版selenium框架元素定位报错)NameError: name ‘By‘ is not defined
- 强化学习:从入门到入坑再到拉屎
- Port inspection steps - 7680 port analysis - Dosvc service
- Knowledge Distillation 7: Detailed Explanation of Knowledge Distillation Code
- Thinking about data governance after Didi fines
- RESTful api接口设计规范
- Redis uses LIST to cache the latest comments
- C# 实现PLC的定时器
- Difference between unallocated blocks and unused blocks in database files
猜你喜欢
SIP协议标准和实现机制
binom二项分布,
type_traits元编程库学习
SIP Protocol Standard and Implementation Mechanism
Learning DAVID Database (1)
VS QT - ui does not display newly added members (controls) || code is silent
LeetCode每日一练 —— 138. 复制带随机指针的链表
Notes on the establishment of the company's official website (6): The public security record of the domain name is carried out and the record number is displayed at the bottom of the web page
《DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction》论文笔记
Summary of Huawei Distributed Storage FusionStorage Knowledge Points [Interview]
随机推荐
5. How does the SAP ABAP OData service support the $filter operation
SIP Protocol Standard and Implementation Mechanism
Detailed explanation of TCP (1)
Safety 20220718
(4) Recursion, variable parameters, access modifiers, understanding main method, code block
(树) 最近公共祖先(LCA)
SQL Interview Questions (Key Points)
postgresql 15源码浅析(5)—— pg_control
errno error code and meaning (Chinese)
endian mode
微软 AI 量化投资平台 Qlib 体验
volatile内存语义以及实现 -volatile写和读对普通变量的影响
扫雷游戏(c语言写)
[Swift] Customize the shortcut that pops up by clicking the APP icon
Implementation of a sequence table
Component pass value provide/inject
(Line segment tree) Summary of common problems of basic line segment tree
Smartcom Programming Level 4 - Magic Academy Lesson 6
数据库文件中的未分配的块和未使用的块的区别
《DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction》论文笔记