Advertisement

How To

The basics of debugging in Code::Blocks

Softonic Editorial Team

Softonic Editorial Team

So, you’ve successfully created your first program in Code::Blocks – that is, you have written your source code, made any changes needed, and compiled and built your code. Maybe you got lucky and your program came out just right on the first try. But more likely you’ll need to make edits and debug your code in order to come out with a finished product that works properly.

So let’s learn how to debug in Code::Blocks, which is a popular IDE that many developers use to create code with C/C++ and other languages.

The basics of debugging in Code::Blocks

How to debug your program

Debugging your program in Code::Blocks might seem daunting at first, but after we review the process it will become second nature. The process of debugging involves tracing the program operation step by step. You also use the debugging process to place breakpoints where you wish the program to pause. A debugger can pause your program and you can watch the values of the variables that you have defined. This will help you to isolate errors or mistakes in the code. First, let’s talk about using breakpoints.

Using breakpoints

  1. Set a place in the code to have the program pause. To do this, pull down the Debug and click Run to cursor. The cursor should be over the first line of code where you plan to start the tracing process. 
  2. Move the cursor over the line where you want your program to stop. This is called a breakpoint. Now you can tell the debugger to run the program up to the cursor’s position, or line number. This allows you to see the point where your program malfunctions.

When the debugger detects a breakpoint, the program pauses and the debugger allows you to inspect your code. The breakpoint remains until you remove it. It can be toggled on and off by pressing F5. (Prior to running the program in debug mode, breakpoints will be marked with a red circle. )

Problematic areas of code can now be isolated between breakpoints for easier identification.

Using watches to monitor code variables

To monitor specific variables during the execution of the program, you should open the Watches window. This will highlight the variables in your code.

Do this by going to the Debug pull-down menu. Click Debugging Windows and then Watches. The Watches menu shows a list of the variables in your code. If nothing is next to the listed variable, there is currently nothing assigned to it in the program.

Debug tips

Yellow markers are displayed on the left side of the screen beside the location of breakpoints in the code when the running program has paused. This lets you see the exact location of the breakpoint.

To advance to next line of code, select Next line from the Debug menu. You can also use the F7 key as a keyboard shortcut to accomplish the same task. This allows you to walk through your code line by line in search of errors. This reduces troubleshooting time greatly.

When you are finished debugging, click Continue, and your program will run to the end. If your program is stuck and will not advance, you have the option to choose Stop debugging from the Debug menu.
When you run the debug process, the yellow triangle will show you where the breakpoint has stopped the program from running. The red circle will show the various locations that the breakpoints have been placed throughout the code.


Now that you understand the basics of debugging in Code::Blocks, you are on your way to completion of a successful program. When you have completed the debugging process Code::Blocks will ask you if you want to save your workspace. If so, click yes; it is now safe to exit the program.

Sources:

http://www.codeblocks.org/

http://www.sci.brooklyn.cuny.edu/~goetz/codeblocks/codeblocks-instructions.pdf

https://en.wikipedia.org/wiki/Code::Blocks

Related links:

Download Code::Blocks

Softonic Editorial Team

Softonic Editorial Team

Editorial Guidelines

民权资讯网木莲杭州放心的网站关键词优化和健康有关的公司起名惠普电脑怎么样麦饭石真空石头养生锅鼠年的婴儿起名大全周公解梦老公哥斯拉观后感300字歌剧卡门观后感四个人的公司起名周易四柱八字命理日喀则网站制作用修起名字起英文名字哪些软件竞价和seo起名工具下载兵器博物馆观后感广东网站建设定制玉溪专业网站制作多少钱香河武老师起名多少钱广州家具网站制作保定限号适合女孩起名的诗句词荒野兵器xf金手指常用的平面设计的网站上海网站建设代码本命年从什么时候算起深圳网站建设简介本地大连网站优化易学八字算命少年生前被连续抽血16次?多部门介入两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”淀粉肠小王子日销售额涨超10倍高中生被打伤下体休学 邯郸通报单亲妈妈陷入热恋 14岁儿子报警何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言张家界的山上“长”满了韩国人?男孩8年未见母亲被告知被遗忘中国拥有亿元资产的家庭达13.3万户19岁小伙救下5人后溺亡 多方发声315晚会后胖东来又人满为患了张立群任西安交通大学校长“重生之我在北大当嫡校长”男子被猫抓伤后确诊“猫抓病”测试车高速逃费 小米:已补缴周杰伦一审败诉网易网友洛杉矶偶遇贾玲今日春分倪萍分享减重40斤方法七年后宇文玥被薅头发捞上岸许家印被限制高消费萧美琴窜访捷克 外交部回应联合利华开始重组专访95后高颜值猪保姆胖东来员工每周单休无小长假男子被流浪猫绊倒 投喂者赔24万小米汽车超级工厂正式揭幕黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发当地回应沈阳致3死车祸车主疑毒驾恒大被罚41.75亿到底怎么缴妈妈回应孩子在校撞护栏坠楼外国人感慨凌晨的中国很安全杨倩无缘巴黎奥运校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变王树国卸任西安交大校长 师生送别手机成瘾是影响睡眠质量重要因素国产伟哥去年销售近13亿阿根廷将发行1万与2万面值的纸币兔狲“狲大娘”因病死亡遭遇山火的松茸之乡“开封王婆”爆火:促成四五十对奥巴马现身唐宁街 黑色着装引猜测考生莫言也上北大硕士复试名单了德国打算提及普京时仅用姓名天水麻辣烫把捣辣椒大爷累坏了

民权资讯网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化