This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: How to find line number of illegal array element access
- From: Bud Davis <bdavis9659 at sbcglobal dot net>
- To: tprince at myrealbox dot com, Roderick Johnstone <rmj at ast dot cam dot ac dot uk>
- Cc: fortran at gcc dot gnu dot org
- Date: Sat, 29 Apr 2006 05:46:48 -0700 (PDT)
- Subject: Re: How to find line number of illegal array element access
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=sbcglobal.net; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=KUAivZXgMnxxPSjjWIw4WRmtVkqmxzDRef/IJYlCMcBlTSjROBDVPlYvtCFUEERRsrYlf4M3tD9jpEIsWuaHOPKh2VFDnzsAUU9foGTZs3ZB1fU86e8dxX8fHUQHpSpNG+YnUoIf9vBlFi46cnqXxi1hTHXmDSFX+xIBy2Bww7I= ;
here is a little example that shows how to do this
until the runtime error can print out the file name
and line number....
[bdavis@gfortran ~]$ cat a.f
integer x(10)
do i = 1,25
x(i) = i
enddo
end
[bdavis@gfortran ~]$ /usr/local/bin/gfortran -static
-fbounds-check a.f
[bdavis@gfortran ~]$ gdb a.out
GNU gdb 6.4
Copyright 2005 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 "i686-pc-linux-gnu"...Using
host libthread_db library
"/lib/tls/libthread_db.so.1".
(gdb) break _gfortran_runtime_error
Breakpoint 1 at 0x8048996: file
../../../gcc/libgfortran/runtime/error.c, line 328.
(gdb) run
Starting program: /home/bdavis/a.out
Breakpoint 1, *_gfortrani_runtime_error (
message=0x80aaa2c "Array reference out of bounds")
at ../../../gcc/libgfortran/runtime/error.c:329
329 ../../../gcc/libgfortran/runtime/error.c: No
such file or directory.
in ../../../gcc/libgfortran/runtime/error.c
(gdb) bt
#0 *_gfortrani_runtime_error (
message=0x80aaa2c "Array reference out of bounds")
at ../../../gcc/libgfortran/runtime/error.c:329
#1 0x08048253 in MAIN__ ()
#2 0x080482a7 in main (argc=1, argv=0xbfe4f0c4)
at ../../../gcc/libgfortran/fmain.c:18
(gdb)
HTH,
bud davis
--- Tim Prince <timothyprince@sbcglobal.net> wrote:
> Roderick Johnstone wrote:
> > Hi
> >
> > I've been using the -fbounds-check option to
> gfortran to check for
> > illegal array element accesses at run time. Is it
> possible to get the
> > source code line number where the illegal access
> was made? If so how?
> >
> with -g, running under gdb?
>
>