当前位置:网站首页>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语言进阶之路(复习中~,希望这篇内容对你可以有所帮助,也欢迎大家和我多多交流!!
边栏推荐
- postgresql 15源码浅析(5)—— pg_control
- (4) Recursion, variable parameters, access modifiers, understanding main method, code block
- The use of beforeDestroy and destroyed
- Unity2D 自定义Scriptable Tiles的理解与使用(四)——开始着手构建一个基于Tile类的自定义tile(下)
- Redis uses sorted set to cache latest comments
- [C language] General method for finding the sum of the greatest common factor and the least common multiple of two integers m and n, the classical solution
- IDEA comment report red solution
- Difference between unallocated blocks and unused blocks in database files
- Daily practice of LeetCode - palindrome structure of OR36 linked list
- Day32 LeetCode
猜你喜欢
浅识Flutter 基本组件之CheckboxListTile组件
IDEA常用快捷键与插件
BP神经网络
SIP Protocol Standard and Implementation Mechanism
(4) Recursion, variable parameters, access modifiers, understanding main method, code block
[C language] General method of base conversion
[Dynamic programming] Maximum sum of consecutive subarrays
A brief introduction to the CheckBox component of the basic components of Flutter
Why don't you programmers make a living off your own projects?And have to work for someone else?
What is a system?
随机推荐
The els block moves the boundary to the right, and accelerates downward.
自己的一些思考
postgresql 15源码浅析(5)—— pg_control
Difference between unallocated blocks and unused blocks in database files
Redis counts new and retained users
Detailed explanation of TCP (2)
Why don't you programmers make a living off your own projects?And have to work for someone else?
Safety 20220709
A brief introduction to the CheckboxListTile component of the basic components of Flutter
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
qlib自动化quant
LeetCode每日一练 —— OR36 链表的回文结构
从滴滴罚款后数据治理思考
Understanding and Using Unity2D Custom Scriptable Tiles (4) - Start to build a custom tile based on the Tile class (below)
日志级别 和 打印log注意
[Swift]自定义点击APP图标弹出的快捷方式
A brief introduction to the CheckBox component of the basic components of Flutter
高等数学---第九章二重积分
What is a system?
el-image标签绑定点击事件后没有有用