好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

C编程的调试技巧.ppt

64页
  • 卖家[上传人]:重生1****23
  • 文档编号:369270981
  • 上传时间:2023-11-21
  • 文档格式:PPT
  • 文档大小:1.12MB
  • / 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,则显示,。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.