936d299246
This does two things: 1. Adds a test. Recently compare-sections got a new "-r" switch, but given no test existed for compare-sections, the patch was allowed in with no testsuite addition. This now adds a test for both compare-sections and compare-sections -r. 2. Makes the compare-sections command work against all targets. Currently, compare-sections only works with remote targets, and only those that support the qCRC packet. The patch makes it so that if the target doesn't support accelerating memory verification, then GDB falls back to comparing memory itself. This is of course slower, but it's better than nothing, IMO. While testing against extended-remote GDBserver I noticed that we send the qCRC request to the target if we're connected, but not yet running a program. That can't work of course -- the patch fixes that. This all also goes in the direction of bridging the local/remote parity gap. I didn't decouple 1. from 2., because that would mean that the test would need to handle the case of the target not supporting the command. Tested on x86_64 Fedora 17, native, remote GDBserver, and extended-remote GDBserver. I also hack-disabled qCRC support to make sure the fallback paths in remote.c work. gdb/doc/ 2014-05-20 Pedro Alves <palves@redhat.com> * gdb.texinfo (Memory) <compare-sections>: Generalize comments to not be remote specific. Add cross reference to the qCRC packet. (Separate Debug Files): Update cross reference to the qCRC packet. (General Query Packets) <qCRC packet>: Add anchor. gdb/ 2014-05-20 Pedro Alves <palves@redhat.com> * NEWS: Mention that compare-sections now works with all targets. * remote.c (PACKET_qCRC): New enum value. (remote_verify_memory): Don't send qCRC if the target has no execution. Use packet_support/packet_ok. If the target doesn't support the qCRC packet, fallback to a deep memory copy. (compare_sections_command): Say "target image" instead of "remote executable". (_initialize_remote): Add PACKET_qCRC to the list of config packets that have no associated command. Extend comment. * target.c (simple_verify_memory, default_verify_memory): New function. * target.h (struct target_ops) <to_verify_memory>: Default to default_verify_memory. (simple_verify_memory): New declaration. * target-delegates.c: Regenerate. gdb/testsuite/ 2014-05-20 Pedro Alves <palves@redhat.com> * gdb.base/compare-sections.c: New file. * gdb.base/compare-sections.exp: New file.
152 lines
4.1 KiB
Text
152 lines
4.1 KiB
Text
# Copyright 2014 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 the compare-sections command.
|
|
|
|
standard_testfile
|
|
|
|
if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug}]} {
|
|
return -1
|
|
}
|
|
|
|
# Run the compare-sections command along with any options as specified
|
|
# by OPTIONS, and check that no mismatch is found.
|
|
proc compare_sections { {options ""} } {
|
|
global gdb_prompt
|
|
|
|
if {$options != ""} {
|
|
set command "compare-sections $options"
|
|
} else {
|
|
set command "compare-sections"
|
|
}
|
|
set test $command
|
|
gdb_test_multiple $command $test {
|
|
-re "MIS-MATCHED.*$gdb_prompt $" {
|
|
fail $test
|
|
}
|
|
-re "warning.*One or more sections.*does not match.*loaded file.*$gdb_prompt $" {
|
|
fail $test
|
|
}
|
|
-re "Section.*matched.*$gdb_prompt $" {
|
|
pass $test
|
|
}
|
|
}
|
|
}
|
|
|
|
gdb_file_cmd $binfile
|
|
|
|
with_test_prefix "after file" {
|
|
# Before starting the target, we're just comparing the
|
|
# executable's sections against themselves... This should never
|
|
# find a mismatch.
|
|
compare_sections
|
|
compare_sections "-r"
|
|
}
|
|
|
|
# Load the file into the target.
|
|
gdb_reload
|
|
|
|
with_test_prefix "after reload" {
|
|
# We're presumabily still stopped at the entry point. All
|
|
# sections should match.
|
|
compare_sections
|
|
compare_sections "-r"
|
|
}
|
|
|
|
# Try comparing just one section. Assume there's a .text section,
|
|
# which is a pretty safe bet.
|
|
set command "compare-sections .text"
|
|
set command_re [string_to_regexp $command]
|
|
set test $command
|
|
gdb_test_multiple $command $test {
|
|
-re "^$command_re\r\nSection .text, range $hex -- $hex. matched\.\r\n$gdb_prompt $" {
|
|
pass $test
|
|
}
|
|
}
|
|
|
|
# Now get past startup code.
|
|
if ![runto_main] then {
|
|
fail "Can't run to main"
|
|
return 0
|
|
}
|
|
|
|
with_test_prefix "after run to main" {
|
|
# Assume all targets' startup code changes some loaded variable.
|
|
gdb_test "compare-sections" \
|
|
"MIS-MATCHED.*warning.*One or more sections.*does not match.*loaded file"
|
|
|
|
# Assume startup code doesn't change read-only sections.
|
|
compare_sections "-r"
|
|
}
|
|
|
|
# Now test that "compare-sections -r" works as expected. Look for an
|
|
# address in a read-only section, patch it, and check that
|
|
# "compare-sections -r" detects a mismatch.
|
|
with_test_prefix "read-only" {
|
|
set ro_address 0
|
|
set has_ro_sections 0
|
|
set test "list read-only sections"
|
|
gdb_test_multiple "maint info sections READONLY" $test {
|
|
-re "($hex)->$hex at $hex. \[^\r\n\]* READONLY.*$gdb_prompt $" {
|
|
set ro_address $expect_out(1,string)
|
|
set has_ro_sections 1
|
|
pass $test
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
pass $test
|
|
}
|
|
}
|
|
|
|
if {!$has_ro_sections} {
|
|
unsupported "no read-only sections"
|
|
return -1;
|
|
}
|
|
|
|
set orig -1
|
|
|
|
set test "get value of read-only section"
|
|
gdb_test_multiple "print /d *(unsigned char *) $ro_address" "$test" {
|
|
-re " = (\[0-9\]*).*$gdb_prompt $" {
|
|
set orig $expect_out(1,string)
|
|
pass "$test"
|
|
}
|
|
}
|
|
|
|
if {$orig == -1} {
|
|
untested "couldn't read address of read-only section"
|
|
return -1
|
|
}
|
|
|
|
# Come up with different value.
|
|
set patch [expr 255 - $orig]
|
|
|
|
# Write PATCH to memory.
|
|
set written -1
|
|
set test "corrupt read-only section"
|
|
gdb_test_multiple "print /d *(unsigned char *) $ro_address = $patch" "$test" {
|
|
-re " = (\[0-9\]*).*$gdb_prompt $" {
|
|
set written $expect_out(1,string)
|
|
pass "$test"
|
|
}
|
|
}
|
|
|
|
if { $written != $patch } {
|
|
unsupported "can't patch read-only section"
|
|
return -1
|
|
}
|
|
|
|
gdb_test "compare-sections -r" \
|
|
"MIS-MATCHED.*warning.*One or more sections.*does not match.*loaded file.*"
|
|
}
|