public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped)
@ 2020-06-23  1:26 yansendao at huawei dot com
  2021-02-03 12:40 ` [Bug fortran/26155] " vries at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: yansendao at huawei dot com @ 2020-06-23  1:26 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26155

            Bug ID: 26155
           Summary: p cos(alat(j)) command make gdb Aborted (core dumped)
           Product: gdb
           Version: 10.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
          Assignee: unassigned at sourceware dot org
          Reporter: yansendao at huawei dot com
  Target Milestone: ---

Created attachment 12646
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12646&action=edit
fortran been debug

$ gfortran licm-print.F90 -g3 -O0
$ gdb a.out 
GNU gdb (GDB) 10.0.50.20200508-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) b 16
Breakpoint 1 at 0x400a20: file licm-print.F90, line 16.
(gdb) r
Starting program: /home/yansendao/tmp/alias/a.out 

Breakpoint 1, mydepart (rr0=..., alat=..., n=10) at licm-print.F90:16
16                if (rr0(k,j) <= 0.0d0) rr0(k,j) = rr0(k,j) + 2.0*cos(alat(j))
(gdb) p j
$1 = 1
(gdb) p alat(j)
$3 = 10
(gdb) p cos(alat(j))
Aborted (core dumped)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/26155] p cos(alat(j)) command make gdb Aborted (core dumped)
  2020-06-23  1:26 [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped) yansendao at huawei dot com
@ 2021-02-03 12:40 ` vries at gcc dot gnu.org
  2021-02-03 12:49 ` vries at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: vries at gcc dot gnu.org @ 2021-02-03 12:40 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26155

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |andrew.burgess at embecosm dot com
                   |                            |, vries at gcc dot gnu.org
   Last reconfirmed|                            |2021-02-03
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
Reproduced:
...
$ gfortran test.F90 -g -O0
$ gdb -batch a.out -ex start -ex "p cos(10)"
Temporary breakpoint 1 at 0x400b3d: file test.F90, line 31.

Temporary breakpoint 1, MAIN__ () at test.F90:31
31          DO i = 1, n
Aborted (core dumped)
...

In more detail:
...
Temporary breakpoint 1, MAIN__ () at test.F90:31
31          DO i = 1, n

Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
0x00000000006ab78e in evaluate_subexp_f (expect_type=0x0, exp=0x2067bf0,
pos=0x7fffffffd3bc, 
    noside=EVAL_NORMAL) at gdb/f-lang.c:938
938                           = TYPE_FIELD_ARTIFICIAL (value_type (arg1), tem -
1);
...

So tem is:
...
(gdb) p tem
$2 = 1
...
and value_type (arg1) is :
...
(gdb) p value_type (arg1)
$1 = (type *) 0x21cc140
(gdb) call recursive_dump_type ($1, 0)
type node 0x21cc140
name '<text gnu-indirect-function variable, no debug info>' (0xe5f160)
code 0x7 (TYPE_CODE_FUNC)
length 1
objfile 0x224c490
target_type 0x0
pointer_type 0x0
reference_type 0x0
type_chain 0x21cc140
instance_flags 0x0
flags
nfields 0 0x0
calling_convention 0
...

So, we do TYPE_FIELD_ARTIFICIAL($1, 0).

The macro TYPE_FIELD_ARTIFICIAL is defined like this:
...
#define TYPE_FIELD_ARTIFICIAL(thistype, n) FIELD_ARTIFICIAL((thistype)->field
(n))
...
so we try to access field 0 of type $1, but the type has no fields (see nfields
in the recursive type dump).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/26155] p cos(alat(j)) command make gdb Aborted (core dumped)
  2020-06-23  1:26 [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped) yansendao at huawei dot com
  2021-02-03 12:40 ` [Bug fortran/26155] " vries at gcc dot gnu.org
