public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation
@ 2020-11-16 15:01 gbenson at redhat dot com
  2020-11-16 15:03 ` [Bug gdb/26905] " gbenson at redhat dot com
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-16 15:01 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 26905
           Summary: Inconsistent DW_AT_count evaluation
           Product: gdb
           Version: unknown
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: gbenson at redhat dot com
  Target Milestone: ---

Clang describes the upper bounds of variable length arrays using a DW_AT_count
attribute which references the DIE of a synthetic variable whose value is a
DW_AT_location.  In some cases GDB correctly handles these, but other times GDB
attempts to dereference the result of evaluating the location expression and
fails.

An example where GDB does not dereference the value:

 $ gdb /path/to/gdb/testsuite/outputs/gdb.mi/mi-vla-c99/mi-vla-c99
 (gdb) b vla.c:28
 (gdb) r
  ...
 Breakpoint 1, func (n=5) at /gdbtest/src/gdb/testsuite/gdb.mi/vla.c:28
 28       return n;                 /* vla-filled */
 (gdb) p vla
 $1 = {0, 1, 2, 3, 4}
 (gdb) p __vla_expr0
 $2 = 5

An example where GDB does dereference the value:

 $ gdb
/path/to/gdb/testsuite/outputs/gdb.base/vla-optimized-out/vla-optimized-out-o1 
 (gdb) b f1
 Breakpoint 1 at 0x401110: file
/gdbtest/src/gdb/testsuite/gdb.base/vla-optimized-out.c, line 34.
 (gdb) r
  ...
 Breakpoint 1, f1 (i=5) at
/gdbtest/src/gdb/testsuite/gdb.base/vla-optimized-out.c:34
 34     }
 (gdb) p a
 Cannot access memory at address 0x6
 (gdb) 
 (gdb) p __vla_expr0
 $1 = 6

In both these examples, __vla_expr0 is the name Clang assigned the synthetic
variable containing the value of DW_AT_count.

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

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

* [Bug gdb/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
@ 2020-11-16 15:03 ` gbenson at redhat dot com
  2020-11-16 15:05 ` gbenson at redhat dot com
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-16 15:03 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #1 from Gary Benson <gbenson at redhat dot com> ---
Created attachment 12965
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12965&action=edit
ELF executable for gdb.mi/mi-vla-c99, which GDB handles correctly

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

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

* [Bug gdb/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
  2020-11-16 15:03 ` [Bug gdb/26905] " gbenson at redhat dot com
@ 2020-11-16 15:05 ` gbenson at redhat dot com
  2020-11-16 15:05 ` gbenson at redhat dot com
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-16 15:05 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #2 from Gary Benson <gbenson at redhat dot com> ---
Created attachment 12966
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12966&action=edit
ELF executable for gdb.base/vla-optimized-out.exp, which GDB handles
incorrectly

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

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

