summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.threads/gcore-thread.exp
blob: 43d253e269fa74c0d090ad256a3c70b7ab194ae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Copyright 2002, 2003, 2004 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}/gcore-${testfile}

if [istarget "*-*-linux"] then {
    set target_cflags "-D_MIT_POSIX_THREADS"
} else {
    set target_cflags ""
}

if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
    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"

set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
# Drop corefile
gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
	"save a corefile" \
{
  -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
    pass "save a corefile"
    global core_supported
    set core_supported 1
  }
  -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)"
    }
}

# 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"