2020-01-01 07:20:01 +01:00
|
|
|
# Copyright 2019-2020 Free Software Foundation, Inc.
|
2019-10-13 08:12:29 +02:00
|
|
|
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
# Import a CU into an "artificial" CU. For each DW_TAG DIE in the
|
|
|
|
# artificial CU, use DW_AT_abstract_origin to refer to a DIE in the
|
|
|
|
# imported CU. This DWARF file organization is frequently found in
|
|
|
|
# programs compiled with -flto (and -g) using GCC.
|
|
|
|
#
|
|
|
|
# This test reproduces the bug described in BZ 25065 without relying
|
|
|
|
# on specific compiler versions or use of optimization switches, in
|
|
|
|
# this case -flto.
|
|
|
|
|
|
|
|
if [skip_cplus_tests] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
load_lib dwarf.exp
|
|
|
|
|
|
|
|
# This test can only be run on targets which support DWARF-2 and use gas.
|
|
|
|
if {![dwarf2_support]} {
|
|
|
|
return 0
|
|
|
|
};
|
|
|
|
|
|
|
|
standard_testfile .c .S
|
|
|
|
|
|
|
|
# ${testfile} is now "implref-struct". srcfile2 is "implref-struct.S".
|
|
|
|
set executable ${testfile}
|
|
|
|
set asm_file [standard_output_file ${srcfile2}]
|
|
|
|
|
|
|
|
# We need to know the size of integer and address types in order
|
|
|
|
# to write some of the debugging info we'd like to generate.
|
|
|
|
if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug c++}] {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create the DWARF.
|
|
|
|
Dwarf::assemble $asm_file {
|
|
|
|
declare_labels cu_label main_label doit_label int_label
|
|
|
|
declare_labels Foo_label Foo_pointer_type doit_self_label
|
|
|
|
declare_labels foo_label Foo_destructor_obj_pointer_label
|
|
|
|
declare_labels Foo_constructor_obj_pointer_label
|
|
|
|
set int_size [get_sizeof "int" 4]
|
|
|
|
set addr_size [get_sizeof "void *" 8]
|
|
|
|
|
|
|
|
global srcdir subdir srcfile
|
|
|
|
|
|
|
|
extern main
|
|
|
|
extern doit
|
|
|
|
|
|
|
|
set main_range [function_range main ${srcdir}/${subdir}/${srcfile}]
|
|
|
|
set main_start [lindex $main_range 0]
|
|
|
|
set main_length [lindex $main_range 1]
|
|
|
|
|
|
|
|
set doit_range [function_range doit ${srcdir}/${subdir}/${srcfile}]
|
|
|
|
set doit_start [lindex $doit_range 0]
|
|
|
|
set doit_length [lindex $doit_range 1]
|
|
|
|
|
|
|
|
cu {} {
|
|
|
|
compile_unit {
|
|
|
|
{language @DW_LANG_C_plus_plus}
|
|
|
|
{name "<artificial>"}
|
|
|
|
} {
|
|
|
|
imported_unit {
|
2019-12-08 11:25:28 +01:00
|
|
|
{import %$cu_label}
|
2019-10-13 08:12:29 +02:00
|
|
|
}
|
|
|
|
subprogram {
|
2019-12-08 11:25:28 +01:00
|
|
|
{abstract_origin %$main_label}
|
2019-10-13 08:12:29 +02:00
|
|
|
{low_pc $main_start addr}
|
|
|
|
{high_pc "$main_start + $main_length" addr}
|
|
|
|
} {
|
|
|
|
subprogram {
|
2019-12-08 11:25:28 +01:00
|
|
|
{abstract_origin %$doit_label}
|
2019-10-13 08:12:29 +02:00
|
|
|
{low_pc $doit_start addr}
|
|
|
|
{high_pc "$doit_start + $doit_length" addr}
|
|
|
|
} {
|
|
|
|
formal_parameter {
|
2019-12-08 11:25:28 +01:00
|
|
|
{abstract_origin %$doit_self_label}
|
2019-10-13 08:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DW_TAG_variable {
|
2019-12-08 11:25:28 +01:00
|
|
|
{abstract_origin %$foo_label}
|
2019-10-13 08:12:29 +02:00
|
|
|
{location 4 data1}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cu {} {
|
|
|
|
cu_label: compile_unit {
|
|
|
|
{language @DW_LANG_C_plus_plus}
|
|
|
|
{name "imported_unit.c"}
|
|
|
|
} {
|
|
|
|
int_label: base_type {
|
|
|
|
{byte_size $int_size sdata}
|
|
|
|
{encoding @DW_ATE_signed}
|
|
|
|
{name int}
|
|
|
|
}
|
|
|
|
|
|
|
|
main_label: subprogram {
|
|
|
|
{name main}
|
|
|
|
{type :$int_label}
|
|
|
|
{external 1 flag}
|
|
|
|
} {
|
|
|
|
Foo_label: class_type {
|
|
|
|
{name Foo}
|
|
|
|
{byte_size 1 sdata}
|
|
|
|
} {
|
|
|
|
doit_label: subprogram {
|
|
|
|
{name doit}
|
|
|
|
{type :$int_label}
|
|
|
|
{accessibility 1 DW_FORM_data1}
|
|
|
|
} {
|
|
|
|
doit_self_label: formal_parameter {
|
|
|
|
{name this}
|
|
|
|
{artificial 1 DW_FORM_flag_present}
|
|
|
|
{type :$Foo_pointer_type}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Foo_pointer_type: pointer_type {
|
|
|
|
{byte_size $addr_size sdata}
|
|
|
|
{type :$Foo_label}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foo_label: DW_TAG_variable {
|
|
|
|
{name foo}
|
|
|
|
{type :$Foo_label}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if { [prepare_for_testing "failed to prepare" ${testfile} \
|
|
|
|
[list $srcfile $asm_file] {nodebug}] } {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test_no_output "set language c++"
|
|
|
|
|
[gdb/symtab] Fix partial unit psymtabs
Consider test-case gdb.dwarf2/imported-unit.exp.
It contains a CU with type int:
...
<0><129>: Abbrev Number: 2 (DW_TAG_compile_unit)
<12a> DW_AT_language : 4 (C++)
<12b> DW_AT_name : imported_unit.c
<1><13b>: Abbrev Number: 3 (DW_TAG_base_type)
<13c> DW_AT_byte_size : 4
<13d> DW_AT_encoding : 5 (signed)
<13e> DW_AT_name : int
...
which is imported in another CU:
...
<0><d2>: Abbrev Number: 2 (DW_TAG_compile_unit)
<d3> DW_AT_language : 4 (C++)
<d4> DW_AT_name : <artificial>
<1><e1>: Abbrev Number: 3 (DW_TAG_imported_unit)
<e2> DW_AT_import : <0x129> [Abbrev Number: 2]
...
However, if we print the partial symbols:
...
$ gdb -batch imported-unit -ex "maint print psymbols"
...
we see type int both in the importing CU:
...
Partial symtab for source file <artificial>@0xc7 (object 0x29f9b80)
...
Depends on 1 other partial symtabs.
0 0x2a24240 imported_unit.c
Global partial symbols:
`main', function, 0x4004b2
Static partial symbols:
`int', type, 0x0
...
and in the imported CU:
...
Partial symtab for source file imported_unit.c (object 0x2a24240)
...
Depends on 0 other partial symtabs.
Shared partial symtab with user 0x29f9b80
Static partial symbols:
`int', type, 0x0
...
This is an artefact resulting from the fact that all CUs in an objfile
share the same storage array for static partial symbols (and another array for
global partial symbols), using a range to describe their symbols.
Then when scanning the partial symbols of a CU and encountering an import, either:
- the referred CU has not been parsed yet, and will be parsed, and the range of
static partial symbols of the referred CU will be a subrange of the range of
static partial symbols of this CU, or
- the referred CU has already been parsed, and the range of static partial
symbols of the referred CU will not be a subrange of the range of static
partial symbols of this CU.
This is inconsistent handling, and confuses the notion of a symbol belonging to
a single symtab.
Furthermore, it might slow down searches, given that the symbol needs to be
skipped twice.
Finally, the same issue holds for global partial symbols, where the range of a
CU is sorted after parsing is finished. Obviously sorting the range of a CU
may invalidate subranges, effectively moving symbols in and out of imported
CUs.
Fix this for both static and global partial symbols, by gathering partial
symbols in a per-CU vector, and adding those symbols to the per-objfile
storage only once complete.
Tested on x86_64-linux, with native and board cc-with-dwz and cc-with-dwz-m.
gdb/ChangeLog:
2020-03-13 Tom de Vries <tdevries@suse.de>
PR symtab/25646
* psymtab.c (partial_symtab::partial_symtab): Don't set
globals_offset and statics_offset. Push element onto
current_global_psymbols and current_static_psymbols stacks.
(concat): New function.
(end_psymtab_common): Set globals_offset and statics_offset. Pop
element from current_global_psymbols and current_static_psymbols
stacks. Concat popped elements to global_psymbols and
static_symbols.
(add_psymbol_to_list): Use current_global_psymbols and
current_static_psymbols stacks.
* psymtab.h (class psymtab_storage): Add current_global_psymbols and
current_static_psymbols fields.
gdb/testsuite/ChangeLog:
2020-03-13 Tom de Vries <tdevries@suse.de>
PR symtab/25646
* gdb.dwarf2/imported-unit.exp: Add test.
2020-03-13 08:50:51 +01:00
|
|
|
# Verify that the partial symtab for the unit importing the partial unit does
|
|
|
|
# not contain the static partial symbol int, which is defined in the partial
|
|
|
|
# unit. Test-case for PR25646.
|
|
|
|
gdb_test "main print psymbols" \
|
|
|
|
[multi_line \
|
|
|
|
" Depends on 1 other partial symtabs\." \
|
|
|
|
"\[^\r\n\]*" \
|
|
|
|
" Global partial symbols:" \
|
|
|
|
" `main', function, $hex" \
|
|
|
|
"" \
|
|
|
|
".*"] \
|
|
|
|
"no static partial symbols in importing unit"
|
|
|
|
|
2019-10-13 08:12:29 +02:00
|
|
|
# Sanity check
|
|
|
|
gdb_test "ptype main" "= int \\(void\\)"
|
|
|
|
|
|
|
|
# Each of these tests caused a segfault prior to fixing BZ 25065.
|
|
|
|
gdb_test "ptype main::Foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}"
|
|
|
|
gdb_test "ptype main::foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}"
|