Blame SOURCES/gdb-test-for-rhbz1976887.patch

ed07ac
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
ed07ac
From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= <ahajkova@redhat.com>
ed07ac
Date: Wed, 29 Sep 2021 11:14:51 +0200
ed07ac
Subject: gdb-test-for-rhbz1976887.patch
ed07ac
ed07ac
;; Backport test for RHBZ 1976887 (Kevin Buettner).
ed07ac
ed07ac
Test case reproducing PR28030 bug
ed07ac
ed07ac
The original reproducer for PR28030 required use of a specific
ed07ac
compiler version - gcc-c++-11.1.1-3.fc34 is mentioned in the PR,
ed07ac
though it seems probable that other gcc versions might also be able to
ed07ac
reproduce the bug as well.  This commit introduces a test case which,
ed07ac
using the DWARF assembler, provides a reproducer which is independent
ed07ac
of the compiler version.  (Well, it'll work with whatever compilers
ed07ac
the DWARF assembler works with.)
ed07ac
ed07ac
To the best of my knowledge, it's also the first test case which uses
ed07ac
the DWARF assembler to provide debug info for a shared object.  That
ed07ac
being the case, I provided more than the usual commentary which should
ed07ac
allow this case to be used as a template when a combo shared
ed07ac
library / DWARF assembler test case is required in the future.
ed07ac
ed07ac
I provide some details regarding the bug in a comment near the
ed07ac
beginning of locexpr-dml.exp.
ed07ac
ed07ac
This problem was difficult to reproduce; I found myself constantly
ed07ac
referring to the backtrace while trying to figure out what (else) I
ed07ac
might be missing while trying to create a reproducer.  Below is a
ed07ac
partial backtrace which I include for posterity.
ed07ac
ed07ac
 #0  internal_error (
ed07ac
    file=0xc50110 "/ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/gdbtypes.c", line=5575,
ed07ac
    fmt=0xc520c0 "Unexpected type field location kind: %d")
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdbsupport/errors.cc:51
ed07ac
 #1  0x00000000006ef0c5 in copy_type_recursive (objfile=0x1635930,
ed07ac
    type=0x274c260, copied_types=0x30bb290)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/gdbtypes.c:5575
ed07ac
 #2  0x00000000006ef382 in copy_type_recursive (objfile=0x1635930,
ed07ac
    type=0x274ca10, copied_types=0x30bb290)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/gdbtypes.c:5602
ed07ac
 #3  0x0000000000a7409a in preserve_one_value (value=0x24269f0,
ed07ac
    objfile=0x1635930, copied_types=0x30bb290)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/value.c:2529
ed07ac
 #4  0x000000000072012a in gdbscm_preserve_values (
ed07ac
    extlang=0xc55720 <extension_language_guile>, objfile=0x1635930,
ed07ac
    copied_types=0x30bb290)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/guile/scm-value.c:94
ed07ac
 #5  0x00000000006a3f82 in preserve_ext_lang_values (objfile=0x1635930,
ed07ac
    copied_types=0x30bb290)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/extension.c:568
ed07ac
 #6  0x0000000000a7428d in preserve_values (objfile=0x1635930)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/value.c:2579
ed07ac
 #7  0x000000000082d514 in objfile::~objfile (this=0x1635930,
ed07ac
    __in_chrg=<optimized out>)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/objfiles.c:549
ed07ac
 #8  0x0000000000831cc8 in std::_Sp_counted_ptr<objfile*, (__gnu_cxx::_Lock_policy)2>::_M_dispose (this=0x1654580)
ed07ac
    at /usr/include/c++/11/bits/shared_ptr_base.h:348
ed07ac
 #9  0x00000000004e6617 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release (this=0x1654580) at /usr/include/c++/11/bits/shared_ptr_base.h:168
ed07ac
 #10 0x00000000004e1d2f in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count (this=0x190bb88, __in_chrg=<optimized out>)
ed07ac
    at /usr/include/c++/11/bits/shared_ptr_base.h:705
ed07ac
 #11 0x000000000082feee in std::__shared_ptr<objfile, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr (this=0x190bb80, __in_chrg=<optimized out>)
