delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/09/21/00:36:42

X-Spam-Check-By: sourceware.org
Date: Wed, 20 Sep 2006 21:36:29 -0700
From: Christopher Layne <clayne AT anodized DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: gdb attach to process to produce stacktrace
Message-ID: <20060921043629.GG6790@ns1.anodized.com>
References: <eerlgl$fnq$1 AT sea DOT gmane DOT org> <027801c6dccb$91bb4980$a501a8c0 AT CAM DOT ARTIMI DOT COM> <eerpq2$1a9$1 AT sea DOT gmane DOT org> <07400671-D3C8-4F0E-903A-1BB3233C6D31 AT andrew DOT cmu DOT edu>
Mime-Version: 1.0
In-Reply-To: <07400671-D3C8-4F0E-903A-1BB3233C6D31@andrew.cmu.edu>
User-Agent: Mutt/1.5.11
X-Assp-Spam-Prob: 0.00000
X-Assp-Whitelisted: Yes
X-Assp-Envelope-From: clayne AT ns1 DOT anodized DOT com
X-Assp-Intended-For: cygwin AT cygwin DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Wed, Sep 20, 2006 at 03:17:29PM -0400, Ethan Tira-Thompson wrote:
> For a quick example, try figuring out why this example program is  
> crashing... The idea is simple: set up an array of strings containing  
> 'a' through 'z', build a string from 100 random selections, and then  
> display the result.
> 
> No fair figuring it out from looking at the code (it's a suitably  
> subtle newbie type problem, though obfuscated enough it's not  
> glaringly obvious) -- pretend it's a "real" problem in a piece of  
> fairly complicated code that isn't just a dozen lines long, try using  
> gdb to figure it out. (for the lazy/hurried, answer posted here,  
> including comparison to what happens in cygwin: http://ethan.tira- 
> thompson.com/stuff/gdb-answer.html )

Had to admit to pull up the test case in a debugger because Ethan
was right, it wasn't obvious ;). Anyways, my method of dealing with
the immediate segfault type situation is to pull it up in gdb and
hope for a violation that will give me a useful backtrace. If that
doesn't occur, I just do a general 'b main' and next until I step
over the function that causes it and then do the same thing within
the violating function. In this case it was easy - since I recognized:

  37619 [main] whack 2976 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
  38212 [main] whack 2976 open_stackdumpfile: Dumping stack trace to whack.exe.stackdump

as being a typical buffer walk off *and* the fact that it wasn't a
large amount of iterations (which is really what made things to be
easy - otherwise it's serious pain).

int initStrs(char* strs[]) {
  // initialize a string for each letter^M
  int i;
  for(i=0; i<'z'-'a'; i++) {^M
    strs[i]=malloc(sizeof(char[2]));^M
    strs[i][0]='a'+i; // current letter^M
    strs[i][1]='\0';  // null terminate for a c-style string^M
  }
  return 26;
}

Culprit:

(gdb) p 'z' - 'a'
$16 = 25


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019