Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Williams <mark@myosotissp.com>
To: Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix toplevel types with -fdebug-types-section
Date: Sun, 19 Jan 2020 16:31:00 -0000	[thread overview]
Message-ID: <CAN0QdPUt+1qErME0avZkY3O1Ea4TMKkCKH3mNqMyvXGLv1BGLQ@mail.gmail.com> (raw)
In-Reply-To: <70d20408-1f27-560c-aa9e-a496624e1113@simark.ca>

[-- Attachment #1: Type: text/plain, Size: 68 bytes --]

New patch, with more detail in the commit message, and a test case.

[-- Attachment #2: 0001-gdb-Fix-toplevel-types-with-fdebug-types-section.patch --]
[-- Type: application/octet-stream, Size: 4848 bytes --]

From fac8ac9559f2b97325f0fab3315afc5088d6c38d Mon Sep 17 00:00:00 2001
From: mwilliams <mwilliams@fb.com>
Date: Sun, 19 Jan 2020 08:09:59 -0800
Subject: [PATCH] gdb: Fix toplevel types with -fdebug-types-section

When debugging a program compiled with -fdebug-types-section,
only the first top-level type in each file is visible to gdb.

The problem was caused by moving the assignment to list_in_scope
from process_full_comp_unit and process_full_type_unit to
start_symtab. This was fine for process_full_comp_unit, because
symtabs and comp units are one-to-one. But there can be many type
units per symtab (one for each type), and we only call start_symtab
for the first one. This adds the necessary assignments on the paths
where start_symtab is not called.

gdb/Changelog
2020-01-19 Mark Williams <mark@myosotissp.com>

	PR gdb/24480
	* dwarf2read.c add missing assingments to list_in_scope when
	start_symtab was already called.

gdb/testsuite/Changelog
2020-01-19 Mark Williams <mark@myosotissp.com>

	PR gdb/24480
	* dw4-toplevel-types.exp Test for top level types
	* dw4-toplevel-types.cc Test for top level types
---
 gdb/dwarf2read.c                              |  2 ++
 .../gdb.dwarf2/dw4-toplevel-types.cc          | 21 +++++++++++
 .../gdb.dwarf2/dw4-toplevel-types.exp         | 35 +++++++++++++++++++
 3 files changed, 58 insertions(+)
 create mode 100644 gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.cc
 create mode 100644 gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.exp

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index d1b65b7bc3..c8f0d27f91 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -11762,6 +11762,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
 			    COMPUNIT_DIRNAME (cust),
 			    compunit_language (cust),
 			    0, cust));
+	  list_in_scope = get_builder ()->get_file_symbols ();
 	}
       return;
     }
@@ -11813,6 +11814,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
 			COMPUNIT_DIRNAME (cust),
 			compunit_language (cust),
 			0, cust));
+      list_in_scope = get_builder ()->get_file_symbols ();
 
       auto &file_names = line_header->file_names ();
       for (i = 0; i < file_names.size (); ++i)
diff --git a/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.cc b/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.cc
new file mode 100644
index 0000000000..ebb9ea7f16
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.cc
@@ -0,0 +1,21 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2016 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+struct X {} x;
+struct Y {} y;
+struct Z {} z;
+int main() {}
diff --git a/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.exp b/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.exp
new file mode 100644
index 0000000000..70dc24cba5
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw4-toplevel-types.exp
@@ -0,0 +1,35 @@
+# Copyright 2010-2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test dwarf4 signatured types (DW_TAG_type_unit).
+
+standard_testfile .cc
+
+# This test is intended for targets which support DWARF-4.
+# Since we pass an explicit -gdwarf-4 -fdebug-types-section to the compiler,
+# we let that be the test of whether the target supports it.
+
+if { [prepare_for_testing "failed to prepare" "${testfile}" \
+	  $srcfile {debug c++ additional_flags=-gdwarf-4 additional_flags=-fdebug-types-section}] } {
+    return -1
+}
+
+if ![runto_main] {
+    return -1
+}
+
+gdb_test "ptype X" "type = struct X {.*"
+gdb_test "ptype Y" "type = struct Y {.*"
+gdb_test "ptype Z" "type = struct Z {.*"
-- 
2.17.1


  reply	other threads:[~2020-01-19 16:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-18 18:59 Mark Williams
2020-01-19  2:04 ` Simon Marchi
2020-01-19  2:10   ` Simon Marchi
2020-01-19 16:31     ` Mark Williams [this message]
2020-01-19 16:40       ` Simon Marchi
2020-01-21 19:56       ` Tom Tromey

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=CAN0QdPUt+1qErME0avZkY3O1Ea4TMKkCKH3mNqMyvXGLv1BGLQ@mail.gmail.com \
    --to=mark@myosotissp.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /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