C编程的调试技巧.ppt
64页主要内容vVC+集成开发环境v调试方法v如何独立解决问题v编程规范一、集成开发环境的熟悉保存、全部保存打开最近的工程给工程中添加文件查找文件在指定目录下的某类型文件中搜索所有包含某字符串的文件Debug:带有调试信息,文件大Release:没有调试信息,不能调试,文件小切换Debug模式和Release模式比较文件大小编译(编译(ctrl+F7):编译源文件到目标文件):编译源文件到目标文件构建(构建(F7):链接目标文件和库函数为可执行文件,如无目标文件则先生成):链接目标文件和库函数为可执行文件,如无目标文件则先生成清洁:删掉清洁:删掉debug或者或者release版本的所有中间文件和可执行文件版本的所有中间文件和可执行文件调试调试单步执行(单步执行(F10):单步执行,遇到函数调用时把其当作一条语句执行):单步执行,遇到函数调用时把其当作一条语句执行深入函数的单步执行(深入函数的单步执行(F11):单步执行,遇到函数调用是深入到其内部):单步执行,遇到函数调用是深入到其内部执行到光标处(执行到光标处(ctrl+F10):一次执行完光标前的所有语句,并停到光标处):一次执行完光标前的所有语句,并停到光标处跳出(跳出(shift+F11):执行完当前函数的所有剩余代码,并从函数跳出):执行完当前函数的所有剩余代码,并从函数跳出重新开始调试(重新开始调试(ctrl+shift+F5):重新开始调试过程):重新开始调试过程结束调试(结束调试(shift+F5):执行完程序的剩余部分,结束调试):执行完程序的剩余部分,结束调试设置设置/取消断点(取消断点(F9):在某一行设置和取消断点):在某一行设置和取消断点当前执行的语句当前执行的语句堆栈的内容:函数调用关系堆栈的内容:函数调用关系从这里可以从这里可以查看内存数据查看内存数据程序执行过程中的一程序执行过程中的一些变量会显示在这里些变量会显示在这里著名的著名的watch窗口:看变量窗口:看变量表达式、地址等各种信息表达式、地址等各种信息寄存器当前值寄存器当前值二、调试方法树立正确的编程方法论v没有解决不了的问题,树立编程信心v按照正确的方法来编程从实践中体会解决问题的思路、编程的思想熟练掌握语法,数据结构,算法、模式,底层环境按照编程规范来编写代码充分利用各种资源:v调试器vmsdnv网络搜索引擎常用调试手段1.利用编译器的输出信息排除错误2.利用调试器的调试功能单步、run to cursor、断点、条件断点、查看堆栈、利用watch窗口查看变量、表达式的值3.分段调试法、增量调试法4.利用flush人为刷新缓冲区5.修改输出信息,增加标志位6.利用输出语句打印调试信息7.通过堆栈观察函数调用情况8.综合程序调试方法9.注释的技巧、条件编译几个简单例子#include#includevoid main()coutsetw(10)十进制十进制setw(10)二进制二进制setw(10)八进制八进制“setw(10)十六进制十六进制endl;for(int i=1;i=156;i+)coutsetw(10)deci=1;j/=2)if(d/j=1)cout1;if(d/j=0)cout0;d=d%j;coutsetw(10)octisetw(10)hexiendl;一个编程风格非常糟糕的例子:一个编程风格非常糟糕的例子:/*FILE COMMENT*System Name:for eduction(NO TRANSFERRING)*File Name :e05b.c*Contents :embedded C language entrance course*:exercise 5B:program using pointer*:乮乮pass one-dimensional array to function)*Model :for OAKS8-LCD Board*CPU :R8C/Tiny series*Compiler :NC30WA(V.5.30 Release 1)*OS :not be used*Programmer :RENESAS Semiconductor Training Center*Note :for OAKS8-R5F21114FP(R8C/11 group,20MHz)*COPYRIGHT(C)2004 RENESAS TECHNOLOGY CORPORATION *AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED*History :*FILE COMMENT END*/*include file*/#include defs.h/*define common symbol*/#include oaks8lib.h/*for function to deal with OAKS8-LCDBoard peripheral*/*define function prototype*/int main(void);static void get_string(unsigned char*message,unsigned char*buff);/*input string*/static int get_strlength(unsigned char*str);/*get string length*/static void print_dec(unsigned char*message,int dec);/*display decimal number in LCD*/*FUNC COMMENT*ID :1.0*function name:main*function :call function to get string length,display result*parameter :none*return :result 0:normal end*function used:get_strlength*notice :none*History :*FUNC COMMENT END*/int main(void)unsigned char buff10+1;/*define variable to save string input from key matrix*/int count;/*define variable for save number of character*/while(1)/*input string from key matrix*/get_string(Str=,buff);/*call function to get string length*/*pass address of array saving string,get string length*/count=get_strlength(buff);/*display string length in LCD*/print_dec(Len=,count);return 0;/*FUNC COMMENT*ID :1.1*function name:get_string*function :input string from key matrix*parameter :message:pointer to input waiting message*:buff :pointer to space saving string input*return :none*function used:none*notice :none*History :*FUNC COMMENT END*/static void get_string(unsigned char*message,unsigned char*buff)/*define function to input string*/LCD_puts(message);/*display message*/SW_gets(buff);/*input string from key matrix*/LCD_puts(buff);/*display string input*/LCD_putchar(n);/*return*/*FUNC COMMENT*ID :1.2*function name:get_strlength*function :refer string using pointer passed as argument,return length*parameter :str:address of string to count length*return :length*function used:none*notice :none*History :*FUNC COMMENT END*/static int get_strlength(unsigned char*str)/*define function to get string length*/int len=0;/*define and initialize variable for string length*/*refer every character in one-dimensional array buff pointed by*/*pointer str,count up until detect(0)at end of string*/while(0!=*str+)len+;/*count number of character*/return len;/*return length*/*FUNC COMMENT*ID :1.3*function name:print_dec*function :display decimal number in LCD*parameter :message:pointer to input waiting message*:dec :decimal number to be displayed*return :none*function used:none*notice :none*History :*FUNC COMMENT END*/static void print_dec(unsigned char*message,int dec)/*define function to display decimal number in LCD*/LCD_puts(message);/*display message*/LCD_putdec(dec);/*display decimal number in LCD*/LCD_putchar(n);/*return*/*end of file*/一个编程风格良好的例子:一个编程风格良好的例子:结 论 1永远不要写过长的语句,应该让代码尽可能简单;永远不要把两条语句写在一行中,以便于调试。
include void main()float num1,num2,outcome;char op,a;do coutput two numbers:num1num2endl;coutenter its operater:opendl;if(num2!=0)switch(op)case*:outcome=num1*num2;break;case/:outcome=num1/num2;break;case+:outcome=num1+num2;break;case-:outcome=num1-num2;break;default:coutthey can not be workn;coutthe outcome isoutcomeendl;else couto can not as a dividern;coutaendl;while(a=y);两个数的算术运算两个数的算术运算/如果输入字符如果输入字符a,则显示,。

卡西欧5800p使用说明书资料.ppt
锂金属电池界面稳定化-全面剖析.docx
SG3525斩控式单相交流调压电路设计要点.doc
话剧《枕头人》剧本.docx
重视家风建设全面从严治党治家应成为领导干部必修课PPT模板.pptx
黄渤海区拖网渔具综合调查分析.docx
2024年一级造价工程师考试《建设工程技术与计量(交通运输工程)-公路篇》真题及答案.docx
【课件】Unit+3+Reading+and+Thinking公开课课件人教版(2019)必修第一册.pptx
嵌入式软件开发流程566841551.doc
生命密码PPT课件.ppt
爱与责任-师德之魂.ppt
制冷空调装置自动控制技术讲义.ppt