@ 2021-02-03 12:49 ` vries at gcc dot gnu.org
  2021-02-25 10:33 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: vries at gcc dot gnu.org @ 2021-02-03 12:49 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26155

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
Tentative patch:
...
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index bd6ef20f9b1..3b402cf1822 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -934,6 +934,8 @@ evaluate_subexp_f (struct type *expect_type, struct
expression *ex
p,
                   Infinite recursion ensues.  */
                if (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC)
                  {
+                   if (tem - 1 >= value_type (arg1)->num_fields ())
+                       error (_("Cannot find argument type"));
                    bool is_artificial
                      = TYPE_FIELD_ARTIFICIAL (value_type (arg1), tem - 1);
                    argvec[tem] = fortran_argument_convert (argvec[tem],
...
with which we have:
...
$ gdb -batch a.out -ex start -ex "p cos (10)"
Temporary breakpoint 1 at 0x400b3d: file test.F90, line 31.

Temporary breakpoint 1, MAIN__ () at test.F90:31
31          DO i = 1, n
Cannot find argument type
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/26155] p cos(alat(j)) command make gdb Aborted (core dumped)
  2020-06-23  1:26 [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped) yansendao at huawei dot com
  2021-02-03 12:40 ` [Bug fortran/26155] " vries at gcc dot gnu.org
  2021-02-03 12:49 ` vries at gcc dot gnu.org
@ 2021-02-25 10:33 ` cvs-commit at gcc dot gnu.org
  2021-02-25 10:43 ` andrew.burgess at embecosm dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-02-25 10:33 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26155

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Andrew Burgess <aburgess@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=68337b8be308cd309727bbe022ce9ce5d38f426a

commit 68337b8be308cd309727bbe022ce9ce5d38f426a
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Fri Nov 13 10:39:23 2020 +0000

    gdb/fortran: don't access non-existent type fields

    When attempting to call a Fortran function for which there is no debug
    information we currently trigger undefined behaviour in GDB by
    accessing non-existent type fields.

    The reason is that in order to prepare the arguments, for a call to a
    Fortran function, we need to know the type of each argument.  If the
    function being called has no debug information then obviously GDB
    doesn't know about the argument types and we should either give the
    user an error or pick a suitable default.  What we currently do is
    just assume the field exist and access undefined memory, which is
    clearly wrong.

    The reason GDB needs to know the argument type is to tell if the
    argument is artificial or not, artificial arguments will be passed by
    value while non-artificial arguments will be passed by reference.

    An ideal solution for this problem would be to allow the user to cast
    the function to the correct type, we already do this to some degree
    with the return value, for example:

      (gdb) print some_func_ ()
      'some_func_' has unknown return type; cast the call to its declared
return type
      (gdb) print (integer) some_func_ ()
      $1 = 1

    But if we could extend this to allow casting to the full function
    type, GDB could figure out from the signature what are real
    parameters, and what are artificial parameters.  Maybe something like
    this:

      (gdb) print ((integer () (integer, double)) some_other_func_ (1, 2.3)

    Alas, right now the Fortran expression parser doesn't seem to support
    parsing function signatures, and we certainly don't have support for
    figuring out real vs artificial arguments from a signature.

    Still, I think we can prevent GDB from accessing undefined memory and
    provide a reasonable default behaviour.

    In this commit I:

      - Only ask if the argument is artificial if the type of the argument
      is actually known.

      - Unknown arguments are assumed to be artificial and passed by
      value (non-artificial arguments are pass by reference).

      - If an artificial argument is prefixed with '&' by the user then we
      treat the argument as pass-by-reference.

    With these three changes we avoid undefined behaviour in GDB, and
    allow the user, in most cases, to get a reasonably natural default
    behaviour.

    gdb/ChangeLog:

            PR fortran/26155
            * f-lang.c (fortran_argument_convert): Delete declaration.
            (fortran_prepare_argument): New function.
            (evaluate_subexp_f): Move logic to new function
            fortran_prepare_argument.

    gdb/testsuite/ChangeLog:

            PR fortran/26155
            * gdb.fortran/call-no-debug-func.f90: New file.
            * gdb.fortran/call-no-debug-prog.f90: New file.
            * gdb.fortran/call-no-debug.exp: New file.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/26155] p cos(alat(j)) command make gdb Aborted (core dumped)
  2020-06-23  1:26 [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped) yansendao at huawei dot com
                   ` (2 preceding siblings ...)
  2021-02-25 10:33 ` cvs-commit at gcc dot gnu.org
@ 2021-02-25 10:43 ` andrew.burgess at embecosm dot com
  2021-02-25 11:58 ` vries at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: andrew.burgess at embecosm dot com @ 2021-02-25 10:43 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26155

Andrew Burgess <andrew.burgess at embecosm dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #4 from Andrew Burgess <andrew.burgess at embecosm dot com> ---
Tom,

Sorry I didn't spot you'd commented on this bug.  I've had this patch sat on
the mailing list since last year, but only got around to addressing the
feedback and merging it recently.

This issue should be resolved now.  Feel free to reopen the bug if you continue
to see this problem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/26155] p cos(alat(j)) command make gdb Aborted (core dumped)
  2020-06-23  1:26 [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped) yansendao at huawei dot com
                   ` (3 preceding siblings ...)
  2021-02-25 10:43 ` andrew.burgess at embecosm dot com
@ 2021-02-25 11:58 ` vries at gcc dot gnu.org
  2021-02-25 12:00 ` vries at gcc dot gnu.org
  2021-02-25 14:45 ` tromey at sourceware dot org
  6 siblings, 0 replies; 8+ messages in thread
