C编程:使用pthreads进行调试 [英] C Programming: Debugging with pthreads

查看:205
本文介绍了C编程:使用pthreads进行调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初调整的最难的事情之一是我在C中用pthread进行的第一次激烈的体验编程。我习惯了解下一行要运行的代码是什么,我的大部分调试技术都围绕着这个期望。

One of the hardest things for me to initially adjust to was my first intense experience programming with pthreads in C. I was used to knowing exactly what the next line of code to be run would be and most of my debugging techniques centered around that expectation.

在C中使用pthreads调试一些好的技术是什么?您可以在没有任何添加的工具,您使用的工具或任何有助于您调试的其他工具的情况下,建议个人方法。

What are some good techniques to debugging with pthreads in C? You can suggest personal methodologies without any added tools, tools you use, or anything else that helps you debug.

P.S。我在linux中使用gcc进行C编程,但不要让这一定限制你的答案。

P.S. I do my C programming using gcc in linux, but don't let that necessarily restrain your answer

推荐答案

Valgrind 是查找种族条件和pthread API漏洞的绝佳工具。它保存程序存储器(或者可能是共享资源)访问的模型,并且即使在错误是良性的时也会检测到丢失的锁(这当然意味着在稍后的时候它将完全意外地变得不太好)。

Valgrind is an excellent tool to find race conditions and pthreads API misuses. It keeps a model of program memory (and perhaps of shared resources) accesses and will detect missing locks even when the bug is benign (which of course means that it will completely unexpectedly become less benign at some later point).

要使用它,您调用 valgrind --tool = helgrind 这里是其手册。另外,有 valgrind --tool = drd 手册)。 Helgrind和DRD使用不同的模型,以便它们检测重叠但可能不同的错误集合。

To use it, you invoke valgrind --tool=helgrind, here is its manual. Also, there is valgrind --tool=drd (manual). Helgrind and DRD use different models so they detect overlapping but possibly different set of bugs. False positives also may occur.

无论如何,valgrind为我保存了无数小时的调试(并非所有的调试)。

Anyway, valgrind has saved countless hours of debugging (not all of them though :) for me.

这篇关于C编程:使用pthreads进行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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