当前位置:网站首页>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语言进阶之路(复习中~,希望这篇内容对你可以有所帮助,也欢迎大家和我多多交流!!

边栏推荐
- 问题1:给你1-10的列表,实现列表输出,单数在左边,双数在右边。
- A brief introduction to the CheckboxListTile component of the basic components of Flutter
- Safety 20220718
- Redis 使用LIST做最新评论缓存
- Good place to download jar packages
- Why don't you programmers make a living off your own projects?And have to work for someone else?
- [C language] General method of expression evaluation
- $parent/$children 与 ref
- 微软 AI 量化投资平台 Qlib 体验
- exsl文件预览,word文件预览网页方法
猜你喜欢

Understanding and Using Unity2D Custom Scriptable Tiles (4) - Start to build a custom tile based on the Tile class (below)

强化学习:从入门到入坑再到拉屎

Postgresql 15 source code analysis (5) - pg_control

No qualifying bean of type question

《DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction》论文笔记

Learning DAVID Database (1)

No qualifying bean of type 问题
![[C language] General method of expression evaluation](/img/59/cf43b7dd16c203b4f31c1591615955.jpg)
[C language] General method of expression evaluation

SIP Protocol Standard and Implementation Mechanism

IDEA comment report red solution
随机推荐
Mysql 45 study notes (twenty-four) MYSQL master-slave consistency
Can‘t load /home/Iot/.rnd into RNG
Redis uses sorted set to cache latest comments
A brief introduction to the showDatePicker method of the basic components of Flutter
SQL Interview Questions (Key Points)
beforeDestroy与destroyed的使用
已解决(最新版selenium框架元素定位报错)NameError: name ‘By‘ is not defined
Can't load /home/Iot/.rnd into RNG
qlib自动化quant
LeetCode每日一练 —— OR36 链表的回文结构
浅识Flutter 基本组件之CheckBox组件
Implementation of a sequence table
RESTful api interface design specification
Unity2D 自定义Scriptable Tiles的理解与使用(四)——开始着手构建一个基于Tile类的自定义tile(下)
数据库文件中的未分配的块和未使用的块的区别
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
Understanding and Using Unity2D Custom Scriptable Tiles (4) - Start to build a custom tile based on the Tile class (below)
RESTful api接口设计规范
(五)final、抽象类、接口、内部类
BUG definition of SonarQube