OSDN Git Service

2012-01-16 Pedro Alves <palves@redhat.com>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.threads / gcore-thread.exp
index 5ecfd0c..dfb2314 100644 (file)
@@ -1,5 +1,4 @@
-# Copyright 2002, 2003, 2004, 2007, 2008, 2009, 2010
-# Free Software Foundation, Inc.
+# Copyright 2002-2004, 2007-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
 # 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}/gcore-${testfile}
+set testfile "gcore-thread"
+set srcfile  pthreads.c
+set objfile  ${objdir}/${subdir}/${testfile}.o
+set binfile  ${objdir}/${subdir}/${testfile}
+set corefile ${objdir}/${subdir}/${testfile}.test
+set core0file ${objdir}/${subdir}/${testfile}0.test
 
 if [istarget "*-*-linux"] then {
     set target_cflags "-D_MIT_POSIX_THREADS"
@@ -35,7 +30,15 @@ if [istarget "*-*-linux"] then {
     set target_cflags ""
 }
 
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
+# Attempt to prevent -Wl,-z,relro which happens by default at least on
+# Kubuntu-10.10.  Due to PR corefiles/11804 will then GDB be unable to find
+# libpthread, therefore libthread_db will not fail as expected
+# on the test `zeroed-threads cannot be listed'.
+
+set opts [list debug "incdir=${objdir}"]
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $opts] != ""
+    || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {additional_flags=-Wl,-z,norelro}] ] != ""
+        && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] != "") } {
     return -1
 }
 
@@ -43,10 +46,7 @@ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executab
 
 # Start with a fresh gdb.
 
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
+clean_restart ${testfile}
 
 # regexp for "horizontal" text (i.e. doesn't include newline or
 # carriage return)
@@ -57,8 +57,7 @@ set nl "\[\r\n\]+"
 
 set timeout 30
 
-send_gdb "help gcore\n"
-gdb_expect {
+gdb_test_multiple "help gcore" "help gcore" {
     -re "Undefined command: .gcore.*$gdb_prompt $" {
        # gcore command not supported -- nothing to test here.
        unsupported "gdb does not support gcore on this target"
@@ -67,12 +66,6 @@ gdb_expect {
     -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 {
@@ -80,8 +73,7 @@ if { ! [ runto_main ] } then {
     return -1
 }
 
-send_gdb "info threads\n"
-gdb_expect {
+gdb_test_multiple "info threads" "threads are supported" {
     -re ".* main .*$gdb_prompt $" {
        # OK, threads are supported.
     }
@@ -101,10 +93,10 @@ delete_breakpoints
 gdb_breakpoint "thread2"
 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
 
-set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
+set escapedfilename [string_to_regexp $corefile]
 # Drop corefile
-gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
-       "save a corefile" \
+set core_supported 0
+gdb_test_multiple "gcore $corefile" "save a corefile" \
 {
   -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
     pass "save a corefile"
@@ -113,48 +105,75 @@ gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
   }
   -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
     unsupported "save a corefile"
-    global core_supported
-    set core_supported 0
   }
 }
 
-global core_supported
 if {!$core_supported} {
   return -1
 }
 
-# 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)"
+
+# Test the uninitialized thread list.
+# Provide the case of glibc td_thr_get_info handling of:
+# /* Special case for the main thread before initialization.  */
+
+foreach symbol {__stack_user stack_used} {
+    set test "clear ${symbol}.next"
+    gdb_test_multiple "p *(void **) &${symbol} = 0" $test {
+       -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" {
+           pass $test
+       }
+       -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
+           xfail $test
+           # Do not do the verification.
+           set core0file ""
+       }
     }
 }
 
+if {"$core0file" != ""} {
+    gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
+}
+
+
+# Now restart gdb and load the corefile.
+clean_restart ${testfile}
+
+proc load_core { corefile } {
+    global gdb_prompt
+    global libthread_db_seen
+
+    set libthread_db_seen 0
+    gdb_test_multiple "core $corefile" \
+       "re-load generated corefile" {
+           -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
+               set libthread_db_seen 1
+               exp_continue
+           }
+           -re " is not a core dump:.*\r\n$gdb_prompt $" {
+               fail "re-load generated corefile (bad file format)"
+               # No use proceeding from here.
+               return 0;
+           }
+           -re ": No such file or directory.*\r\n$gdb_prompt $" {
+               fail "re-load generated corefile (file not found)"
+               # No use proceeding from here.
+               return 0;
+           }
+           -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
+               fail "re-load generated corefile (incomplete note section)"
+           }
+           -re "Core was generated by .*\r\n$gdb_prompt $" {
+               pass "re-load generated corefile"
+           }
+       }
+    return 1
+}
+
+if ![load_core $corefile] {
+    return
+}
+
 # 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
@@ -174,3 +193,16 @@ gdb_test "info threads" ".* thread2 .*" \
 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
        "thread2 is current thread in corefile"
 
+
+# Test the uninitialized thread list.
+
+if {"$core0file" != "" && [load_core $core0file]} {
+    set test "zeroed-threads cannot be listed"
+
+    if {!$libthread_db_seen} {
+       verbose -log "No libthread_db loaded - -Wl,-z,relro compilation?"
+       xfail $test
+    } else {
+       gdb_test "info threads" "Cannot find new threads: .*" $test
+    }
+}