Skip to content

Commit b442930

Browse files
committed
[gdb/testsuite] Extend gdb.base/index-cache.exp
The test-case gdb.base/index-cache.exp uses only one source file, which contains main. While doing "file $exec", in set_initial_language a symbol lookup of "main" is done, causing the symtab containing main to be expanded. Handling of main is special, and a future optimization may skip the lookup and expansion. Reliably exercise: - the lookup of main, expanding the symtab containing main, by doing "ptype main", and - the lookup of another symbol, expanding a symtab not containing main, by: - adding another source file containing function foo, and - doing "ptype foo". This triggered a segfault with target board native-extended-gdbserver, filed as PR symtab/30712, but that seems to be fixed by a previous commit in this series. Tested on x86_64-linux. Approved-By: Tom Tromey <[email protected]> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30712
1 parent edb157d commit b442930

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* This testcase is part of GDB, the GNU debugger.
2+
3+
Copyright 2023 Free Software Foundation, Inc.
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
17+
18+
extern int foo (void);
19+
20+
int
21+
foo (void)
22+
{
23+
return 0;
24+
}

gdb/testsuite/gdb.base/index-cache.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
You should have received a copy of the GNU General Public License
1616
along with this program. If not, see <http://www.gnu.org/licenses/>. */
1717

18+
extern int foo (void);
19+
1820
int
19-
main ()
21+
main (void)
2022
{
21-
return 0;
23+
return foo ();
2224
}
2325

gdb/testsuite/gdb.base/index-cache.exp

+20-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
# This test checks that the index-cache feature generates the expected files at
1717
# the expected location.
1818

19-
standard_testfile
19+
standard_testfile .c -2.c
2020

21-
if { [build_executable "failed to prepare" $testfile $srcfile \
21+
if { [build_executable "failed to prepare" $testfile [list $srcfile $srcfile2] \
2222
{debug ldflags=-Wl,--build-id}] } {
2323
return
2424
}
@@ -147,6 +147,12 @@ proc_with_prefix test_cache_disabled { cache_dir test_prefix } {
147147
gdb_assert "$nfiles_created == 0" "no files were created"
148148

149149
check_cache_stats 0 0
150+
151+
# Trigger expansion of symtab containing main, if not already done.
152+
gdb_test "ptype main" "^type = int \\(void\\)"
153+
154+
# Trigger expansion of symtab not containing main.
155+
gdb_test "ptype foo" "^type = int \\(void\\)"
150156
}
151157
}
152158
}
@@ -192,6 +198,12 @@ proc_with_prefix test_cache_enabled_miss { cache_dir } {
192198
} else {
193199
check_cache_stats 0 0
194200
}
201+
202+
# Trigger expansion of symtab containing main, if not already done.
203+
gdb_test "ptype main" "^type = int \\(void\\)"
204+
205+
# Trigger expansion of symtab not containing main.
206+
gdb_test "ptype foo" "^type = int \\(void\\)"
195207
}
196208
}
197209

@@ -221,6 +233,12 @@ proc_with_prefix test_cache_enabled_hit { cache_dir } {
221233
} else {
222234
check_cache_stats 0 0
223235
}
236+
237+
# Trigger expansion of symtab containing main, if not already done.
238+
gdb_test "ptype main" "^type = int \\(void\\)"
239+
240+
# Trigger expansion of symtab not containing main.
241+
gdb_test "ptype foo" "^type = int \\(void\\)"
224242
}
225243
}
226244

0 commit comments

Comments
 (0)