From: vries at gcc dot gnu.org @ 2021-02-25 11:58 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26155

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.1

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/26155] p cos(alat(j)) command make gdb Aborted (core dumped)
  2020-06-23  1:26 [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped) yansendao at huawei dot com
                   ` (4 preceding siblings ...)
  2021-02-25 11:58 ` vries at gcc dot gnu.org
@ 2021-02-25 12:00 ` vries at gcc dot gnu.org
  2021-02-25 14:45 ` tromey at sourceware dot org
  6 siblings, 0 replies; 8+ messages in thread
From: vries at gcc dot gnu.org @ 2021-02-25 12:00 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26155

--- Comment #5 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Andrew Burgess from comment #4)
> Tom,
> 
> Sorry I didn't spot you'd commented on this bug.  I've had this patch sat on
> the mailing list since last year, but only got around to addressing the
> feedback and merging it recently.
> 

Np.  Ah, I see, that's
https://sourceware.org/pipermail/gdb-patches/2020-July/170493.html .

Yeah, that's on of the reasons why I always try to note at least the first
submitted patch for a PR in the PR.

> This issue should be resolved now.  Feel free to reopen the bug if you
> continue to see this problem.

Ack, thanks for fixing this :)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug fortran/26155] p cos(alat(j)) command make gdb Aborted (core dumped)
  2020-06-23  1:26 [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped) yansendao at huawei dot com
                   ` (5 preceding siblings ...)
  2021-02-25 12:00 ` vries at gcc dot gnu.org
@ 2021-02-25 14:45 ` tromey at sourceware dot org
  6 siblings, 0 replies; 8+ messages in thread
From: tromey at sourceware dot org @ 2021-02-25 14:45 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26155

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at sourceware dot org

--- Comment #6 from Tom Tromey <tromey at sourceware dot org> ---
> Yeah, that's on of the reasons why I always try to note at least the first
> submitted patch for a PR in the PR.

I wish we had a robot that would look for the "PR .../NNNN" text
in email, and publish links to the mailing list archives in bugzilla.
That would have prevented some lossage over the years.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-02-25 14:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23  1:26 [Bug fortran/26155] New: p cos(alat(j)) command make gdb Aborted (core dumped) yansendao at huawei dot com
2021-02-03 12:40 ` [Bug fortran/26155] " vries at gcc dot gnu.org
2021-02-03 12:49 ` vries at gcc dot gnu.org
2021-02-25 10:33 ` cvs-commit at gcc dot gnu.org
2021-02-25 10:43 ` andrew.burgess at embecosm dot com
2021-02-25 11:58 ` vries at gcc dot gnu.org
2021-02-25 12:00 ` vries at gcc dot gnu.org
2021-02-25 14:45 ` tromey at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).