delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/07/24/03:47:34

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Sat, 24 Jul 2004 10:45:38 +0200
From: "Eli Zaretskii" <eliz AT gnu DOT org>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-Id: <2914-Sat24Jul2004104537+0300-eliz@gnu.org>
X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 1.8.9
In-reply-to: <20040724014454.16860.00001365@mb-m20.aol.com> (sterten@aol.com)
Subject: Re: strange error
References: <2719-Fri23Jul2004140734+0300-eliz AT gnu DOT org> <20040724014454 DOT 16860 DOT 00001365 AT mb-m20 DOT aol DOT com>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: sterten AT aol DOT com (Sterten)
> Newsgroups: comp.os.msdos.djgpp
> Date: 24 Jul 2004 05:44:54 GMT
> 
> C:\DJGPP>gdb qser3.exe        
> GNU gdb 5.2.1         
> Copyright 2002 Free Software Foundation, Inc.     
> GDB is free software, covered by the GNU General Public License, and you are 
> welcome to change it and/or distribute copies of it under certain conditions. 
> Type "show copying" to see the conditions.     
> There is absolutely no warranty for GDB. Type "show warranty" for details. 
> This GDB was configured as "i386-pc-msdosdjgpp"...    
> (no debugging symbols found)...       
> (gdb) run 16 1 5        
> Starting program: c:/djgpp/qser3.exe 16 1 5     
>           
> Program received signal SIGSEGV, Segmentation fault.    
> 0x00001cfc in ?? ()        

So far so good.  Is the address shown by GDB (0x00001cfc) identical to
what you see in the crash message when you run the program from the
command line, not under GDB?

> disassemble after SIGSEV gives:
> ...
> 0x168b <main+11>: mov $0xd270,%edx     
> 0x1690 <main+16>: push %esi      
> 0x1691 <main+17>: push %ebx      
> 0x1692 <main+18>: sub $0x3c,%esp     
> 0x1695 <main+21>: and $0xfffffff0,%esp     
> 0x1698 <main+24>: movl $0x0,0xf984     
> 0x16a2 <main+34>: movl $0x0,(%ecx,%eax,4)    
> 0x16a9 <main+41>: movl $0x0,(%edx,%eax,4)    
> 0x16b0 <main+48>: inc %eax      
> 0x16b1 <main+49>: mov %eax,0xf984     
> 0x16b6 <main+54>: cmp $0x62,%eax     
> 0x16b9 <main+57>: jle 0x16a2 <main+34>     
> 0x16bb <main+59>: cmpl $0x1,0x8(%ebp)     
> 0x16bf <main+63>: jle 0x1f43 <main+2243>    
> 0x16c5 <main+69>: push %eax      
> 0x16c6 <main+70>: mov 0xc(%ebp),%eax     
> 0x16c9 <main+73>: push $0x1a634      
> 0x16ce <main+78>: push $0x15e0      
> ---Type <return> to continue, or q <return> to quit---q    
> Quit          
> (gdb) quit         

Not good, you should continue the disassembly until it reaches the
address where it crashed (0x1cfc).  Alternatively, say

  (gdb) disassemble 0x1c80 0x1d20

to see only a small portion of the code around the crash address.
(But I suggest to produce the entire disassembly, so it is easier to
compare with what the compiler produces, see below.)

> now, maybe this can be used to find the line, where it crashed , but it's not
> easy.
> And then, we still don't know the first line,
> where an incorrect index occurred.

That can be found by compiling the source with switches that produce
assembly listing (see section 8.20 in the DJGPP FAQ, except that you
will also need to add the -g switch--this is a mistake in the FAQ).
Then you will be able to find the source line by comparing the
assembly listing produced by the compiler and the disassembly in the
debugger.

> There can be many incorrect indices
>  before without the program crashing.

If we find the machine instruction that crashed (the one at address
0x00001cfc), we will be able to tell the index and its value.

Bottom line, using the debugger in such cases might need some hard
work, but it is always the shortest way to the solution, because it
saves you the need to guess.

> I also tried to get the whole output with >>file or redir, 
> but failed

What exactly did you try, and how it failed?  I use redirection with
the debugger all the time, and it works for me.

- Raw text -


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