ed07ac
    at /usr/include/c++/11/bits/shared_ptr_base.h:1154
ed07ac
 #12 0x000000000082ff0a in std::shared_ptr<objfile>::~shared_ptr (
ed07ac
    this=0x190bb80, __in_chrg=<optimized out>)
ed07ac
    at /usr/include/c++/11/bits/shared_ptr.h:122
ed07ac
 #13 0x000000000085ed7e in __gnu_cxx::new_allocator<std::_List_node<std::shared_ptr<objfile> > >::destroy<std::shared_ptr<objfile> > (this=0x114bc00,
ed07ac
    __p=0x190bb80) at /usr/include/c++/11/ext/new_allocator.h:168
ed07ac
 #14 0x000000000085e88d in std::allocator_traits<std::allocator<std::_List_node<std::shared_ptr<objfile> > > >::destroy<std::shared_ptr<objfile> > (__a=...,
ed07ac
    __p=0x190bb80) at /usr/include/c++/11/bits/alloc_traits.h:531
ed07ac
 #15 0x000000000085e50c in std::__cxx11::list<std::shared_ptr<objfile>, std::allocator<std::shared_ptr<objfile> > >::_M_erase (this=0x114bc00, __position=
ed07ac
  std::shared_ptr<objfile> (expired, weak count 1) = {get() = 0x1635930})
ed07ac
    at /usr/include/c++/11/bits/stl_list.h:1925
ed07ac
 #16 0x000000000085df0e in std::__cxx11::list<std::shared_ptr<objfile>, std::allocator<std::shared_ptr<objfile> > >::erase (this=0x114bc00, __position=
ed07ac
  std::shared_ptr<objfile> (expired, weak count 1) = {get() = 0x1635930})
ed07ac
    at /usr/include/c++/11/bits/list.tcc:158
ed07ac
 #17 0x000000000085c748 in program_space::remove_objfile (this=0x114bbc0,
ed07ac
    objfile=0x1635930)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/progspace.c:210
ed07ac
 #18 0x000000000082d3ae in objfile::unlink (this=0x1635930)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/objfiles.c:487
ed07ac
 #19 0x000000000082e68c in objfile_purge_solibs ()
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/objfiles.c:875
ed07ac
 #20 0x000000000092dd37 in no_shared_libraries (ignored=0x0, from_tty=1)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/solib.c:1236
ed07ac
 #21 0x00000000009a37fe in target_pre_inferior (from_tty=1)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/target.c:2496
ed07ac
 #22 0x00000000007454d6 in run_command_1 (args=0x0, from_tty=1,
ed07ac
    run_how=RUN_NORMAL)
ed07ac
    at /ironwood1/sourceware-git/f34-pr28030/bld/../../worktree-pr28030/gdb/infcmd.c:437
