当前位置:网站首页>BUG destroyer!!Practical debugging skills are super comprehensive
BUG destroyer!!Practical debugging skills are super comprehensive
2022-07-31 04:01:00 【vpurple__】
目录
4.1一些调试的实例(Memory with stack area、Array element memory storage related knowledge
1.什么是bug?
第一次被发现的导致计算机错误的飞蛾,也是第一个计算机程序错误.
2.调试
2.1什么是调试
找bugThe process is debugging
调试(英语:Debugging / Debug),又称除错,是发现和减少计算机程序或电子仪器设备中程序 错误的一个过程.
2.2调试的基本步骤
1.发现程序错误的存在.
2.以隔离、消除等方式对错误进行定位.
3.确定错误产生的原因.
4.提出纠正错误的解决办法.
5.对程序错误予以改正,重新测试.
2.3.debug和release的介绍.
Debug 通常称为调试版本,它包含调试信息,It can be debugged step by step without any optimization,便于程序员调试程序.
Release 称为发布版本,It is often that there is no debug information,Can't debug step by step进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以便用户很好地使用.
3.windows环境调试介绍
3.1调试准备
在环境中选择 debug 选项,才能使代码正常调试.
3.2学会快捷键
最常使用的几个快捷键:
F5
启动调试,经常用来直接跳到下一个断点处.
F9
创建断点和取消断点, 断点的重要作用,可以在程序的任意位置设置断点. 这样就You can make the program stop execution at will at the desired position,继而一步步执行下去.(F5+F9常常搭配使用)
条件断点
F10
逐过程,通常用来处理一个过程,A process can be一次函数调用(When you encounter a function, go directly to it,不进入函数内部),或者是一条语句.
F11
逐语句,就是每次都执行一条语句,但是这个快捷键We can make our execution logic go inside the function(这是最常用的).
CTRL + F5
开始执行不调试,直接执行.如果你想让程序直接运行起来而不调试就可以直接使用
vs2022The screenshot of the debugging shortcut key is as follows:
If you want to know more shortcut keys,Click the link to the blog post below:(16条消息) VS中常用的快捷键_MrLisky的博客-CSDN博客_vs快捷键https://blog.csdn.net/mrlisky/article/details/72622009
3.3 调试的时候查看程序当前信息
A watch window is recommended.
观察内存
函数调用堆栈
查看汇编代码
when debugging is possible,右键转到反汇编
查看寄存器信息
4.多多动手,尝试调试,才能有进步.
一定要熟练掌握调试技巧.
初学者可能80%的时间在写代码,20%的时间在调试.
但是一个程序员可能20%的时间在写 程序,但是80%的时间在调试.
我们所讲的都是一些简单的调试.
以后可能会出现很复杂调试场景:多线程程序的调试等.
多多使用快捷键,提升效率.
4.1一些调试的实例(Memory with stack area、Array element memory storage related knowledge
#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 运行时错误
借助调试,逐步定位问题.最难搞.
大家好,这里是媛仔!!Welcome to Yuanzic语言进阶之路(复习中~,Hope this content can be helpful to you,也欢迎大家和我多多交流!!
边栏推荐
- three.js 制作3D相册
- LeetCode每日一练 —— OR36 链表的回文结构
- Port inspection steps - 7680 port analysis - Dosvc service
- The BP neural network
- idea工程明明有依赖但是文件就是显示没有,Cannot resolve symbol ‘XXX‘
- Implementation of a sequence table
- some of my own thoughts
- Difference between unallocated blocks and unused blocks in database files
- TCP和UDP详解
- SIP协议标准和实现机制
猜你喜欢
已解决(最新版selenium框架元素定位报错)NameError: name ‘By‘ is not defined
Zotero如何删除自动生成的标签
【C语言进阶】文件操作(一)
MySQL基础操作
IIR filter and FIR filter
Mysql 45 study notes (23) How does MYSQL ensure that data is not lost
LocalDate加减操作及比较大小
Daily practice of LeetCode - 138. Copy a linked list with random pointers
组件传值 provide/inject
(八)Math 类、Arrays 类、System类、Biglnteger 和 BigDecimal 类、日期类
随机推荐
Daily practice of LeetCode - 138. Copy a linked list with random pointers
endian mode
Safety 20220712
Summary of Huawei Distributed Storage FusionStorage Knowledge Points [Interview]
IIR filter and FIR filter
errno error code and meaning (Chinese)
Ambiguous method call.both
Difference between unallocated blocks and unused blocks in database files
interprocess communication
errno错误码及含义(中文)
Select the smoke test case, and make the first pass for the product package entering QA
Database implements distributed locks
[C language] Three-pointed chess (classic solution + list diagram)
BUG definition of SonarQube
Why don't you programmers make a living off your own projects?And have to work for someone else?
The application and practice of mid-to-platform brand advertising platform
(五)final、抽象类、接口、内部类
(5) final, abstract class, interface, inner class
Key Technologies of Interface Testing
已解决(最新版selenium框架元素定位报错)NameError: name ‘By‘ is not defined