* [Bug gdb/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
  2020-11-16 15:03 ` [Bug gdb/26905] " gbenson at redhat dot com
  2020-11-16 15:05 ` gbenson at redhat dot com
@ 2020-11-16 15:05 ` gbenson at redhat dot com
  2020-11-16 15:06 ` gbenson at redhat dot com
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-16 15:05 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #3 from Gary Benson <gbenson at redhat dot com> ---
Created attachment 12967
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12967&action=edit
dwarfdump of gdb.mi/mi-vla-c99 (which GDB handles correctly)

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

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

* [Bug gdb/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (2 preceding siblings ...)
  2020-11-16 15:05 ` gbenson at redhat dot com
@ 2020-11-16 15:06 ` gbenson at redhat dot com
  2020-11-16 15:23 ` gbenson at redhat dot com
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-16 15:06 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #4 from Gary Benson <gbenson at redhat dot com> ---
Created attachment 12968
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12968&action=edit
dwarfdump of gdb.base/vla-optimized-out.exp (which GDB handles incorrectly)

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

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

* [Bug gdb/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (3 preceding siblings ...)
  2020-11-16 15:06 ` gbenson at redhat dot com
@ 2020-11-16 15:23 ` gbenson at redhat dot com
  2020-11-16 15:25 ` gbenson at redhat dot com
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-16 15:23 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #5 from Gary Benson <gbenson at redhat dot com> ---
Interestingly, gdb.base/vla-ptr.exp has a mixed failure:
 $ gdb /path/to/gdb/testsuite/outputs/gdb.base/vla-ptr/vla-ptr 
 (gdb) b vla-ptr.c:46
 (gdb) r
  ...
 Breakpoint 1, vla_func (n=5) at
/gdbtest/src/gdb/testsuite/gdb.base/vla-ptr.c:46
 46       foo(n, vla);
 (gdb) p vla
 $1 = {2, 3, 4, 5, 6}
 (gdb) p td_vla
 $2 = 0x7fffffffd610
 (gdb) p __vla_expr0
 $3 = 5
 (gdb) p __vla_expr1
 $4 = 5

The two arrays are defined as:
 35       int vla[n];
 36       typedef int typedef_vla[n];
 37       typedef_vla td_vla;

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

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

* [Bug gdb/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (4 preceding siblings ...)
  2020-11-16 15:23 ` gbenson at redhat dot com
@ 2020-11-16 15:25 ` gbenson at redhat dot com
  2020-11-16 15:26 ` gbenson at redhat dot com
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-16 15:25 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #6 from Gary Benson <gbenson at redhat dot com> ---
Created attachment 12969
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12969&action=edit
ELF executable for gdb.base/vla-ptr.exp, which demonstrates both cases

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

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

* [Bug gdb/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (5 preceding siblings ...)
  2020-11-16 15:25 ` gbenson at redhat dot com
@ 2020-11-16 15:26 ` gbenson at redhat dot com
  2020-11-17  9:51 ` gbenson at redhat dot com
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-16 15:26 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #7 from Gary Benson <gbenson at redhat dot com> ---
Created attachment 12970
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12970&action=edit
dwarfdump of gdb.base/vla-ptr (with one case GDB handles and one case it
doesn't)

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

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

* [Bug gdb/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (6 preceding siblings ...)
  2020-11-16 15:26 ` gbenson at redhat dot com
@ 2020-11-17  9:51 ` gbenson at redhat dot com
  2020-11-20 13:50 ` [Bug symtab/26905] " vries at gcc dot gnu.org
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: gbenson at redhat dot com @ 2020-11-17  9:51 UTC (permalink / raw)
  To: gdb-prs

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

Gary Benson <gbenson at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |26909


Referenced Bugs:

https://sourceware.org/bugzilla/show_bug.cgi?id=26909
[Bug 26909] [meta] Debug Clang-built code
-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug symtab/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (7 preceding siblings ...)
  2020-11-17  9:51 ` gbenson at redhat dot com
@ 2020-11-20 13:50 ` vries at gcc dot gnu.org
  2020-11-20 16:32 ` vries at gcc dot gnu.org
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-20 13:50 UTC (permalink / raw)
  To: gdb-prs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vries at gcc dot gnu.org
          Component|gdb                         |symtab

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

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

* [Bug symtab/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (8 preceding siblings ...)
  2020-11-20 13:50 ` [Bug symtab/26905] " vries at gcc dot gnu.org
@ 2020-11-20 16:32 ` vries at gcc dot gnu.org
  2020-11-22  9:55 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-20 16:32 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #8 from Tom de Vries <vries at gcc dot gnu.org> ---
Posted patch here:
https://sourceware.org/pipermail/gdb-patches/2020-November/173438.html

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

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

* [Bug symtab/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (9 preceding siblings ...)
  2020-11-20 16:32 ` vries at gcc dot gnu.org
@ 2020-11-22  9:55 ` cvs-commit at gcc dot gnu.org
  2020-11-23 17:59 ` mark at klomp dot org
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-11-22  9:55 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #9 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

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

commit 117c628d49309e3b6a8b11d492f497104f3e4b2c
Author: Gary Benson <gbenson@redhat.com>
Date:   Sun Nov 22 10:54:58 2020 +0100

    [gdb/testsuite] Add testcase for DW_AT_count referencing a variable

    Clang describes the upper bounds of variable length arrays using
    a DW_AT_count attribute which references the DIE of a synthetic
    variable whose value is specified using a DW_AT_location.  GDB handles
    these incorrectly if the corresponding DWARF expression finishes with a
    DW_OP_stack_value (PR26905).  This commit adds a new kfailed test to
    gdb.dwarf2/count.exp with the same DWARF as that generated by Clang for
    gdb.base/vla-optimized-out.exp, one of the failing tests.

    Checked on Fedora 32 x86_64, with GCC and Clang.

    gdb/testsuite/ChangeLog:

    2020-11-22  Gary Benson <gbenson@redhat.com>

            PR gdb/26905
            * gdb.dwarf2/count.exp: Add test for an array whose upper bound
            is defined using a DW_AT_count which references another DIE.

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

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

* [Bug symtab/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (10 preceding siblings ...)
  2020-11-22  9:55 ` cvs-commit at gcc dot gnu.org
@ 2020-11-23 17:59 ` mark at klomp dot org
  2020-11-30 12:50 ` cvs-commit at gcc dot gnu.org
  2020-11-30 12:53 ` vries at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: mark at klomp dot org @ 2020-11-23 17:59 UTC (permalink / raw)
  To: gdb-prs

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

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mark at klomp dot org

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

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

* [Bug symtab/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (11 preceding siblings ...)
  2020-11-23 17:59 ` mark at klomp dot org
@ 2020-11-30 12:50 ` cvs-commit at gcc dot gnu.org
  2020-11-30 12:53 ` vries at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-11-30 12:50 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #10 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

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

commit 7ce05d212d1b825dc58d2b0d390417f2c134cd98
Author: Tom de Vries <tdevries@suse.de>
Date:   Mon Nov 30 13:50:26 2020 +0100

    [gdb/symtab] Fix gdb.base/vla-optimized-out.exp with clang

    Consider test-case gdb.base/vla-optimized-out.exp, compiled using clang-10.

    GDB fails to get the size of the vla a:
    ...
    (gdb) p sizeof (a)^M
    Cannot access memory at address 0x6^M
    (gdb) FAIL: gdb.base/vla-optimized-out.exp: o1: printed size of \
      optimized out vla
    ...

    The relevant DWARF looks like this: the variable a:
    ...
     <2><12b>: Abbrev Number: 5 (DW_TAG_variable)
        <12c>   DW_AT_name        : a
        <132>   DW_AT_type        : <0x189>
    ...
    has type:
    ...
     <1><189>: Abbrev Number: 10 (DW_TAG_array_type)
        <18a>   DW_AT_type        : <0x198>
     <2><18e>: Abbrev Number: 11 (DW_TAG_subrange_type)
        <18f>   DW_AT_type        : <0x19f>
        <193>   DW_AT_count       : <0x117>
    ...
    with the count attribute equated to the value of this artificial variable:
    ...
     <2><117>: Abbrev Number: 4 (DW_TAG_variable)
        <118>   DW_AT_location    : 10 byte block: 75 1 10 ff ff ff ff f 1a 9f
\
                  (DW_OP_breg5 (rdi): 1;
                   DW_OP_constu: 4294967295;
                   DW_OP_and;
                   DW_OP_stack_value)
        <123>   DW_AT_name        : __vla_expr0
        <127>   DW_AT_type        : <0x182>
        <12b>   DW_AT_artificial  : 1
    ...

    The location description of the variable is terminated with
DW_OP_stack_value,
    which according to the DWARF spec means that "the DWARF expression
represents
    the actual value of the object, rather than its location".

    However, in attr_to_dynamic_prop, we set is_reference to true:
    ...
                   baton->locexpr.is_reference = true;
    ...
    and use it in dwarf2_evaluate_property to dereference the value of the
DWARF
    expression, which causes the access to memory at address 0x6.

    Fix this by ignoring the baton->locexpr.is_reference == true setting if
    the expression evaluation has ctx.location == DWARF_VALUE_STACK, such that
we
    get:
    ...
    (gdb) p sizeof (a)^M
    $2 = 6^M
    (gdb) PASS: gdb.base/vla-optimized-out.exp: o1: printed size of \
      optimized out vla
    ...

    Tested on x86_64-linux, with gcc.

    Tested the following test-cases (the ones mentioned in PR26905) on
    x86_64-linux with clang-10:
    - gdb.base/vla-optimized-out.exp
    - gdb.base/vla-ptr.exp
    - gdb.mi/mi-vla-c99

    gdb/ChangeLog:

    2020-11-30  Tom de Vries  <tdevries@suse.de>

            PR symtab/26905
            * dwarf2/loc.c (dwarf2_locexpr_baton_eval): Add and handle
            is_reference parameter.
            (dwarf2_evaluate_property): Update dwarf2_locexpr_baton_eval call.

    gdb/testsuite/ChangeLog:

    2020-11-30  Tom de Vries  <tdevries@suse.de>

            PR symtab/26905
            * gdb.dwarf2/count.exp: Remove kfails.

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

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

* [Bug symtab/26905] Inconsistent DW_AT_count evaluation
  2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
                   ` (12 preceding siblings ...)
  2020-11-30 12:50 ` cvs-commit at gcc dot gnu.org
@ 2020-11-30 12:53 ` vries at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: vries at gcc dot gnu.org @ 2020-11-30 12:53 UTC (permalink / raw)
  To: gdb-prs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.1
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #11 from Tom de Vries <vries at gcc dot gnu.org> ---
Patch committed, removing kfails in appropriate test-case, marking
resolved-fixed.

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

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

end of thread, other threads:[~2020-11-30 12:53 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16 15:01 [Bug gdb/26905] New: Inconsistent DW_AT_count evaluation gbenson at redhat dot com
2020-11-16 15:03 ` [Bug gdb/26905] " gbenson at redhat dot com
2020-11-16 15:05 ` gbenson at redhat dot com
2020-11-16 15:05 ` gbenson at redhat dot com
2020-11-16 15:06 ` gbenson at redhat dot com
2020-11-16 15:23 ` gbenson at redhat dot com
2020-11-16 15:25 ` gbenson at redhat dot com
2020-11-16 15:26 ` gbenson at redhat dot com
2020-11-17  9:51 ` gbenson at redhat dot com
2020-11-20 13:50 ` [Bug symtab/26905] " vries at gcc dot gnu.org
2020-11-20 16:32 ` vries at gcc dot gnu.org
2020-11-22  9:55 ` cvs-commit at gcc dot gnu.org
2020-11-23 17:59 ` mark at klomp dot org
2020-11-30 12:50 ` cvs-commit at gcc dot gnu.org
2020-11-30 12:53 ` vries at gcc dot gnu.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).