ed07ac
ed07ac
I'll note a few points regarding this backtrace:
ed07ac
ed07ac
Frame #1 is where the internal error occurs.  It's caused by an
ed07ac
unhandled case for FIELD_LOC_KIND_DWARF_BLOCK.  The fix for this bug
ed07ac
adds support for this case.
ed07ac
ed07ac
Frame #22 - it's a partial backtrace - shows that GDB is attempting to
ed07ac
(re)run the program.  You can see the exact command sequence that was
ed07ac
used for reproducing this problem in the PR (at
ed07ac
https://sourceware.org/bugzilla/show_bug.cgi?id=28030), but in a
ed07ac
nutshell, after starting the program and advancing to the appropriate
ed07ac
source line, GDB was asked to step into libstdc++; a "finish" command
ed07ac
was issued, returning a value.  The fact that a value was returned is
ed07ac
very important.  GDB was then used to step back into libstdc++.  A
ed07ac
breakpoint was set on a source line in the library after which a "run"
ed07ac
command was issued.
ed07ac
ed07ac
Frame #19 shows a call to objfile_purge_solibs.  It's aptly named.
ed07ac
ed07ac
Frame #7 is a call to the destructor for one of the objfile solibs; it
ed07ac
turned out to be the one for libstdc++.
ed07ac
ed07ac
Frames #6 thru #3 show various value preservation frames.  If you look
ed07ac
at preserve_values() in gdb/value.c, the value history is preserved
ed07ac
first, followed by internal variables, followed by values for the
ed07ac
extension languages (python and guile).
ed07ac
ed07ac
diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location-lib.c b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location-lib.c
ed07ac
new file mode 100644
ed07ac
--- /dev/null
ed07ac
+++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location-lib.c
ed07ac
@@ -0,0 +1,48 @@
ed07ac
+/* Copyright (C) 2021 Free Software Foundation, Inc.
ed07ac
+
ed07ac
+   This file is part of GDB.
ed07ac
+
ed07ac
+   This program is free software; you can redistribute it and/or modify
ed07ac
+   it under the terms of the GNU General Public License as published by
ed07ac
+   the Free Software Foundation; either version 3 of the License, or
ed07ac
+   (at your option) any later version.
ed07ac
+
ed07ac
+   This program is distributed in the hope that it will be useful,
ed07ac
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ed07ac
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ed07ac
+   GNU General Public License for more details.
ed07ac
+
ed07ac
+   You should have received a copy of the GNU General Public License
ed07ac
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
ed07ac
+
ed07ac
+#include "locexpr-data-member-location.h"
ed07ac
+
ed07ac
+struct A g_A = {3, 4};
ed07ac
+struct B g_B = { {8, 9}, 10, 11 };
ed07ac
+
ed07ac
+B *
ed07ac
+foo ()
ed07ac
+{						/* foo prologue */
ed07ac
+  asm ("foo_label: .globl foo_label");
ed07ac
+  return &g_;;					/* foo return */
ed07ac
+}						/* foo end */
ed07ac
+
ed07ac
+B *
ed07ac
+bar (B *v)
ed07ac
+{						/* bar prologue */
ed07ac
+  asm ("bar_label: .globl bar_label");
ed07ac
+  return v;					/* bar return */
ed07ac
+}						/* bar end */
ed07ac
+
ed07ac
+/* Some of the DWARF assembler procs (e.g. function_range) compile
ed07ac
+   this file, expecting it to be a complete program with a main()
ed07ac
+   function.  When IS_SHAREDLIB is NOT defined, we have main() as
ed07ac
+   defined below.  */
ed07ac
+
ed07ac
+#ifndef IS_SHAREDLIB
ed07ac
+int
ed07ac
+main ()
ed07ac
+{
ed07ac
+  B *b = foo ();
ed07ac
+}
ed07ac
+#endif
ed07ac
diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location-main.c b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location-main.c
ed07ac
new file mode 100644
ed07ac
--- /dev/null
ed07ac
+++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location-main.c
ed07ac
@@ -0,0 +1,27 @@
ed07ac
+/* Copyright (C) 2021 Free Software Foundation, Inc.
ed07ac
+
ed07ac
+   This file is part of GDB.
ed07ac
+
ed07ac
+   This program is free software; you can redistribute it and/or modify
ed07ac
+   it under the terms of the GNU General Public License as published by
ed07ac
+   the Free Software Foundation; either version 3 of the License, or
ed07ac
+   (at your option) any later version.
ed07ac
+
ed07ac
+   This program is distributed in the hope that it will be useful,
ed07ac
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ed07ac
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ed07ac
+   GNU General Public License for more details.
ed07ac
+
ed07ac
+   You should have received a copy of the GNU General Public License
ed07ac
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
ed07ac
+
ed07ac
+#include "locexpr-data-member-location.h"
ed07ac
+
ed07ac
+int
ed07ac
+main (void)
ed07ac
+{
ed07ac
+  B *v1;
ed07ac
+  v1 = bar (foo ());
ed07ac
+
ed07ac
+  return 0;
ed07ac
+}
ed07ac
diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp
ed07ac
new file mode 100644
ed07ac
--- /dev/null
ed07ac
+++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp
ed07ac
@@ -0,0 +1,349 @@
ed07ac
+# Copyright 2021 Free Software Foundation, Inc.
ed07ac
+
ed07ac
+# This program is free software; you can redistribute it and/or modify
ed07ac
+# it under the terms of the GNU General Public License as published by
ed07ac
+# the Free Software Foundation; either version 3 of the License, or
ed07ac
+# (at your option) any later version.
ed07ac
+#
ed07ac
+# This program is distributed in the hope that it will be useful,
ed07ac
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
ed07ac
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ed07ac
+# GNU General Public License for more details.
ed07ac
+#
ed07ac
+# You should have received a copy of the GNU General Public License
ed07ac
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
ed07ac
+
ed07ac
+# This test case uses the DWARF assembler to reproduce the problem
ed07ac
+# described by PR28030.  The bug turned out to be that
ed07ac
+# FIELD_LOC_KIND_DWARF_BLOCK was not handled when recursively copying
ed07ac
+# a value's type when preserving the value history during the freeing
ed07ac
+# up of objfiles associated with a shared object.  (Yes, figuring out
ed07ac
+# how to make this happen in a concise test case turned out to be
ed07ac
+# challenging.)
ed07ac
+#
ed07ac
+# The following elements proved to be necessary for reproducing the
ed07ac
+# problem:
ed07ac
+#
ed07ac
+# 1) A location expression needed to be used with
ed07ac
+#    DW_AT_data_member_location rather than a simple offset.
ed07ac
+#    Moreover, this location expression needed to use opcodes
ed07ac
+#    which GDB's DWARF reader could not convert to a simple
ed07ac
+#    offset.  (Note, however, that GDB could probably be improved
ed07ac
+#    to handle the opcodes chosen for this test; if decode_locdesc()
ed07ac
+#    in dwarf2/read.c is ever updated to handle both DW_OP_pick and
ed07ac
+#    DW_OP_drop, then this test could end up passing even if
ed07ac
+#    the bug it's intended to test has not been fixed.)
ed07ac
+#
ed07ac
+# 2) The debug info containing the above DWARF info needed
ed07ac
+#    to be associated with a shared object since the problem
ed07ac
+#    occurred while GDB was preserving values during the
ed07ac
+#    purging of shared objects.
ed07ac
+#
ed07ac
+# 3) After performing some simple gdb commands, the program is
ed07ac
+#    run again.  In the course of running the objfile destructor
ed07ac
+#    associated with the shared object, values are preserved
ed07ac
+#    along with their types.  As noted earlier, it was during
ed07ac
+#    the recursive type copy that the bug was observed.
ed07ac
+#
ed07ac
+# Therefore, due to #2 above, this test case creates debug info
ed07ac
+# which is then used by a shared object.
ed07ac
+
ed07ac
+# This test can't be run on targets lacking shared library support.
ed07ac
+if [skip_shlib_tests] {
ed07ac
+    return 0
ed07ac
+}
ed07ac
+
ed07ac
+load_lib dwarf.exp
ed07ac
+
ed07ac
+# This test can only be run on targets which support DWARF-2 and use gas.
ed07ac
+if ![dwarf2_support] {
ed07ac
+    return 0
ed07ac
+}
ed07ac
+
ed07ac
+# gdb_test_file_name is the name of this file without the .exp
ed07ac
+# extension.  Use it to form basenames for the main program
ed07ac
+# and shared object.
ed07ac
+set main_basename ${::gdb_test_file_name}-main
ed07ac
+set lib_basename ${::gdb_test_file_name}-lib
ed07ac
+
ed07ac
+# We're generating DWARF assembly for the shared object; therefore,
ed07ac
+# the source file for the library / shared object must be listed first
ed07ac
+# (in the standard_testfile invocation) since ${srcfile} is used by
ed07ac
+# get_func_info (for determining the start, end, and length of a
ed07ac
+# function).
ed07ac
+#
ed07ac
+# The output of Dwarf::assemble will be placed in $lib_basename.S
ed07ac
+# which will be ${srcfile3} after the execution of standard_testfile.
ed07ac
+
ed07ac
+standard_testfile $lib_basename.c $main_basename.c $lib_basename.S
ed07ac
+
ed07ac
+set libsrc "${::srcdir}/${::subdir}/${::srcfile}"
ed07ac
+set lib_so [standard_output_file ${lib_basename}.so]
ed07ac
+set asm_file [standard_output_file ${::srcfile3}]
ed07ac
+
ed07ac
+# We need to know the size of some types in order to write some of the
ed07ac
+# debugging info that we're about to generate.  For that, we ask GDB
ed07ac
+# by debugging the shared object associated with this test case.
ed07ac
+
ed07ac
+# Compile the shared library: -DIS_SHAREDLIB prevents main() from
ed07ac
+# being defined.  Note that debugging symbols will be present for
ed07ac
+# this compilation.
ed07ac
+if {[gdb_compile_shlib $libsrc $lib_so \
ed07ac
+                       {additional_flags=-DIS_SHAREDLIB debug}] != ""} {
ed07ac
+    untested "failed to compile shared library"
ed07ac
+    return
ed07ac
+}
ed07ac
+
ed07ac
+# Start a fresh GDB and load the shared library.
ed07ac
+clean_restart $lib_so
ed07ac
+
ed07ac
+# Using our running GDB session, determine sizes of several types.
ed07ac
+set long_size [get_sizeof "long" -1]
ed07ac
+set addr_size [get_sizeof "void *" -1]
ed07ac
+set struct_A_size [get_sizeof "g_A" -1]
ed07ac
+set struct_B_size [get_sizeof "g_B" -1]
ed07ac
+
ed07ac
+if { $long_size == -1 || $addr_size == -1 \
ed07ac
+     || $struct_A_size == -1 || $struct_B_size == -1} {
ed07ac
+    perror "Can't determine type sizes"
ed07ac
+    return
ed07ac
+}
ed07ac
+
ed07ac
+# Retrieve struct offset of MBR in struct TP
ed07ac
+proc get_offsetof { tp mbr } {
ed07ac
+    return [get_integer_valueof "&((${tp} *) 0)->${mbr}" -1]
ed07ac
+}
ed07ac
+
ed07ac
+# Use running GDB session to get struct offsets
ed07ac
+set A_a [get_offsetof A a]
ed07ac
+set A_x [get_offsetof A x]
ed07ac
+set B_a [get_offsetof B a]
ed07ac
+set B_b [get_offsetof B b]
ed07ac
+set B_x2 [get_offsetof B x2]
ed07ac
+
ed07ac
+# Create the DWARF.
ed07ac
+Dwarf::assemble ${asm_file} {
ed07ac
+    declare_labels L
ed07ac
+
ed07ac
+    # Find start, end, and length of functions foo and bar.
ed07ac
+    # These calls to get_func_info will create and set variables
ed07ac
+    # foo_start, bar_start, foo_end, bar_end, foo_len, and
ed07ac
+    # bar_len.
ed07ac
+    #
ed07ac
+    # In order to get the right answers, get_func_info (and,
ed07ac
+    # underneath, function_range) should use the same compiler flags
ed07ac
+    # as those used to make a shared object.  For any targets that get
ed07ac
+    # this far, -fpic is probably correct.
ed07ac
+    #
ed07ac
+    # Also, it should be noted that IS_SHAREDLIB is NOT defined as one
ed07ac
+    # of the additional flags.  Not defining IS_SHAREDLIB will cause a
ed07ac
+    # main() to be defined for the compilation of the shared library
ed07ac
+    # source file which happens as a result of using get_func_info;
ed07ac
+    # this is currently required in order to this facility.
ed07ac
+    set flags {additional_flags=-fpic debug}
ed07ac
+    get_func_info foo $flags
ed07ac
+    get_func_info bar $flags
ed07ac
+
ed07ac
+    cu {} {
ed07ac
+	DW_TAG_compile_unit {
ed07ac
+	    {DW_AT_language @DW_LANG_C_plus_plus}
ed07ac
+	    {name ${::srcfile}}
ed07ac
+	    {stmt_list $L DW_FORM_sec_offset}
ed07ac
+        } {
ed07ac
+	    declare_labels int_label class_A_label class_B_label \
ed07ac
+	                   B_ptr_label
ed07ac
+
ed07ac
+	    int_label: DW_TAG_base_type {
ed07ac
+		{DW_AT_byte_size ${::long_size} DW_FORM_udata}
ed07ac
+		{DW_AT_encoding @DW_ATE_signed}
ed07ac
+		{DW_AT_name "int"}
ed07ac
+	    }
ed07ac
+
ed07ac
+	    class_A_label: DW_TAG_class_type {
ed07ac
+		{DW_AT_name "A"}
ed07ac
+		{DW_AT_byte_size ${::struct_A_size} DW_FORM_sdata}
ed07ac
+	    } {
ed07ac
+		DW_TAG_member {
ed07ac
+		    {DW_AT_name "a"}
ed07ac
+		    {DW_AT_type :$int_label}
ed07ac
+		    {DW_AT_data_member_location ${::A_a} DW_FORM_udata}
ed07ac
+		}
ed07ac
+		DW_TAG_member {
ed07ac
+		    {DW_AT_name "x"}
ed07ac
+		    {DW_AT_type :$int_label}
ed07ac
+		    {DW_AT_data_member_location ${::A_x} DW_FORM_udata}
ed07ac
+		}
ed07ac
+	    }
ed07ac
+
ed07ac
+	    class_B_label: DW_TAG_class_type {
ed07ac
+		{DW_AT_name "B"}
ed07ac
+		{DW_AT_byte_size ${::struct_B_size} DW_FORM_sdata}
ed07ac
+	    } {
ed07ac
+		# While there are easier / better ways to specify an
ed07ac
+		# offset used by DW_AT_data_member_location than that
ed07ac
+		# used below, we need a location expression here in
ed07ac
+		# order to reproduce the bug.  Moreover, this location
ed07ac
+		# expression needs to use opcodes that aren't handled
ed07ac
+		# by decode_locdesc() in dwarf2/read.c; if we use
ed07ac
+		# opcodes that _are_ handled by that function, the
ed07ac
+		# location expression will be converted into a simple
ed07ac
+		# offset - which will then (again) not reproduce the
ed07ac
+		# bug.  At the time that this test was written,
ed07ac
+		# neither DW_OP_pick nor DW_OP_drop were being handled
ed07ac
+		# by decode_locdesc(); this is why those opcodes were
ed07ac
+		# chosen.
ed07ac
+		DW_TAG_inheritance {
ed07ac
+		    {DW_AT_type :$class_A_label}
ed07ac
+		    {DW_AT_data_member_location {
ed07ac
+			DW_OP_constu ${::B_a}
ed07ac
+			DW_OP_plus
ed07ac
+			DW_OP_pick 0
ed07ac
+			DW_OP_drop} SPECIAL_expr}
ed07ac
+		    {DW_AT_accessibility 1 DW_FORM_data1}
ed07ac
+		}
ed07ac
+		DW_TAG_member {
ed07ac
+		    {DW_AT_name "b"}
ed07ac
+		    {DW_AT_type :$int_label}
ed07ac
+		    {DW_AT_data_member_location ${::B_b} DW_FORM_udata}
ed07ac
+		}
ed07ac
+		DW_TAG_member {
ed07ac
+		    {DW_AT_name "x2"}
ed07ac
+		    {DW_AT_type :$int_label}
ed07ac
+		    {DW_AT_data_member_location ${::B_x2} DW_FORM_udata}
ed07ac
+		}
ed07ac
+	    }
ed07ac
+
ed07ac
+	    B_ptr_label: DW_TAG_pointer_type {
ed07ac
+		{DW_AT_type :$class_B_label}
ed07ac
+		{DW_AT_byte_size ${::addr_size} DW_FORM_sdata}
ed07ac
+	    }
ed07ac
+
ed07ac
+	    DW_TAG_variable {
ed07ac
+		{DW_AT_name "g_A"}
ed07ac
+		{DW_AT_type :$class_A_label}
ed07ac
+		{DW_AT_external 1 flag}
ed07ac
+		{DW_AT_location {DW_OP_addr [gdb_target_symbol "g_A"]} \
ed07ac
+		                 SPECIAL_expr}
ed07ac
+	    }
ed07ac
+
ed07ac
+	    DW_TAG_variable {
ed07ac
+		{DW_AT_name "g_B"}
ed07ac
+		{DW_AT_type :$class_B_label}
ed07ac
+		{DW_AT_external 1 flag}
ed07ac
+		{DW_AT_location {DW_OP_addr [gdb_target_symbol "g_B"]} \
ed07ac
+		                 SPECIAL_expr}
ed07ac
+	    }
ed07ac
+
ed07ac
+	    # We can't use MACRO_AT for the definitions of foo and bar
ed07ac
+	    # because it doesn't provide a way to pass the appropriate
ed07ac
+	    # flags.  Therefore, we list the name, low_pc, and high_pc
ed07ac
+	    # explicitly.
ed07ac
+	    DW_TAG_subprogram {
ed07ac
+		{DW_AT_name foo}
ed07ac
+		{DW_AT_low_pc $foo_start DW_FORM_addr}
ed07ac
+		{DW_AT_high_pc $foo_end DW_FORM_addr}
ed07ac
+		{DW_AT_type :${B_ptr_label}}
ed07ac
+		{DW_AT_external 1 flag}
ed07ac
+	    }
ed07ac
+
ed07ac
+	    DW_TAG_subprogram {
ed07ac
+		{DW_AT_name bar}
ed07ac
+		{DW_AT_low_pc $bar_start DW_FORM_addr}
ed07ac
+		{DW_AT_high_pc $bar_end DW_FORM_addr}
ed07ac
+		{DW_AT_type :${B_ptr_label}}
ed07ac
+		{DW_AT_external 1 flag}
ed07ac
+	    } {
ed07ac
+		DW_TAG_formal_parameter {
ed07ac
+		    {DW_AT_name v}
ed07ac
+		    {DW_AT_type :${B_ptr_label}}
ed07ac
+		}
ed07ac
+	    }
ed07ac
+	}
ed07ac
+    }
ed07ac
+
ed07ac
+    lines {version 2} L {
ed07ac
+	include_dir "${::srcdir}/${::subdir}"
ed07ac
+	file_name "${::srcfile}" 1
ed07ac
+
ed07ac
+	# Generate a line table program.
ed07ac
+	program {
ed07ac
+	    {DW_LNE_set_address $foo_start}
ed07ac
+	    {line [gdb_get_line_number "foo prologue"]}
ed07ac
+	    {DW_LNS_copy}
ed07ac
+	    {DW_LNE_set_address foo_label}
ed07ac
+	    {line [gdb_get_line_number "foo return"]}
ed07ac
+	    {DW_LNS_copy}
ed07ac
+	    {line [gdb_get_line_number "foo end"]}
ed07ac
+	    {DW_LNS_copy}
ed07ac
+	    {DW_LNE_set_address $foo_end}
ed07ac
+	    {DW_LNS_advance_line 1}
ed07ac
+	    {DW_LNS_copy}
ed07ac
+	    {DW_LNE_end_sequence}
ed07ac
+
ed07ac
+	    {DW_LNE_set_address $bar_start}
ed07ac
+	    {line [gdb_get_line_number "bar prologue"]}
ed07ac
+	    {DW_LNS_copy}
ed07ac
+	    {DW_LNE_set_address bar_label}
ed07ac
+	    {line [gdb_get_line_number "bar return"]}
ed07ac
+	    {DW_LNS_copy}
ed07ac
+	    {line [gdb_get_line_number "bar end"]}
ed07ac
+	    {DW_LNS_copy}
ed07ac
+	    {DW_LNE_set_address $bar_end}
ed07ac
+	    {DW_LNS_advance_line 1}
ed07ac
+	    {DW_LNS_copy}
ed07ac
+	    {DW_LNE_end_sequence}
ed07ac
+	}
ed07ac
+    }
ed07ac
+}
ed07ac
+
ed07ac
+# Compile the shared object again, but this time include / use the
ed07ac
+# DWARF info that we've created above.  Note that (again)
ed07ac
+# -DIS_SHAREDLIB is used to prevent inclusion of main() in the shared
ed07ac
+# object.  Also note the use of the "nodebug" option.  Any debugging
ed07ac
+# information that we need will be provided by the DWARF info created
ed07ac
+# above.
ed07ac
+if {[gdb_compile_shlib [list $libsrc $asm_file] $lib_so \
ed07ac
+                       {additional_flags=-DIS_SHAREDLIB nodebug}] != ""} {
ed07ac
+    untested "failed to compile shared library"
ed07ac
+    return
ed07ac
+}
ed07ac
+
ed07ac
+# Compile the main program for use with the shared object.
ed07ac
+if [prepare_for_testing "failed to prepare" ${testfile} \
ed07ac
+                        ${::srcfile2} [list debug shlib=$lib_so]] {
ed07ac
+    return -1
ed07ac
+}
ed07ac
+
ed07ac
+# Do whatever is necessary to make sure that the shared library is
ed07ac
+# loaded for remote targets.
ed07ac
+gdb_load_shlib ${lib_so}
ed07ac
+
ed07ac
+if ![runto_main] then {
ed07ac
+    fail "can't run to main"
ed07ac
+    return
ed07ac
+}
ed07ac
+
ed07ac
+# Step into foo so that we can finish out of it.
ed07ac
+gdb_test "step" "foo .. at .* foo end.*" "step into foo"
ed07ac
+
ed07ac
+# Finishing out of foo will create a value that will later need to
ed07ac
+# be preserved when restarting the program.
ed07ac
+gdb_test "finish" "= \\(class B \\*\\) ${::hex} .*" "finish out of foo"
ed07ac
+
ed07ac
+# Dereferencing and printing the return value isn't necessary
ed07ac
+# for reproducing the bug, but we should make sure that the
ed07ac
+# return value is what we expect it to be.
ed07ac
+gdb_test "p *$" { = { = {a = 8, x = 9}, b = 10, x2 = 11}} \
ed07ac
+         "dereference return value"
ed07ac
+
ed07ac
+# The original PR28030 reproducer stepped back into the shared object,
ed07ac
+# so we'll do the same here:
ed07ac
+gdb_test "step" "bar \\(.*" "step into bar"
ed07ac
+
ed07ac
+# We don't want a clean restart here since that will be too clean.
ed07ac
+# The original reproducer for PR28030 set a breakpoint in the shared
ed07ac
+# library and then restarted via "run".  The command below does roughly
ed07ac
+# the same thing.  It's at this step that an internal error would
ed07ac
+# occur for PR28030.  The "message" argument tells runto to turn on
ed07ac
+# the printing of PASSes while runto is doing its job.
ed07ac
+runto "bar" message
ed07ac
diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.h b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.h
ed07ac
new file mode 100644
ed07ac
--- /dev/null
ed07ac
+++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.h
ed07ac
@@ -0,0 +1,30 @@
ed07ac
+/* Copyright (C) 2021 Free Software Foundation, Inc.
ed07ac
+
ed07ac
+   This file is part of GDB.
ed07ac
+
ed07ac
+   This program is free software; you can redistribute it and/or modify
ed07ac
+   it under the terms of the GNU General Public License as published by
ed07ac
+   the Free Software Foundation; either version 3 of the License, or
ed07ac
+   (at your option) any later version.
ed07ac
+
ed07ac
+   This program is distributed in the hope that it will be useful,
ed07ac
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ed07ac
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ed07ac
+   GNU General Public License for more details.
ed07ac
+
ed07ac
+   You should have received a copy of the GNU General Public License
ed07ac
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
ed07ac
+
ed07ac
+typedef struct A {
ed07ac
+    long a;
ed07ac
+    long x;
ed07ac
+} A;
ed07ac
+
ed07ac
+typedef struct B {
ed07ac
+    A a;
ed07ac
+    long b;
ed07ac
+    long x2;
ed07ac
+} B;
ed07ac
+
ed07ac
+extern B *foo ();
ed07ac
+extern B *bar (B *v);