Skip to content

Commit

Permalink
[gdb/testsuite] Extend gdb.base/index-cache.exp
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vries committed Aug 4, 2023
1 parent edb157d commit b442930
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
24 changes: 24 additions & 0 deletions gdb/testsuite/gdb.base/index-cache-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This testcase is part of GDB, the GNU debugger.
Copyright 2023 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/>. */

extern int foo (void);

int
foo (void)
{
return 0;
}
6 changes: 4 additions & 2 deletions gdb/testsuite/gdb.base/index-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

extern int foo (void);

int
main ()
main (void)
{
return 0;
return foo ();
}

22 changes: 20 additions & 2 deletions gdb/testsuite/gdb.base/index-cache.exp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
# This test checks that the index-cache feature generates the expected files at
# the expected location.

standard_testfile
standard_testfile .c -2.c

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

check_cache_stats 0 0

# Trigger expansion of symtab containing main, if not already done.
gdb_test "ptype main" "^type = int \\(void\\)"

# Trigger expansion of symtab not containing main.
gdb_test "ptype foo" "^type = int \\(void\\)"
}
}
}
Expand Down Expand Up @@ -192,6 +198,12 @@ proc_with_prefix test_cache_enabled_miss { cache_dir } {
} else {
check_cache_stats 0 0
}

# Trigger expansion of symtab containing main, if not already done.
gdb_test "ptype main" "^type = int \\(void\\)"

# Trigger expansion of symtab not containing main.
gdb_test "ptype foo" "^type = int \\(void\\)"
}
}

Expand Down Expand Up @@ -221,6 +233,12 @@ proc_with_prefix test_cache_enabled_hit { cache_dir } {
} else {
check_cache_stats 0 0
}

# Trigger expansion of symtab containing main, if not already done.
gdb_test "ptype main" "^type = int \\(void\\)"

# Trigger expansion of symtab not containing main.
gdb_test "ptype foo" "^type = int \\(void\\)"
}
}

Expand Down

0 comments on commit b442930

Please sign in to comment.