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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
|
# Copyright 2019-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/>.
# Make it easier to run the 'info modules' command (using
# GDBInfoModules), and the 'info module ...' commands (using
# GDBInfoModuleContents) and process the output.
#
# The difficulty we run into is that different versions of gFortran
# include different helper modules which show up in the results. The
# procedures in this library help process those parts of the output we
# actually want to check, while ignoring those parts that we don't
# care about.
#
# For each namespace GDBInfoModules and GDBInfoModuleContents, there's
# a run_command proc, use this to run a command and capture the
# output. Then make calls to check_header, check_entry, and
# check_no_entry to ensure the output was as expected.
namespace eval GDBInfoSymbols {
# A string that is the header printed by GDB immediately after the
# 'info [modules|types|functions|variables]' command has been issued.
variable _header
# A list of entries extracted from the output of the command.
# Each entry is a filename, a line number, and the rest of the
# text describing the entry. If an entry has no line number then
# it is replaced with the text NONE.
variable _entries
# The string that is the complete last command run.
variable _last_command
# Add a new entry to the _entries list.
proc _add_entry { filename lineno text } {
variable _entries
set entry [list $filename $lineno $text]
lappend _entries $entry
}
# Run the 'info modules' command, passing ARGS as extra arguments
# to the command. Process the output storing the results within
# the variables in this namespace.
#
# The results of any previous call to run_command are discarded
# when this is called.
proc run_command { cmd { testname "" } } {
global gdb_prompt
variable _header
variable _entries
variable _last_command
if {![regexp -- "^info (modules|types|variables|functions)" $cmd]} {
perror "invalid command"
}
set _header ""
set _entries [list]
set _last_command $cmd
if { $testname == "" } {
set testname $cmd
}
send_gdb "$cmd\n"
gdb_expect {
-re "^$cmd\r\n" {
# Match the original command echoed back to us.
}
timeout {
fail "$testname (timeout)"
return 0
}
}
gdb_expect {
-re "^\r\n" {
# Found the blank line after the header, we're done
# parsing the header now.
}
-re "^\[ \t]*(\[^\r\n\]+)\r\n" {
set str $expect_out(1,string)
if { $_header == "" } {
set _header $str
} else {
set _header "$_header $str"
}
exp_continue
}
timeout {
fail "$testname (timeout)"
return 0
}
}
set current_file ""
gdb_expect {
-re "^File (\[^\r\n\]+):\r\n" {
set current_file $expect_out(1,string)
exp_continue
}
-re "^(\[0-9\]+):\[ \t\]+(\[^\r\n\]+)\r\n" {
set lineno $expect_out(1,string)
set text $expect_out(2,string)
if { $current_file == "" } {
fail "$testname (missing filename)"
return 0
}
_add_entry $current_file $lineno $text
exp_continue
}
-re "^\[ \t\]+(\[^\r\n\]+)\r\n" {
set lineno "NONE"
set text $expect_out(1,string)
if { $current_file == "" } {
fail "$testname (missing filename)"
return 0
}
_add_entry $current_file $lineno $text
exp_continue
}
-re "^\r\n" {
exp_continue
}
-re "^$gdb_prompt $" {
# All done.
}
timeout {
fail "$testname (timeout)"
return 0
}
}
pass $testname
return 1
}
# Check that the header held in _header matches PATTERN. Use
# TESTNAME as the name of the test, or create a suitable default
# test name based on the last command.
proc check_header { pattern { testname "" } } {
variable _header
variable _last_command
if { $testname == "" } {
set testname "$_last_command: check header"
}
gdb_assert {[regexp -- $pattern $_header]} $testname
}
# Call check_entry_1 with OPTIONAL == 0.
proc check_entry { filename lineno text { testname "" } } {
check_entry_1 $filename $lineno $text 0 $testname
}
# Call check_entry_1 with OPTIONAL == 1.
proc check_optional_entry { filename lineno text { testname "" } } {
check_entry_1 $filename $lineno $text 1 $testname
}
# Check that we have an entry in _entries matching FILENAME,
# LINENO, and TEXT. If LINENO is the empty string it is replaced
# with the string NONE in order to match a similarly missing line
# number in the output of the command.
#
# TESTNAME is the name of the test, or a default will be created
# based on the last command run and the arguments passed here.
#
# If a matching entry is found then it is removed from the
# _entries list, this allows us to check for duplicates using the
# check_no_entry call.
proc check_entry_1 { filename lineno text optional testname } {
variable _entries
variable _last_command
if { $testname == "" } {
set testname \
"$_last_command: check for entry '$filename', '$lineno', '$text'"
}
if { $lineno == "" } {
set lineno "NONE"
}
set new_entries [list]
set found_match 0
foreach entry $_entries {
if {!$found_match} {
set f [lindex $entry 0]
set l [lindex $entry 1]
set t [lindex $entry 2]
if { [regexp -- $filename $f] \
&& [regexp -- $lineno $l] \
&& [regexp -- $text $t] } {
set found_match 1
} else {
lappend new_entries $entry
}
} else {
lappend new_entries $entry
}
}
set _entries $new_entries
if { $optional && ! $found_match } {
unsupported $testname
} else {
gdb_assert { $found_match } $testname
}
}
# Check that there is no entry in the _entries list matching
# FILENAME, LINENO, and TEXT. The LINENO and TEXT are optional,
# and will be replaced with '.*' if missing.
#
# If LINENO is the empty string then it will be replaced with the
# string NONE in order to match against missing line numbers in
# the output of the command.
#
# TESTNAME is the name of the test, or a default will be built
# from the last command run and the arguments passed here.
#
# This can be used after a call to check_entry to ensure that
# there are no further matches for a particular file in the
# output.
proc check_no_entry { filename { lineno ".*" } { text ".*" } \
{ testname "" } } {
variable _entries
variable _last_command
if { $testname == "" } {
set testname \
"$_last_command: check no matches for '$filename', '$lineno', and '$text'"
}
if { $lineno == "" } {
set lineno "NONE"
}
foreach entry $_entries {
set f [lindex $entry 0]
set l [lindex $entry 1]
set t [lindex $entry 2]
if { [regexp -- $filename $f] \
&& [regexp -- $lineno $l] \
&& [regexp -- $text $t] } {
fail $testname
}
}
pass $testname
}
}
namespace eval GDBInfoModuleSymbols {
# A string that is the header printed by GDB immediately after the
# 'info modules (variables|functions)' command has been issued.
variable _header
# A list of entries extracted from the output of the command.
# Each entry is a filename, a module name, a line number, and the
# rest of the text describing the entry. If an entry has no line
# number then it is replaced with the text NONE.
variable _entries
# The string that is the complete last command run.
variable _last_command
# Add a new entry to the _entries list.
proc _add_entry { filename module lineno text } {
variable _entries
set entry [list $filename $module $lineno $text]
lappend _entries $entry
}
# Run the 'info module ....' command, passing ARGS as extra
# arguments to the command. Process the output storing the
# results within the variables in this namespace.
#
# The results of any previous call to run_command are discarded
# when this is called.
proc run_command { cmd { testname "" } } {
global gdb_prompt
variable _header
variable _entries
variable _last_command
if {![regexp -- "^info module (variables|functions)" $cmd]} {
perror "invalid command: '$cmd'"
}
set _header ""
set _entries [list]
set _last_command $cmd
if { $testname == "" } {
set testname $cmd
}
send_gdb "$cmd\n"
gdb_expect {
-re "^$cmd\r\n" {
# Match the original command echoed back to us.
}
timeout {
fail "$testname (timeout)"
return 0
}
}
gdb_expect {
-re "^\r\n" {
# Found the blank line after the header, we're done
# parsing the header now.
}
-re "^\[ \t\]*(\[^\r\n\]+)\r\n" {
set str $expect_out(1,string)
if { $_header == "" } {
set _header $str
} else {
set _header "$_header $str"
}
exp_continue
}
timeout {
fail "$testname (timeout)"
return 0
}
}
set current_module ""
set current_file ""
gdb_expect {
-re "^Module \"(\[^\"\]+)\":\r\n" {
set current_module $expect_out(1,string)
exp_continue
}
-re "^File (\[^\r\n\]+):\r\n" {
if { $current_module == "" } {
fail "$testname (missing module)"
return 0
}
set current_file $expect_out(1,string)
exp_continue
}
-re "^(\[0-9\]+):\[ \t\]+(\[^\r\n\]+)\r\n" {
set lineno $expect_out(1,string)
set text $expect_out(2,string)
if { $current_module == "" } {
fail "$testname (missing module)"
return 0
}
if { $current_file == "" } {
fail "$testname (missing filename)"
return 0
}
_add_entry $current_file $current_module \
$lineno $text
exp_continue
}
-re "^\[ \t\]+(\[^\r\n\]+)\r\n" {
set lineno "NONE"
set text $expect_out(1,string)
if { $current_module == "" } {
fail "$testname (missing module)"
return 0
}
if { $current_file == "" } {
fail "$testname (missing filename)"
return 0
}
_add_entry $current_file $current_module \
$lineno $text
exp_continue
}
-re "^\r\n" {
exp_continue
}
-re "^$gdb_prompt $" {
# All done.
}
timeout {
fail "$testname (timeout)"
return 0
}
}
pass $testname
return 1
}
# Check that the header held in _header matches PATTERN. Use
# TESTNAME as the name of the test, or create a suitable default
# test name based on the last command.
proc check_header { pattern { testname "" } } {
variable _header
variable _last_command
if { $testname == "" } {
set testname "$_last_command: check header"
}
gdb_assert {[regexp -- $pattern $_header]} $testname
}
# Check that we have an entry in _entries matching FILENAME,
# MODULE, LINENO, and TEXT. If LINENO is the empty string it is
# replaced with the string NONE in order to match a similarly
# missing line number in the output of the command.
#
# TESTNAME is the name of the test, or a default will be created
# based on the last command run and the arguments passed here.
#
# If a matching entry is found then it is removed from the
# _entries list, this allows us to check for duplicates using the
# check_no_entry call.
#
# If OPTIONAL, don't generate a FAIL for a mismatch, but use UNSUPPORTED
# instead.
proc check_entry_1 { filename module lineno text optional testname } {
variable _entries
variable _last_command
if { $testname == "" } {
set testname \
"$_last_command: check for entry '$filename', '$lineno', '$text'"
}
if { $lineno == "" } {
set lineno "NONE"
}
set new_entries [list]
set found_match 0
foreach entry $_entries {
if {!$found_match} {
set f [lindex $entry 0]
set m [lindex $entry 1]
set l [lindex $entry 2]
set t [lindex $entry 3]
if { [regexp -- $filename $f] \
&& [regexp -- $module $m] \
&& [regexp -- $lineno $l] \
&& [regexp -- $text $t] } {
set found_match 1
} else {
lappend new_entries $entry
}
} else {
lappend new_entries $entry
}
}
set _entries $new_entries
if { $optional && ! $found_match } {
unsupported $testname
} else {
gdb_assert { $found_match } $testname
}
}
# Call check_entry_1 with OPTIONAL == 0.
proc check_entry { filename module lineno text { testname "" } } {
check_entry_1 $filename $module $lineno $text 0 $testname
}
# Call check_entry_1 with OPTIONAL == 1.
proc check_optional_entry { filename module lineno text { testname "" } } {
check_entry_1 $filename $module $lineno $text 1 $testname
}
# Check that there is no entry in the _entries list matching
# FILENAME, MODULE, LINENO, and TEXT. The LINENO and TEXT are
# optional, and will be replaced with '.*' if missing.
#
# If LINENO is the empty string then it will be replaced with the
# string NONE in order to match against missing line numbers in
# the output of the command.
#
# TESTNAME is the name of the test, or a default will be built
# from the last command run and the arguments passed here.
#
# This can be used after a call to check_entry to ensure that
# there are no further matches for a particular file in the
# output.
proc check_no_entry { filename module { lineno ".*" } \
{ text ".*" } { testname "" } } {
variable _entries
variable _last_command
if { $testname == "" } {
set testname \
"$_last_command: check no matches for '$filename', '$lineno', and '$text'"
}
if { $lineno == "" } {
set lineno "NONE"
}
foreach entry $_entries {
set f [lindex $entry 0]
set m [lindex $entry 1]
set l [lindex $entry 2]
set t [lindex $entry 3]
if { [regexp -- $filename $f] \
&& [regexp -- $module $m] \
&& [regexp -- $lineno $l] \
&& [regexp -- $text $t] } {
fail $testname
}
}
pass $testname
}
}
|