Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Tom de Vries (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io>
To: Andrew Burgess <andrew.burgess@embecosm.com>,	gdb-patches@sourceware.org
Subject: Change in binutils-gdb[master]: [gdb/symtab] Prefer var def over decl
Date: Mon, 14 Oct 2019 16:35:00 -0000	[thread overview]
Message-ID: <20191014163514.F047529ECF@gnutoolchain-gerrit.osci.io> (raw)
In-Reply-To: <gerrit.1571043046000.Id92326cb8ef9903b121ef9e320658eb565d0f5a9@gnutoolchain-gerrit.osci.io>

Hello Andrew Burgess, 

I'd like you to reexamine a change. Please visit

    https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/29

to look at the new patch set (#2).

Change subject: [gdb/symtab] Prefer var def over decl
......................................................................

[gdb/symtab] Prefer var def over decl

Consider the DWARF as generated by gcc with the tentative patch to fix gcc
PR91507 - "wrong debug for completed array with previous incomplete
declaration":
...
 <1><f4>: Abbrev Number: 2 (DW_TAG_array_type)
    <f5>   DW_AT_type        : <0xff>
    <f9>   DW_AT_sibling     : <0xff>
 <2><fd>: Abbrev Number: 3 (DW_TAG_subrange_type)
 <2><fe>: Abbrev Number: 0
 <1><ff>: Abbrev Number: 4 (DW_TAG_pointer_type)
    <100>   DW_AT_byte_size   : 8
    <101>   DW_AT_type        : <0x105>
 <1><105>: Abbrev Number: 5 (DW_TAG_base_type)
    <106>   DW_AT_byte_size   : 1
    <107>   DW_AT_encoding    : 6       (signed char)
    <108>   DW_AT_name        : (indirect string, offset: 0x19f): char
 <1><10c>: Abbrev Number: 6 (DW_TAG_variable)
    <10d>   DW_AT_name        : zzz
    <111>   DW_AT_decl_file   : 1
    <112>   DW_AT_decl_line   : 1
    <113>   DW_AT_decl_column : 14
    <114>   DW_AT_type        : <0xf4>
    <118>   DW_AT_external    : 1
    <118>   DW_AT_declaration : 1
 <1><118>: Abbrev Number: 2 (DW_TAG_array_type)
    <119>   DW_AT_type        : <0xff>
    <11d>   DW_AT_sibling     : <0x128>
 <1><12f>: Abbrev Number: 8 (DW_TAG_variable)
    <130>   DW_AT_specification: <0x10c>
    <134>   DW_AT_decl_line   : 2
    <135>   DW_AT_decl_column : 7
    <136>   DW_AT_type        : <0x118>
    <13a>   DW_AT_location    : 9 byte block: 3 30 10 60 0 0 0 0 0      (DW_OP_addr: 601030)
...

The DWARF will result in two entries in the symbol table, a decl with type
char *[] and a def with type char*[2].

When trying to print the value of zzz:
...
$ gdb a.spec.out -batch -ex "p zzz"
...
the decl (rather than the def) will be found in the symbol table, which is
missing the location information, and consequently we get:
...
$1 = 0x601030 <zzz>
...

[ There is a fallback mechanism that finds the address of the variable in the
minimal symbol table, but that's not used here, because the type of the decl
does not specify a size.  We could use the symbol size here to get the size
of the type, but that's currently not done: PR exp/24989.  Still, fixing that
PR would not fix the generic case, where minimal symbol info is not
available. ]

Fix this by preferring defs over decls when searching in the symbol table.

Build and reg-tested on x86_64-linux.

[ The test-case is a bit simpler than the DWARF example listed above, because
the new variable varval3 that is used is not listed in the minimal symbols, so
there's no need to work around the fallback mechanism to trigger the problem. ]

gdb/ChangeLog:

2019-09-10  Tom de Vries  <tdevries@suse.de>

	PR symtab/24971
	* block.c (best_symbol, better_symbol): New function.
	(block_lookup_symbol_primary): Prefer def over decl.

gdb/testsuite/ChangeLog:

2019-09-10  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/varval.exp: Add decl before def test.

Change-Id: Id92326cb8ef9903b121ef9e320658eb565d0f5a9
---
M gdb/block.c
M gdb/testsuite/gdb.dwarf2/varval.exp
2 files changed, 55 insertions(+), 3 deletions(-)


  git pull ssh://gnutoolchain-gerrit.osci.io:29418/binutils-gdb refs/changes/29/29/2
-- 
To view, visit https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/29
To unsubscribe, or for help writing mail filters, visit https://gnutoolchain-gerrit.osci.io/r/settings

Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Id92326cb8ef9903b121ef9e320658eb565d0f5a9
Gerrit-Change-Number: 29
Gerrit-PatchSet: 2
Gerrit-Owner: Tom de Vries <tdevries@suse.de>
Gerrit-Reviewer: Andrew Burgess <andrew.burgess@embecosm.com>
Gerrit-MessageType: newpatchset


       reply	other threads:[~2019-10-14 16:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <gerrit.1571043046000.Id92326cb8ef9903b121ef9e320658eb565d0f5a9@gnutoolchain-gerrit.osci.io>
2019-10-14 16:35 ` Tom de Vries (Code Review) [this message]
2019-10-14 16:51 ` Tom de Vries (Code Review)
2019-10-18 13:31 ` [review] " Luis Machado (Code Review)
2019-10-18 16:44 ` Tom de Vries (Code Review)
2019-10-23 16:27 ` [review v3] " Tom de Vries (Code Review)
2019-10-23 16:29 ` Tom de Vries (Code Review)
2019-10-31 15:50 ` Tom Tromey (Code Review)
2019-11-04  1:11 ` Joel Brobecker (Code Review)
2019-11-07 14:27 ` Tom de Vries (Code Review)
2019-11-07 15:30 ` Tom de Vries (Code Review)
2019-11-11 16:45 ` Joel Brobecker (Code Review)
2019-11-14 16:38 ` Tom de Vries (Code Review)
2019-11-21 13:34 ` Tom Tromey (Code Review)
2019-11-22 10:24 ` Tom de Vries (Code Review)
2019-11-22 11:02 ` Tom de Vries (Code Review)
2019-11-22 12:17 ` [review v4] " Tom de Vries (Code Review)
2019-11-22 12:19 ` Tom de Vries (Code Review)
2019-12-05 20:29 ` Tom Tromey (Code Review)
2019-12-06 17:53 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-12-06 17:53 ` Sourceware to Gerrit sync (Code Review)
2019-12-09  6:29 ` [review v5] " Tom de Vries (Code Review)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191014163514.F047529ECF@gnutoolchain-gerrit.osci.io \
    --to=gerrit@gnutoolchain-gerrit.osci.io \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@sergiodj.net \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox