From: Michael Snyder Date: Wed, 9 Jan 2002 00:37:41 +0000 (+0000) Subject: 2002-01-08 Michael Snyder X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a911c3606d956a008cb681d2f1d35dd0cee668dc;p=binutils-gdb.git 2002-01-08 Michael Snyder * gdb.base/gcore.exp: New test for generate-core-file command. * gdb.base/gcore.c: Testcase for above. * gdb.threads/gcore-thread.exp: New test for gcore (threaded). --- diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0a916133412..bd859e3b5fa 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2002-01-08 Michael Snyder + + * gdb.base/gcore.exp: New test for generate-core-file command. + * gdb.base/gcore.c: Testcase for above. + * gdb.threads/gcore-thread.exp: New test for gcore (threaded). + 2002-01-08 Jason Merrill * gdb.c++/userdef.cc: Use instead of . diff --git a/gdb/testsuite/gdb.base/gcore.c b/gdb/testsuite/gdb.base/gcore.c new file mode 100644 index 00000000000..af09dced7e1 --- /dev/null +++ b/gdb/testsuite/gdb.base/gcore.c @@ -0,0 +1,52 @@ +/* + * Test GDB's ability to save and reload a corefile. + */ + +#include + +int extern_array[4] = {1, 2, 3, 4}; +static int static_array[4] = {5, 6, 7, 8}; +static int un_initialized_array[4]; +static char *heap_string; + +void +terminal_func () +{ + return; +} + +void +array_func () +{ + int local_array[4]; + int i; + + heap_string = (char *) malloc (80); + strcpy (heap_string, "I'm a little teapot, short and stout..."); + for (i = 0; i < 4; i++) + { + un_initialized_array[i] = extern_array[i] + 8; + local_array[i] = extern_array[i] + 12; + } + terminal_func (); +} + +#ifdef PROTOTYPES +int factorial_func (int value) +#else +int factorial_func (value) + int value; +#endif +{ + if (value > 1) { + value *= factorial_func (value - 1); + } + array_func (); + return (value); +} + +main() +{ + factorial_func (6); + return 0; +} diff --git a/gdb/testsuite/gdb.base/gcore.exp b/gdb/testsuite/gdb.base/gcore.exp new file mode 100644 index 00000000000..232a3b56a49 --- /dev/null +++ b/gdb/testsuite/gdb.base/gcore.exp @@ -0,0 +1,220 @@ +# Copyright 2002 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 2 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Please email any bugs, comments, and/or additions to this file to: +# bug-gdb@prep.ai.mit.edu + +# This file was written by Michael Snyder (msnyder@redhat.com) +# This is a test for the gdb command "generate-core-file". + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile "gcore" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." +} + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +# Does this gdb support gcore? +send_gdb "help gcore\n" +gdb_expect { + -re "Undefined command: .gcore.*$gdb_prompt $" { + # gcore command not supported -- nothing to test here. + unsupported "gdb does not support gcore on this target" + return -1; + } + -re "Save a core file .*$gdb_prompt $" { + pass "help gcore" + } + -re ".*$gdb_prompt $" { + fail "help gcore" + } + timeout { + fail "help gcore (timeout)" + } +} + +if { ! [ runto main ] } then { + gdb_suppress_entire_file "Run to main failed, so all tests in this file will automatically fail." +} + +proc capture_command_output { command prefix } { + global gdb_prompt + global expect_out + + set output_string "" + send_gdb "$command\n" + gdb_expect { + -re "${command}\[\r\n\]+${prefix}(.*)\[\r\n\]+$gdb_prompt $" { + set output_string $expect_out(1,string) + } + default { + fail "capture_command_output failed on $command." + } + } + return $output_string +} + +gdb_test "break terminal_func" "Breakpoint .* at .*${srcfile}, line .*" \ + "set breakpoint at terminal_func" + +gdb_test "continue" "Breakpoint .*, terminal_func.*" \ + "continue to terminal_func" + +set print_prefix ".\[0123456789\]* = " + +set pre_corefile_backtrace [capture_command_output "backtrace" ""] +set pre_corefile_regs [capture_command_output "info registers" ""] +set pre_corefile_allregs [capture_command_output "info all-reg" ""] +set pre_corefile_static_array \ + [capture_command_output "print static_array" "$print_prefix"] +set pre_corefile_uninit_array \ + [capture_command_output "print un_initialized_array" "$print_prefix"] +set pre_corefile_heap_string \ + [capture_command_output "print heap_string" "$print_prefix"] +set pre_corefile_local_array \ + [capture_command_output "print array_func::local_array" "$print_prefix"] +set pre_corefile_extern_array \ + [capture_command_output "print extern_array" "$print_prefix"] + +gdb_test "gcore ${objdir}/${subdir}/gcore.test" \ + "Saved corefile ${objdir}/${subdir}/gcore.test" \ + "save a corefile" + +# Now restart gdb and load the corefile. +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +send_gdb "core ${objdir}/${subdir}/gcore.test\n" +gdb_expect { + -re ".* is not a core dump:.*$gdb_prompt $" { + fail "re-load generated corefile (bad file format)" + # No use proceeding from here. + return; + } + -re ".*: No such file or directory.*$gdb_prompt $" { + fail "re-load generated corefile (file not found)" + # No use proceeding from here. + return; + } + -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" { + fail "re-load generated corefile (incomplete note section)" + } + -re "Core was generated by .*$gdb_prompt $" { + pass "re-load generated corefile" + } + -re ".*$gdb_prompt $" { + fail "re-load generated corefile" + } + timeout { + fail "re-load generated corefile (timeout)" + } +} + +send_gdb "where\n" +gdb_expect_list "where in corefile" ".*$gdb_prompt $" { + ".*\[\r\n\]+#0 .* terminal_func \\(\\) at " + ".*\[\r\n\]+#1 .* array_func \\(\\) at " + ".*\[\r\n\]+#2 .* factorial_func \\(value=1\\) at " + ".*\[\r\n\]+#3 .* factorial_func \\(value=2\\) at " + ".*\[\r\n\]+#4 .* factorial_func \\(value=3\\) at " + ".*\[\r\n\]+#5 .* factorial_func \\(value=4\\) at " + ".*\[\r\n\]+#6 .* factorial_func \\(value=5\\) at " + ".*\[\r\n\]+#7 .* factorial_func \\(value=6\\) at " + ".*\[\r\n\]+#8 .* main \\(.*\\) at " +} + +set post_corefile_regs [capture_command_output "info registers" ""] +if ![string compare $pre_corefile_regs $post_corefile_regs] then { + pass "corefile restored general registers" +} else { + fail "corefile restored general registers:\npre: $pre_corefile_regs\npost: $post_corefile_regs\n" +} + +set post_corefile_allregs [capture_command_output "info all-reg" ""] +if ![string compare $pre_corefile_allregs $post_corefile_allregs] then { + pass "corefile restored all registers" +} else { + fail "corefile restored all registers:\npre: $pre_corefile_allregs\npost: $post_corefile_allregs\n" +} + +set post_corefile_extern_array \ + [capture_command_output "print extern_array" "$print_prefix"] +pass "extern_array = $post_corefile_extern_array" +if ![string compare $pre_corefile_extern_array $post_corefile_extern_array] { + pass "corefile restored extern array" +} else { + fail "corefile restored extern array" +} + +set post_corefile_static_array \ + [capture_command_output "print static_array" "$print_prefix"] +pass "static_array = $post_corefile_static_array" +if ![string compare $pre_corefile_static_array $post_corefile_static_array] { + pass "corefile restored static array" +} else { + fail "corefile restored static array" +} + +set post_corefile_uninit_array \ + [capture_command_output "print un_initialized_array" "$print_prefix"] +pass "uninit_array = $post_corefile_uninit_array" +if ![string compare $pre_corefile_uninit_array $post_corefile_uninit_array] { + pass "corefile restored un-initialized array" +} else { + fail "corefile restored un-initialized array" +} + +set post_corefile_heap_string \ + [capture_command_output "print heap_string" "$print_prefix"] +pass "heap_string = $post_corefile_heap_string" +if ![string compare $pre_corefile_heap_string $post_corefile_heap_string] { + pass "corefile restored heap array" +} else { + fail "corefile restored heap array" +} + +set post_corefile_local_array \ + [capture_command_output "print array_func::local_array" "$print_prefix"] +pass "local_array = $post_corefile_local_array" +if ![string compare $pre_corefile_local_array $post_corefile_local_array] { + pass "corefile restored stack array" +} else { + fail "corefile restored stack array" +} + +set post_corefile_backtrace [capture_command_output "backtrace" ""] +if ![string compare $pre_corefile_backtrace $post_corefile_backtrace] { + pass "corefile restored backtrace" +} else { + fail "corefile restored backtrace" +} diff --git a/gdb/testsuite/gdb.threads/gcore-thread.exp b/gdb/testsuite/gdb.threads/gcore-thread.exp new file mode 100644 index 00000000000..b56697be434 --- /dev/null +++ b/gdb/testsuite/gdb.threads/gcore-thread.exp @@ -0,0 +1,186 @@ +# Copyright 2002 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 2 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Please email any bugs, comments, and/or additions to this file to: +# bug-gdb@prep.ai.mit.edu + +# This file was written by Michael Snyder (msnyder@redhat.com) +# This is a test for the gdb command "generate-core-file". + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +# Single-threaded test case +set testfile "pthreads" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +set built_binfile 0 +if [istarget "*-*-linux"] then { + set target_cflags "-D_MIT_POSIX_THREADS" +} else { + set target_cflags "" +} +set why_msg "unrecognized error" +foreach lib {-lpthreads -lpthread -lthread} { + set options "debug" + lappend options "incdir=${objdir}/${subdir}" + lappend options "libs=$lib" + set ccout [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $options] + switch -regexp -- $ccout { + ".*no posix threads support.*" { + set why_msg "missing threads include file" + break + } + ".*cannot open -lpthread.*" { + set why_msg "missing runtime threads library" + } + ".*Can't find library for -lpthread.*" { + set why_msg "missing runtime threads library" + } + {^$} { + pass "successfully compiled posix threads test case" + set built_binfile 1 + break + } + } +} +if {$built_binfile == "0"} { + unsupported "Couldn't compile ${srcfile}, ${why_msg}" + return -1 +} + +# Now we can proceed with the real testing. + +# Start with a fresh gdb. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +# regexp for "horizontal" text (i.e. doesn't include newline or +# carriage return) +set horiz "\[^\n\r\]*" + +# regexp for newline +set nl "\[\r\n\]+" + +set timeout 30 + +send_gdb "help gcore\n" +gdb_expect { + -re "Undefined command: .gcore.*$gdb_prompt $" { + # gcore command not supported -- nothing to test here. + unsupported "gdb does not support gcore on this target" + return -1; + } + -re "Save a core file .*$gdb_prompt $" { + pass "help gcore" + } + -re ".*$gdb_prompt $" { + fail "help gcore" + } + timeout { + fail "help gcore (timeout)" + } +} + +if { ! [ runto main ] } then { + gdb_suppress_entire_file "Run to main failed, so all tests in this file will automatically fail." +} + +send_gdb "info threads\n" +gdb_expect { + -re ".* main .*$gdb_prompt $" { + # OK, threads are supported. + } + -re "${nl}$gdb_prompt $" { + unsupported "gdb does not support threads on this target" + return -1; + } +} + +# Make sure thread 1 is running +delete_breakpoints +gdb_breakpoint "thread1" +gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running" + +# Make sure thread 2 is running +delete_breakpoints +gdb_breakpoint "thread2" +gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running" + +# Drop corefile +gdb_test "gcore ${objdir}/${subdir}/gcore.test" \ + "Saved corefile ${objdir}/${subdir}/gcore.test" \ + "save a corefile" + +# Now restart gdb and load the corefile. +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +send_gdb "core ${objdir}/${subdir}/gcore.test\n" +gdb_expect { + -re ".* is not a core dump:.*$gdb_prompt $" { + fail "re-load generated corefile (bad file format)" + # No use proceeding from here. + return; + } + -re ".*: No such file or directory.*$gdb_prompt $" { + fail "re-load generated corefile (file not found)" + # No use proceeding from here. + return; + } + -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" { + fail "re-load generated corefile (incomplete note section)" + } + -re "Core was generated by .*$gdb_prompt $" { + pass "re-load generated corefile" + } + -re ".*$gdb_prompt $" { + fail "re-load generated corefile" + } + timeout { + fail "re-load generated corefile (timeout)" + } +} + +# FIXME: now what can we test about the thread state? +# We do not know for certain that there should be at least +# three threads, because who knows what kind of many-to-one +# mapping various OS's may do? Let's assume that there must +# be at least two threads: + +gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \ + "corefile contains at least two threads" + +# One thread in the corefile should be in the "thread2" function. + +gdb_test "info threads" ".* thread2 .*" \ + "a corefile thread is executing thread2" + +# The thread2 thread should be marked as the current thread. + +gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \ + "thread2 is current thread in corefile" +