]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/many-completions.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / many-completions.exp
CommitLineData
213516ef 1# Copyright 2020-2023 Free Software Foundation, Inc.
99f1bc6a
AB
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# Test the case where we have so many completions that we require the
17# completions hash table within GDB to grow. Make sure that afte the
18# hash table has grown we try to add duplicate entries into the
19# hash. This checks that GDB doesn't corrupt the hash table when
20# resizing it.
21#
22# In this case we create a test with more functions than the default
23# number of entires in the completion hash table (which is 200), then
24# complete on all function names.
25#
26# GDB will add all the function names from the DWARF, and then from
27# the ELF symbol table, this ensures that we should have duplicates
28# added after resizing the table.
29
30# Create a test source file and return the name of the file. COUNT is
31# the number of dummy functions to create, this should be more than
32# the default number of entries in the completion hash table within
33# GDB (see gdb/completer.c).
34proc prepare_test_source_file { count } {
35 global gdb_test_file_name
36
37 set filename [standard_output_file "$gdb_test_file_name.c"]
38 set outfile [open $filename w]
39
40 puts $outfile "
41#define MAKE_FUNC(NUM) \\
42 void \\
43 func_ ## NUM (void) \\
44 { /* Nothing. */ }
45
46#define CALL_FUNC(NUM) \\
47 func_ ## NUM ()
48"
49
50 for { set i 0 } { $i < $count } { incr i } {
51 puts $outfile "MAKE_FUNC ([format {%03d} $i])"
52 }
53
54 puts $outfile "\nint\nmain ()\n{"
55 for { set i 0 } { $i < $count } { incr i } {
56 puts $outfile " CALL_FUNC ([format {%03d} $i]);"
57 }
58
59 puts $outfile " return 0;\n}"
60 close $outfile
61
62 return $filename
63}
64
65# Build a source file and compile it.
66set filename [prepare_test_source_file 250]
67standard_testfile $filename
68if {[prepare_for_testing "failed to prepare" "$testfile" $srcfile \
69 { debug }]} {
70 return -1
71}
72
73# Start the test.
74if {![runto_main]} {
99f1bc6a
AB
75 return
76}
77
78# We don't want to stop gathering completions too early.
79gdb_test_no_output "set max-completions unlimited"
80
81# Collect all possible completions, and check for duplictes.
82set completions [capture_command_output "complete break func_" ""]
83set duplicates 0
84foreach {-> name} [regexp -all -inline -line {^break (\w+\S*)} $completions] {
85 incr all_funcs($name)
86 if { $all_funcs($name) > 1 } {
87 incr duplicates
88 verbose -log "Duplicate entry for '$name' found"
89 }
90}
91gdb_assert { $duplicates == 0 } "duplicate check"