File: corefile-exec-context.exp

package info (click to toggle)
gdb-doc 16.3-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid, trixie
  • size: 244,264 kB
  • sloc: ansic: 2,134,731; asm: 375,582; exp: 206,875; cpp: 73,639; makefile: 70,232; sh: 26,038; python: 13,697; yacc: 11,341; ada: 7,358; xml: 6,098; perl: 5,077; pascal: 3,389; tcl: 2,986; f90: 2,764; lisp: 1,984; cs: 879; lex: 738; sed: 228; awk: 181; objc: 137; fortran: 57
file content (186 lines) | stat: -rw-r--r-- 5,561 bytes parent folder | download | duplicates (6)
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
179
180
181
182
183
184
185
186
# Copyright 2024 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/>.

# Check GDB can handle reading the full executable name and argument
# list from a core file.
#
# Currently, only Linux supports reading full executable and arguments
# from a core file.
require {is_any_target "*-*-linux*" "*-*-freebsd*"}

standard_testfile

if {[build_executable $testfile.exp $testfile $srcfile] == -1} {
    untested "failed to compile"
    return -1
}

# Linux core files can encore upto 80 characters for the command and
# arguments in the psinfo.  If BINFILE is less than 80 characters in
# length then lets try to make it longer.
set binfile_len [string length $binfile]
if { $binfile_len <= 80 } {
    set extra_len [expr 80 - $binfile_len + 1]
    set extra_str [string repeat "x" $extra_len]
    set new_binfile $binfile$extra_str
    remote_exec build "mv $binfile $new_binfile"
    set binfile $new_binfile
}

# Generate a core file, this time the inferior has no additional
# arguments.
set corefile [core_find $binfile {}]
if {$corefile == ""} {
    untested "unable to create corefile"
    return 0
}
set corefile_1 "$binfile.1.core"
remote_exec build "mv $corefile $corefile_1"

# Load the core file and confirm that the full executable name is
# seen.
clean_restart $binfile
set saw_generated_line false
gdb_test_multiple "core-file $corefile_1" "load core file no args" {
    -re "^Core was generated by `[string_to_regexp $binfile]'\\.\r\n" {
	set saw_generated_line true
	exp_continue
    }

    -re "^$gdb_prompt $" {
	gdb_assert { $saw_generated_line } $gdb_test_name
    }

    -re "^\[^\r\n\]*\r\n" {
	exp_continue
    }
}

# Generate a core file, this time pass some arguments to the inferior.
set args "aaaaa bbbbb ccccc ddddd e\\\\ e\\\\ e\\\\ e\\\\ e"
set corefile [core_find $binfile {} $args]
if {$corefile == ""} {
    untested "unable to create corefile"
    return 0
}
set corefile_2 "$binfile.2.core"
remote_exec build "mv $corefile $corefile_2"

# Load the core file and confirm that the full executable name and
# argument list are seen.
clean_restart $binfile
set saw_generated_line false
gdb_test_multiple "core-file $corefile_2" "load core file with args" {
    -re "^Core was generated by `[string_to_regexp $binfile] $args'\\.\r\n" {
	set saw_generated_line true
	exp_continue
    }

    -re "^$gdb_prompt $" {
	gdb_assert { $saw_generated_line } $gdb_test_name
    }

    -re "^\[^\r\n\]*\r\n" {
	exp_continue
    }
}

# Also, the argument list should be available through 'show args'.
gdb_test "show args" \
    "Argument list to give program being debugged when it is started is \"$args\"\\."

# Move up to 'main'.  Do it this way because we cannot know how many
# frames up 'main' actually is.
gdb_test_multiple "up" "move up to main" {
    -re -wrap "#$decimal\\s+\[^\r\n\]+ in main .*" {
	pass $gdb_test_name
    }

    -re -wrap "#$decimal\\s+\[^\r\n\]+ in .*" {
	send_gdb "up\n"
	exp_continue
    }
}

# Check that the inferior was started with the expected arguments.
gdb_test "print argc" " = 6"
gdb_test "print argv\[1\]" " = $hex \"aaaaa\""
gdb_test "print argv\[2\]" " = $hex \"bbbbb\""
gdb_test "print argv\[3\]" " = $hex \"ccccc\""
gdb_test "print argv\[4\]" " = $hex \"ddddd\""
gdb_test "print argv\[5\]" " = $hex \"e e e e e\""

# Find the name of an environment variable that is not set.
set env_var_base "GDB_TEST_ENV_VAR_"
set env_var_name ""

for { set i 0 } { $i < 10 } { incr i } {
    set tmp_name ${env_var_base}${i}
    if { ! [info exists ::env($tmp_name)] } {
	set env_var_name $tmp_name
	break
    }
}

if { $env_var_name eq "" } {
    unsupported "couldn't find suitable environment variable name"
    return -1
}

# Generate a core file with this environment variable set.
set env_var_value "TEST VALUE"
save_vars { ::env($env_var_name) } {
    setenv $env_var_name $env_var_value

    set corefile [core_find $binfile {} $args]
    if {$corefile == ""} {
	untested "unable to create corefile"
	return 0
    }
}
set corefile_3 "$binfile.2.core"
remote_exec build "mv $corefile $corefile_3"

# Restart, load the core file, and check the environment variable
# shows up.
clean_restart $binfile

# Check for environment variable VAR_NAME in the environment, its
# value should be VAR_VALUE.
proc check_for_env_var { var_name var_value } {
    set saw_var false
    gdb_test_multiple "show environment" "" {
	-re "^$var_name=$var_value\r\n" {
	    set saw_var true
	    exp_continue
	}
	-re "^\[^\r\n\]*\r\n" {
	    exp_continue
	}
	-re "^$::gdb_prompt $" {
	}
    }
    return $saw_var
}

gdb_assert { ![check_for_env_var $env_var_name $env_var_value] } \
    "environment variable is not set before core file load"

gdb_test "core-file $corefile_3" \
    "Core was generated by `[string_to_regexp $binfile] $args'\\.\r\n.*" \
    "load core file for environment test"

gdb_assert { [check_for_env_var $env_var_name $env_var_value] } \
    "environment variable is set after core file load"