GDB first impression

本文分享了作者首次使用GDB进行程序调试的经历,从以往使用printf语句的痛苦体验,到发现GDB的强大功能,如print命令的灵活运用,及与Emacs编辑器的无缝配合。GDB不仅提升了调试效率,还帮助作者深入理解了K&R内存分配器的代码。然而,遗憾的是,中国许多计算机科学学生并未在学校中接触到此类强大的工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I never use GDB before though I’ve heard of it long times ago. Well, I never use it simply because I never really debug program. And maybe I never write programs complicated enough that needs to debug. Though I’ve found time spent on debugging code is quite a lot. I never think of how to improve this. And I never care about the potential bugs left in the code as long as the code begins to work.

My previous experience with debugging is awful. Inserting printfs here and there and finally mess up the code. Changing here and there and later forget where have been changed.

I’m doing the labs of the Berkerley CS61C today and was required to used GDB to complete a exercise exploring the code of K&R’s memory allocator. This power tool get along well with Emacs editor which I’ve been using for studying this opencourse. To start gdb, you just fire it off from Emacs using the command M-x gdb.

The feature I love most is the print command. It make you feel like you are using a python shell. You can print out the value of a variable: ’p a’, a expression `p (int) A->array[5]' , assign values: `p a = 5', execute function: `p f(4, a)'. And In my very exercise, I use ((Header*)0x93db008)[-1].s.size to find out the size of allocated block. And there’s lots of other features I would like to explore later.

GNU has provided lots of powerful tools that make programmers’ life happier. But unfortunately most CS students in China are not get introduced to these powerful tools in their classroom.

转载于:https://www.cnblogs.com/sirkay777/archive/2009/03/09/1407324.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值