diff options
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/gnu-debugdata.c | 30 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/gnu-debugdata.exp | 157 | ||||
-rw-r--r-- | gdb/testsuite/lib/gdb.exp | 9 |
4 files changed, 204 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index cd7c704..b5b125f 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,4 +1,12 @@ 2012-11-26 Jan Kratochvil <jan.kratochvil@redhat.com> + Tom Tromey <tromey@redhat.com> + + * gdb.base/gnu-debugdata.exp: New file. + * gdb.base/gnu-debugdata.c: New file. + * lib/gdb.exp (gdb_file_cmd): Handle LZMA warning. + (gdb_unload): Return 0 on success. + +2012-11-26 Jan Kratochvil <jan.kratochvil@redhat.com> * gdb.base/enumval.exp (print e, print f, print K): XFAIL on GCC <= 4.6. diff --git a/gdb/testsuite/gdb.base/gnu-debugdata.c b/gdb/testsuite/gdb.base/gnu-debugdata.c new file mode 100644 index 0000000..b8b7e8a --- /dev/null +++ b/gdb/testsuite/gdb.base/gnu-debugdata.c @@ -0,0 +1,30 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2012 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/>. */ + +#include <signal.h> + +static int +debugdata_function (void) +{ + return raise (SIGSEGV) + 1; +} + +int +main (void) +{ + return debugdata_function () + 1; +} diff --git a/gdb/testsuite/gdb.base/gnu-debugdata.exp b/gdb/testsuite/gdb.base/gnu-debugdata.exp new file mode 100644 index 0000000..f876309 --- /dev/null +++ b/gdb/testsuite/gdb.base/gnu-debugdata.exp @@ -0,0 +1,157 @@ +# Copyright 2012 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/>. + +standard_testfile + +if [build_executable ${testfile}.exp $testfile] { + return -1 +} + +# A wrapper for 'remote_exec host' that passes or fails a test. +# Returns 0 if all went well, nonzero on failure. +# TEST is the name of the test, other arguments are as for +# remote_exec. +proc run {test program args} { + verbose "cmdline is remote_exec host $program $args" + # remote_exec doesn't work properly if the output is set but the + # input is the empty string -- so replace an empty input with + # /dev/null. + if {[llength $args] > 1 && [lindex $args 1] == ""} { + set args [lreplace $args 1 1 "/dev/null"] + } + set result [eval remote_exec host [list $program] $args] + verbose "result is $result" + lassign $result status output + if {$status == 0} { + pass $test + return 0 + } else { + fail $test + return -1 + } +} + +set pipeline_counter 0 + +# Run a pipeline of processes through 'run'. +# TEST is the base name of the test, it is modified and passed to 'run'. +# Each subsequent argument is a list of the form {PROGRAM [ARG]...}. +# It is passed to 'run'. However, before being passed, if input and output +# files are not specified in the list, then this proc provides them. +# Each program in the pipeline takes its input from the previous +# program's output. +proc pipeline {test args} { + global pipeline_counter + + set input_file {} + foreach arglist $args { + verbose "raw args are $arglist" + lassign $arglist program arguments input output + + if {$input == ""} { + set input $input_file + } + if {$output == ""} { + set output [standard_output_file pipe.[pid].$pipeline_counter] + incr pipeline_counter + } + verbose "cooked args are [list $program $arguments $input $output]" + + if {[run "$test - invoke $program" $program $arguments \ + $input $output]} { + return -1 + } + + set input_file $output + } + return 0 +} + +# Extract the dynamic symbols from the main binary, there is no need +# to also have these in the normal symbol table. +remote_file host delete ${binfile}.dynsyms +if {[pipeline "nm -D" \ + [list [transform nm] "-D ${binfile} --format=posix --defined-only"] \ + [list awk "\\{print\\ \\\$1\\}"] \ + [list sort "" "" "${binfile}.dynsyms"]]} { + return -1 +} + +# Extract all the text (i.e. function) symbols from the debuginfo. +remote_file host delete ${binfile}.funcsyms +if {[pipeline "nm" \ + [list [transform nm] "${binfile} --format=posix --defined-only"] \ + [list awk "\\{if(\\\$2==\"T\"||\\\$2==\"t\")print\\ \\\$1\\}"] \ + [list sort "" "" "${binfile}.funcsyms"]]} { + return -1 +} + +# Keep all the function symbols not already in the dynamic symbol +# table. +remote_file host delete ${binfile}.keep_symbols +if {[run "comm" "comm" "-13 ${binfile}.dynsyms ${binfile}.funcsyms" "" \ + "${binfile}.keep_symbols"]} { + return -1 +} + +# Copy the full debuginfo, keeping only a minimal set of symbols and +# removing some unnecessary sections. +remote_file host delete ${binfile}.mini_debuginfo +if {[run "objcopy 1" [transform objcopy] "-S --remove-section .gdb_index --remove-section .comment --keep-symbols=${binfile}.keep_symbols ${binfile} ${binfile}.mini_debuginfo"]} { + return -1 +} + +# GDB specific - we do not have split executable in advance. +remote_file host delete ${binfile}.strip +if {[run "strip" [transform strip] \ + "--strip-all -o ${binfile}.strip ${binfile}"]} { + return -1 +} + +# Inject the compressed data into the .gnu_debugdata section of the +# original binary. +remote_file host delete ${binfile}.mini_debuginfo.xz +if {[run "xz" "xz" "${binfile}.mini_debuginfo"]} { + return -1 +} +remote_file host delete ${binfile}.test +if {[run "objcopy 2" [transform objcopy] "--add-section .gnu_debugdata=${binfile}.mini_debuginfo.xz ${binfile}.strip ${binfile}.test"]} { + return -1 +} + +clean_restart "$testfile.strip" + +gdb_test "p debugdata_function" \ + {No symbol table is loaded\. Use the "file" command\.} \ + "no symtab" + +clean_restart "$testfile.test" + +if {$gdb_file_cmd_debug_info == "lzma"} { + unsupported "LZMA support not available in this gdb" +} else { + gdb_test "p debugdata_function" \ + { = {<text variable, no debug info>} 0x[0-9a-f]+ <debugdata_function>} \ + "have symtab" +} + +# Be sure to test the 'close' method on the MiniDebugInfo BFD. +if {[gdb_unload]} { + fail "unload MiniDebugInfo" +} else { + pass "unload MiniDebugInfo" +} + +gdb_exit diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 16e8b54..781ccc8 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -128,6 +128,7 @@ proc gdb_version { } { # # gdb_unload -- unload a file if one is loaded +# Return 0 on success, -1 on error. # proc gdb_unload {} { @@ -152,6 +153,7 @@ proc gdb_unload {} { return -1 } } + return 0 } # Many of the tests depend on setting breakpoints at various places and @@ -1278,6 +1280,8 @@ proc default_gdb_exit {} { # # debug file was loaded successfully and has debug information # nodebug file was loaded successfully and has no debug information +# lzma file was loaded, .gnu_debugdata found, but no LZMA support +# compiled in # fail file was not loaded # # I tried returning this information as part of the return value, @@ -1325,6 +1329,11 @@ proc gdb_file_cmd { arg } { send_gdb "file $arg\n" gdb_expect 120 { + -re "Reading symbols from.*LZMA support was disabled.*done.*$gdb_prompt $" { + verbose "\t\tLoaded $arg into $GDB; .gnu_debugdata found but no LZMA available" + set gdb_file_cmd_debug_info "lzma" + return 0 + } -re "Reading symbols from.*no debugging symbols found.*done.*$gdb_prompt $" { verbose "\t\tLoaded $arg into $GDB with no debugging symbols" set gdb_file_cmd_debug_info "nodebug" |