This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to find line number of illegal array element access


Bud, Tim

Thanks for your replies to my query.

For completeness, in case anyone else is reading this, I note that the correct compile line for the test program to enable line numbers to be found after the illegal array element access seems to be a synthesis of that suggested by Tim and Bud:

gfortran -static -g -fbounds-check a.f

Following this with the gdb prescription below gives the source code line number nicely.

Thanks again.

Roderick

Bud Davis wrote:
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?




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]