GDB first impression

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值