2020-01-01 14:20:01 +08:00
|
|
|
# Copyright 2013-2020 Free Software Foundation, Inc.
|
2013-08-27 02:43:40 +08: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/>.
|
|
|
|
|
|
|
|
load_lib dwarf.exp
|
|
|
|
|
|
|
|
# This test can only be run on targets which support DWARF-2.
|
|
|
|
if {![dwarf2_support]} {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
standard_testfile main.c
|
|
|
|
|
2016-12-24 00:52:18 +08:00
|
|
|
if { [prepare_for_testing "failed to prepare" "${testfile}" \
|
2013-08-27 02:43:40 +08:00
|
|
|
[list ${srcfile}]] } {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add a .gdb_index section to PROGRAM.
|
|
|
|
# PROGRAM is assumed to be the output of standard_output_file.
|
|
|
|
# Returns the path of the program or "" if there is a failure.
|
|
|
|
# If there is a failure it will have already been logged.
|
|
|
|
|
|
|
|
proc add_gdb_index { program } {
|
|
|
|
set index_file ${program}.gdb-index
|
2019-09-30 05:58:21 +08:00
|
|
|
set dir [file dirname ${program}]
|
|
|
|
set filename [file tail ${program}]
|
|
|
|
set dwz $dir/.tmp/${filename}.dwz
|
|
|
|
set dwz_index_file $program.dwz.gdb-index
|
2013-08-27 02:43:40 +08:00
|
|
|
verbose -log "index_file: ${index_file}"
|
|
|
|
remote_file host delete ${index_file}
|
Write index for dwz -m file
PR 24445 ("dwz multifile index not written to index cache") exposed the
fact that we are not doing things right when we generate an index for an
object file that has is linked to a dwz file. The same happens whether
the index is generated with the intent of populating the index cache or
using the save gdb-index command.
The problem can be observed when running these tests with the
cc-with-dwz-m board:
FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
FAIL: gdb.dwarf2/gdb-index.exp: index used
FAIL: gdb.dwarf2/gdb-index.exp: index used after symbol reloading
When generating the index for such file and inspecting the CU list of the
resulting index (with readelf --debug-dump=gdb_index), we can see something
like:
CU table:
[ 0] 0x0 - 0xb9
[ 1] 0x0 - 0x44
This is supposed to be a sorted list of the ranges of all CUs in the
file this index represents, so already having some overlap is a red
flag. It turns out that we save the ranges of CUs coming from both the
main file and the dwz file in the same index.
After digging a little bit, it became quite obvious that the index in
the main file should only list the CUs present in the main file, and a
separate index should be generated for the dwz file, listing the CUs
present in that file.
First, that's what happens if you run dwz on a file that already has a
GDB index embedded. Second, dwarf2read.c has code to read an index from
a dwz file. The index in the dwz file is actually required to be
present, if the main file has an index.
So this patch changes write_psymtabs_to_index to generate an index for
the dwz file, if present. That index only contains a CU list, just like
what the dwz tool does when processing a file that already contains an
index.
Some notes about the implementation:
- The file management (creating a temp file, make sure it's
close/removed on error - in the right order) is a bit heavy in
write_psymtabs_to_index, and I needed to add a third file. I factored
this pattern in a separate class, index_wip_file.
- It became a bit tedious to keep the call to assert_file_size in
write_psymtabs_to_index, write_gdbindex would have had to return two
sizes. Instead, I moved the calls to assert_file_size where the file
is written. The downside is that we lose the filename at this point,
but it was only used for the very improbable case of ftell failing, so
I think it's not a problem.
- The actual writing of the index file is factored out to
write_gdbindex_1, so it can be re-used for both index files.
- While the "save gdb-index" command will now write two .gdb-index
files, this patch does not update the gdb-add-index.sh script, this
will come in a later patch.
gdb/ChangeLog:
YYYY-MM-DD Simon Marchi <simon.marchi@efficios.com>
PR gdb/24445
* dwarf-index-write.h (write_psymtabs_to_index): Add
dwz_basename parameter.
* dwarf-index-write.c (write_gdbindex): Move file writing to
write_gdbindex_1. Change return type void.
(assert_file_size): Move up, remove filename parameter.
(write_gdbindex_1): New function.
(write_debug_names): Change return type to void, call
assert_file_size.
(struct index_wip_file): New struct.
(write_psymtabs_to_index): Add dwz_basename parameter. Move
file logic to index_wip_file. Write index for dwz file if
needed.
(save_gdb_index_command): Pass basename of dwz file, if present.
* dwarf-index-cache.c (index_cache::store): Obtain and pass
build-id of dwz file, if present.
* dwarf2read.c (struct dwz_file): Move to dwarf2read.h.
(dwarf2_get_dwz_file): Likewise.
* dwarf2read.h (struct dwz_file): Move from dwarf2read.c.
(dwarf2_get_dwz_file): Likewise.
gdb/testsuite/ChangeLog:
YYYY-MM-DD Tom de Vries <tdevries@suse.de>
PR gdb/24445
* gdb.dwarf2/gdb-index.exp (add_gdb_index): Update dwz file with
generated index.
2019-06-16 22:13:56 +08:00
|
|
|
remote_file host delete ${dwz_index_file}
|
2013-08-28 22:20:43 +08:00
|
|
|
gdb_test_no_output "save gdb-index [file dirname ${index_file}]" \
|
|
|
|
"save gdb-index for file [file tail ${program}]"
|
2013-08-27 02:43:40 +08:00
|
|
|
|
|
|
|
# No point in continuing if generating the index failed.
|
|
|
|
# N.B.: There are times when gdb won't create an index, and it's not a
|
|
|
|
# failure. However, in our case we need an index. So if you find one
|
|
|
|
# not being generated, you'll either have to tweak the .c file or maybe
|
|
|
|
# add a flag to force an index to be generated.
|
|
|
|
if { [remote_file host exists ${index_file}] } {
|
|
|
|
pass "gdb-index file created"
|
|
|
|
} else {
|
|
|
|
fail "gdb-index file created"
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
set program_with_index ${program}.with-index
|
2013-09-21 05:47:06 +08:00
|
|
|
if {[run_on_host "objcopy" [gdb_find_objcopy] "--remove-section .gdb_index --add-section .gdb_index=$index_file --set-section-flags .gdb_index=readonly ${program} ${program_with_index}"]} {
|
2013-08-27 02:43:40 +08:00
|
|
|
return ""
|
|
|
|
}
|
Write index for dwz -m file
PR 24445 ("dwz multifile index not written to index cache") exposed the
fact that we are not doing things right when we generate an index for an
object file that has is linked to a dwz file. The same happens whether
the index is generated with the intent of populating the index cache or
using the save gdb-index command.
The problem can be observed when running these tests with the
cc-with-dwz-m board:
FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
FAIL: gdb.dwarf2/gdb-index.exp: index used
FAIL: gdb.dwarf2/gdb-index.exp: index used after symbol reloading
When generating the index for such file and inspecting the CU list of the
resulting index (with readelf --debug-dump=gdb_index), we can see something
like:
CU table:
[ 0] 0x0 - 0xb9
[ 1] 0x0 - 0x44
This is supposed to be a sorted list of the ranges of all CUs in the
file this index represents, so already having some overlap is a red
flag. It turns out that we save the ranges of CUs coming from both the
main file and the dwz file in the same index.
After digging a little bit, it became quite obvious that the index in
the main file should only list the CUs present in the main file, and a
separate index should be generated for the dwz file, listing the CUs
present in that file.
First, that's what happens if you run dwz on a file that already has a
GDB index embedded. Second, dwarf2read.c has code to read an index from
a dwz file. The index in the dwz file is actually required to be
present, if the main file has an index.
So this patch changes write_psymtabs_to_index to generate an index for
the dwz file, if present. That index only contains a CU list, just like
what the dwz tool does when processing a file that already contains an
index.
Some notes about the implementation:
- The file management (creating a temp file, make sure it's
close/removed on error - in the right order) is a bit heavy in
write_psymtabs_to_index, and I needed to add a third file. I factored
this pattern in a separate class, index_wip_file.
- It became a bit tedious to keep the call to assert_file_size in
write_psymtabs_to_index, write_gdbindex would have had to return two
sizes. Instead, I moved the calls to assert_file_size where the file
is written. The downside is that we lose the filename at this point,
but it was only used for the very improbable case of ftell failing, so
I think it's not a problem.
- The actual writing of the index file is factored out to
write_gdbindex_1, so it can be re-used for both index files.
- While the "save gdb-index" command will now write two .gdb-index
files, this patch does not update the gdb-add-index.sh script, this
will come in a later patch.
gdb/ChangeLog:
YYYY-MM-DD Simon Marchi <simon.marchi@efficios.com>
PR gdb/24445
* dwarf-index-write.h (write_psymtabs_to_index): Add
dwz_basename parameter.
* dwarf-index-write.c (write_gdbindex): Move file writing to
write_gdbindex_1. Change return type void.
(assert_file_size): Move up, remove filename parameter.
(write_gdbindex_1): New function.
(write_debug_names): Change return type to void, call
assert_file_size.
(struct index_wip_file): New struct.
(write_psymtabs_to_index): Add dwz_basename parameter. Move
file logic to index_wip_file. Write index for dwz file if
needed.
(save_gdb_index_command): Pass basename of dwz file, if present.
* dwarf-index-cache.c (index_cache::store): Obtain and pass
build-id of dwz file, if present.
* dwarf2read.c (struct dwz_file): Move to dwarf2read.h.
(dwarf2_get_dwz_file): Likewise.
* dwarf2read.h (struct dwz_file): Move from dwarf2read.c.
(dwarf2_get_dwz_file): Likewise.
gdb/testsuite/ChangeLog:
YYYY-MM-DD Tom de Vries <tdevries@suse.de>
PR gdb/24445
* gdb.dwarf2/gdb-index.exp (add_gdb_index): Update dwz file with
generated index.
2019-06-16 22:13:56 +08:00
|
|
|
|
2019-09-30 05:51:50 +08:00
|
|
|
with_test_prefix "modify dwz file" {
|
|
|
|
if { [remote_file host exists ${dwz_index_file}] } {
|
|
|
|
# We're modifying $dwz in place, otherwise we'd have to update
|
|
|
|
# .gnu_debugaltlink in $program.
|
|
|
|
set args [join [list "--remove-section .gdb_index" \
|
|
|
|
" --add-section .gdb_index=$dwz_index_file" \
|
|
|
|
" --set-section-flags .gdb_index=readonly $dwz"]]
|
|
|
|
if {[run_on_host "objcopy" [gdb_find_objcopy] "$args"]} {
|
|
|
|
return ""
|
|
|
|
}
|
Write index for dwz -m file
PR 24445 ("dwz multifile index not written to index cache") exposed the
fact that we are not doing things right when we generate an index for an
object file that has is linked to a dwz file. The same happens whether
the index is generated with the intent of populating the index cache or
using the save gdb-index command.
The problem can be observed when running these tests with the
cc-with-dwz-m board:
FAIL: gdb.base/index-cache.exp: test_cache_enabled_hit: check index-cache stats
FAIL: gdb.dwarf2/gdb-index.exp: index used
FAIL: gdb.dwarf2/gdb-index.exp: index used after symbol reloading
When generating the index for such file and inspecting the CU list of the
resulting index (with readelf --debug-dump=gdb_index), we can see something
like:
CU table:
[ 0] 0x0 - 0xb9
[ 1] 0x0 - 0x44
This is supposed to be a sorted list of the ranges of all CUs in the
file this index represents, so already having some overlap is a red
flag. It turns out that we save the ranges of CUs coming from both the
main file and the dwz file in the same index.
After digging a little bit, it became quite obvious that the index in
the main file should only list the CUs present in the main file, and a
separate index should be generated for the dwz file, listing the CUs
present in that file.
First, that's what happens if you run dwz on a file that already has a
GDB index embedded. Second, dwarf2read.c has code to read an index from
a dwz file. The index in the dwz file is actually required to be
present, if the main file has an index.
So this patch changes write_psymtabs_to_index to generate an index for
the dwz file, if present. That index only contains a CU list, just like
what the dwz tool does when processing a file that already contains an
index.
Some notes about the implementation:
- The file management (creating a temp file, make sure it's
close/removed on error - in the right order) is a bit heavy in
write_psymtabs_to_index, and I needed to add a third file. I factored
this pattern in a separate class, index_wip_file.
- It became a bit tedious to keep the call to assert_file_size in
write_psymtabs_to_index, write_gdbindex would have had to return two
sizes. Instead, I moved the calls to assert_file_size where the file
is written. The downside is that we lose the filename at this point,
but it was only used for the very improbable case of ftell failing, so
I think it's not a problem.
- The actual writing of the index file is factored out to
write_gdbindex_1, so it can be re-used for both index files.
- While the "save gdb-index" command will now write two .gdb-index
files, this patch does not update the gdb-add-index.sh script, this
will come in a later patch.
gdb/ChangeLog:
YYYY-MM-DD Simon Marchi <simon.marchi@efficios.com>
PR gdb/24445
* dwarf-index-write.h (write_psymtabs_to_index): Add
dwz_basename parameter.
* dwarf-index-write.c (write_gdbindex): Move file writing to
write_gdbindex_1. Change return type void.
(assert_file_size): Move up, remove filename parameter.
(write_gdbindex_1): New function.
(write_debug_names): Change return type to void, call
assert_file_size.
(struct index_wip_file): New struct.
(write_psymtabs_to_index): Add dwz_basename parameter. Move
file logic to index_wip_file. Write index for dwz file if
needed.
(save_gdb_index_command): Pass basename of dwz file, if present.
* dwarf-index-cache.c (index_cache::store): Obtain and pass
build-id of dwz file, if present.
* dwarf2read.c (struct dwz_file): Move to dwarf2read.h.
(dwarf2_get_dwz_file): Likewise.
* dwarf2read.h (struct dwz_file): Move from dwarf2read.c.
(dwarf2_get_dwz_file): Likewise.
gdb/testsuite/ChangeLog:
YYYY-MM-DD Tom de Vries <tdevries@suse.de>
PR gdb/24445
* gdb.dwarf2/gdb-index.exp (add_gdb_index): Update dwz file with
generated index.
2019-06-16 22:13:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-27 02:43:40 +08:00
|
|
|
return ${program_with_index}
|
|
|
|
}
|
|
|
|
|
2017-12-09 06:44:12 +08:00
|
|
|
# Build a copy of the program with an index (.gdb_index/.debug_names).
|
2013-08-27 02:43:40 +08:00
|
|
|
# But only if the toolchain didn't already create one: gdb doesn't support
|
|
|
|
# building an index from a program already using one.
|
|
|
|
|
|
|
|
set test "check if index present"
|
|
|
|
gdb_test_multiple "mt print objfiles ${testfile}" $test {
|
|
|
|
-re "gdb_index.*${gdb_prompt} $" {
|
|
|
|
set binfile_with_index $binfile
|
|
|
|
}
|
2017-12-09 06:44:12 +08:00
|
|
|
-re "debug_names.*${gdb_prompt} $" {
|
|
|
|
set binfile_with_index $binfile
|
|
|
|
}
|
2013-08-27 02:43:40 +08:00
|
|
|
-re "Psymtabs.*${gdb_prompt} $" {
|
|
|
|
set binfile_with_index [add_gdb_index $binfile]
|
|
|
|
if { ${binfile_with_index} == "" } {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 06:44:12 +08:00
|
|
|
# Ok, we have a copy of $binfile with an index.
|
2013-08-27 02:43:40 +08:00
|
|
|
# Restart gdb and verify the index was used.
|
|
|
|
|
|
|
|
clean_restart ${binfile_with_index}
|
|
|
|
gdb_test "mt print objfiles ${testfile}" \
|
2017-12-09 06:44:12 +08:00
|
|
|
"(gdb_index|debug_names).*" \
|
|
|
|
"index used"
|
2013-08-27 02:43:40 +08:00
|
|
|
|
2017-12-09 06:44:12 +08:00
|
|
|
# Make gdb re-read symbols and see if .gdb_index/.debug_names still
|
|
|
|
# gets used. symtab/15885
|
2013-08-27 02:43:40 +08:00
|
|
|
|
|
|
|
# There is gdb_touch_execfile, but it doesn't handle remote hosts.
|
|
|
|
# Is touch portable enough?
|
|
|
|
# First make sure enough time has passed, file mtime resolution is seconds.
|
|
|
|
gdb_test_no_output "shell sleep 1"
|
|
|
|
if {[run_on_host "touch binary" touch ${binfile_with_index}]} {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if ![runto_main] {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
gdb_test "mt print objfiles ${testfile}" \
|
2017-12-09 06:44:12 +08:00
|
|
|
"(gdb_index|debug_names).*" \
|
|
|
|
"index used after symbol reloading"
|