如何学习C调试和最佳实践 [英] How to Learn C Debugging and Best Practices

查看:112
本文介绍了如何学习C调试和最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C中编写了一个Apache模块。在某些条件下,我可以把它解析为segfault,但是我不知道为什么。在这一点上,它可能是我的代码,它可能是我编译程序的方式,或者它可能是操作系统库中的一个错误(在dlopen()的调用中发生segfault)。



我尝试运行GDB和Valgrind没有成功。 GDB给我一个回溯到dlopen()系统调用,看起来没有意义。在Valgrind,这个bug实际上似乎消失了,或至少变得不可重复。另一方面,对于这些工具,我是一个全新的手段。



我对生产质量C编程有点新(我从C开始几年前,但从来没有专业工作。)我最喜欢学习调试程序的绳索是什么?我应该调查什么其他工具?总而言之,你如何找出如何应对新的错误挑战?



编辑:
为了澄清,我要感谢Sydius和dmckee的意见。我看了一下Apache的指南,并且很熟悉dlopen(和dlsym和dlclose)。我的模块大部分工作(它的大约3k行代码,只要我不激活这一节,事情似乎工作正常。)



<我想这是我原来的问题来自哪里 - 我不知道下一步该怎么做。我知道我没有使用GDB和Valgrind来充分发挥潜力。我知道我可能不会用正确的标记进行编译。但是我无法找出更多的东西。我可以找到告诉我我已经知道的初学者指南,以及告诉我超过我需要知道但没有指导的手册页。

解决方案

此链接可能有助于: Apache调试指南与您的具体问题。具体问题的经验是在一般情况下获得更好的最佳方式之一。


I've written an Apache module in C. Under certain conditions, I can get it to segfault, but I have no idea as to why. At this point, it could be my code, it could be the way I'm compiling the program, or it could be a bug in the OS library (the segfault happens during a call to dlopen()).

I've tried running through GDB and Valgrind with no success. GDB gives me a backtrace into the dlopen() system call that appears meaningless. In Valgrind, the bug actually seems to disappear or at least become non-reproducible. On the other hand, I'm a total novice when it comes to these tools.

I'm a little new to production quality C programming (I started on C many years ago, but have never worked professionally with it.) What is the best way for me to go about learning the ropes of debugging programs? What other tools should I be investigating? In summary, how do you figure out how to tackle new bug challenges?

EDIT: Just to clarify, I want to thank Sydius's and dmckee's input. I had taken a look at Apache's guide and am fairly familiar with dlopen (and dlsym and dlclose). My module works for the most part (it's at about 3k lines of code and, as long as I don't activate this one section, things seem to work just fine.)

I guess this is where my original question comes from - I don't know what to do next. I know I haven't used GDB and Valgrind to their full potential. I know that I may not be compiling with the exact right flags. But I'm having trouble figuring out more. I can find beginner's guides that tell me what I already know, and man pages that tell me more than I need to know but with no guidance.

解决方案

This link may help: Apache Debugging Guide with your specific problem. Experience with specific problems is one of the best ways to get better in the general case.

这篇关于如何学习C调试和最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