Date: Sun, 19 Nov 2000 08:43:41 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: djgpp AT delorie DOT com Subject: Re: Debugger that can detect buffer overruns? In-Reply-To: <8v4346$tok$1@plato.wadham.ox.ac.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 Precedence: bulk [Sorry, I don't see the OP's message, so I'm replying to a response.] On 17 Nov 2000, J-P wrote: > In article <8v3s96$ssh$1 AT nnrp1 DOT deja DOT com>, wrote: > >I don't know. Maybe I'm just having trouble understanding the GDB > >documentation. Maybe it _does_ check for buffer overruns and I don't > >know how to use that feature. GDB can catch buffer overruns if you know which buffer and at which place is overrun. Suppose you have found that the 100th element of array[] is sometimes overrun. Then put a watchpoint on that element, like this: (gdb) watch array[100] and then run the program. When the value of array[100] changes, GDB will stop the program and show you the line of code which did that. Note that GDB lets you set watchpoints on absolute addresses as well, so you are not limited by the existing variables or array limits as declared in the program's sources. For example, if you know that the address 0xdeadbeef is overwritten, say this: (gdb) watch *(int *)0xdeadbeef to cause GDB to watch a 4-byte area starting at 0xdeadbeef. (This will only work if 0xdeadbeef is inside the valid limits of the DS segment.)