From owner-freebsd-questions@FreeBSD.ORG Sun Jul 20 14:35:57 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5598E106566C for ; Sun, 20 Jul 2008 14:35:57 +0000 (UTC) (envelope-from af300wsm@gmail.com) Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.229]) by mx1.freebsd.org (Postfix) with ESMTP id 268D88FC0A for ; Sun, 20 Jul 2008 14:35:56 +0000 (UTC) (envelope-from af300wsm@gmail.com) Received: by rv-out-0506.google.com with SMTP id b25so1140915rvf.43 for ; Sun, 20 Jul 2008 07:35:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :user-agent:cc:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id; bh=JeZcsoo0OQ3q0inU0CSOrUvzCZLTBmkFYb+uA+IbfmY=; b=JOfUOxa2Q6podlbtqOs2F7MpGHOugBgJBwM8v594LOAr0I0xqDidUazS9hiClLg50k 1Go1mL2/76DftZfGVZxR4fqKJTQIBctvtL7/oimiLbR9o44ptiIQrp1ZzW7vgCzDYzhX qJCjBL0GkJqnisrInVrFemrjxf66sl3yoBxZ0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:message-id; b=hm6mxhyPQnLAwBA27Wx8IGaniO5GgPdca1Ot8Zh1EL6erbwzRBHErsL69NjCV/YIN4 T0kvF1gca246nbjPHPrr006T7Y11DtKXoayqYmC4juTMsiKt9YK691fF56C2Nvh4qeyU ymylerPdN6gpnqykAXqFLd0+S5F0ww9ivIMfE= Received: by 10.141.15.19 with SMTP id s19mr1264940rvi.205.1216564556627; Sun, 20 Jul 2008 07:35:56 -0700 (PDT) Received: from sniper ( [71.221.183.251]) by mx.google.com with ESMTPS id k41sm6764061rvb.3.2008.07.20.07.35.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 20 Jul 2008 07:35:55 -0700 (PDT) From: Andrew Falanga To: freebsd-questions@freebsd.org Date: Sun, 20 Jul 2008 08:35:21 -0600 User-Agent: KMail/1.9.6 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200807200835.21640.af300wsm@gmail.com> Cc: Edward Sutton Subject: Re: Any advice for learning debugging threading and stack corruption problems for c/c++? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Jul 2008 14:35:57 -0000 On Wednesday 16 July 2008 13:41:46 Edward Sutton wrote: > I have had a very hard time trying to debug which has hindered my work on > some projects. In particular I have had trouble properly grasping how to > work with debugging multi threaded applications, memory errors, and stack > corruption. I know that it is not a five minute learning process to absorb > such knowledge, but I have not yet found helpful references. I have had > best luck trying to logically guess a location close to the problem, then > setting a break and walking through the code. Once I hit a segfault, I run > through the code with a breakpoint bringing me to just before the problem, > but do not always understand how to go further. Strange things I see look > like bad pointer addresses or the problems being caused within another > thread. Since moving to FreeBSD7, I have been unable to use valgrind (which > did not seem to help much on multi threaded apps) and I have not found a > way to test binaries in the work directories and have had to install it to > test it. At present, either gdb alone or kdbg seem to be the only ways I > have been able to get even partially reliable responses from gdb because > other interfaces disregard breakpoints and interrupts to execution. Are > such difficulties common? On another similar topic, is there a good place > to start learning about limitations to system internals, such as > kern.ipc.shmmax and why I may 'not' want to set it to excessively high > values or how other values relate to changing it? How can I tell what cap > is occurring, whether it be a system limit or something controlled within > the app such as with pthread_attr_setstacksize() and how are 'proper' > values determined? The books "advanced programming in the unix environment" > and "programming with posix threads" help me learn the unix world a bit > better, but without debugging knowledge I find it hard to get anywhere with > writing more than my high school level of programs and very difficult to > get anywhere on the projects of others once threads and/or dynamic memory > is involved. Any suggested course for further study from here? > Thanks again, > Edward Sutton, III Debugging threaded applications is an exercise in frustration and downright irritation. There aren't many easy methods. It seems that you're already familiar with gdb so brush up on how to attach to specific threads within the application and such. Usually, it seems that problems with multi-threaded programming come from two threads trying to access the same structure, or object, at the same time. Look through your code and make sure you're not doing something like this. For example, one thread is trying to read from the same file another is trying to read from thus getting file pointers confused. Please note that this scenario only causes problems if the file was opened in one thread and then the file handle was passed to two others (probably not the best way to do things but . . .). Andy