gdb/testsuite: fix buffer overflow in gdb.base/signed-builtin-types.exp

In commit:

  commit 9f50fe0835
  Date:   Wed Dec 7 15:55:25 2022 +0000

      gdb/testsuite: new test for recent dwarf reader issue

A new test (gdb.base/signed-builtin-types.exp) was added that made use
of 'info sources' to figure out if the debug information for a
particular object file had been fully expanded or not.  Unfortunately
some lines of the 'info sources' output can be very long, this was
observed on some systems where the debug information for the
dynamic-linker was installed, in this case, the list of source files
associated with the dynamic linker was so long it would cause expect's
internal buffer to overflow.

This commit switches from using 'info sources' to 'maint print
objfile', the output from the latter command is more compact, but
also, can be restricted to a single named object file.

With this change in place I am no longer seeing buffer overflow errors
from expect when running gdb.base/signed-builtin-types.exp.
This commit is contained in:
Andrew Burgess 2022-12-20 12:51:50 +00:00
parent f5e82fac07
commit 3a98808c16

View file

@ -21,7 +21,8 @@ standard_testfile .c -lib.c
# Compile the shared library.
set srcdso [file join $srcdir $subdir $srcfile2]
set objdso [standard_output_file lib${gdb_test_file_name}.so]
set libname "lib${gdb_test_file_name}.so"
set objdso [standard_output_file $libname]
if {[gdb_compile_shlib $srcdso $objdso {debug}] != ""} {
untested "failed to compile dso"
return -1
@ -46,46 +47,10 @@ if {[readnow]} {
# library has been fully expanded or not. Return true if the debug
# information has NOT been fully expanded (which is what we want for this
# test).
proc shared_library_debug_not_fully_expanded {} {
set library_expanded ""
gdb_test_multiple "info sources" "" {
-re "^info sources\r\n" {
exp_continue
}
-re "^(\[^\r\n\]+):\r\n\\(Full debug information has not yet been read for this file\\.\\)\r\n\r\n" {
set libname $expect_out(1,string)
if {$libname == $::objdso} {
set library_expanded "no"
}
exp_continue
}
-re "^(\[^\r\n\]+):\r\n\\(Objfile has no debug information\\.\\)\r\n\r\n" {
set libname $expect_out(1,string)
if {$libname == $::objdso} {
# For some reason the shared library has no debug
# information, this is not expected.
set library_expanded "missing debug"
}
exp_continue
}
-re "^(\[^\r\n\]+):\r\n\r\n" {
set libname $expect_out(1,string)
if {$libname == $::objdso} {
set library_expanded "yes"
}
exp_continue
}
-re "^$::gdb_prompt $" {
gdb_assert {[string equal $library_expanded "yes"] \
|| [string equal $library_expanded "no"]} \
$gdb_test_name
}
-re "^(\[^\r\n:\]*)\r\n" {
exp_continue
}
}
return [expr $library_expanded == "no"]
proc assert_shared_library_debug_not_fully_expanded {} {
gdb_test_lines "maint print objfiles $::libname" "" \
"Object file \[^\r\n\]*$::libname" \
-re-not "Symtabs:"
}
foreach_with_prefix type_name {"short" "int" "long" "char"} {
@ -93,7 +58,7 @@ foreach_with_prefix type_name {"short" "int" "long" "char"} {
with_test_prefix "before sizeof expression" {
# Check that the debug information for the shared library has
# not yet been read in.
gdb_assert { [shared_library_debug_not_fully_expanded] }
assert_shared_library_debug_not_fully_expanded
}
# Evaluate a sizeof expression for a builtin type. At one point GDB
@ -106,7 +71,7 @@ foreach_with_prefix type_name {"short" "int" "long" "char"} {
with_test_prefix "after sizeof expression" {
# Check that the debug information for the shared library has not
# yet been read in.
gdb_assert { [shared_library_debug_not_fully_expanded] }
assert_shared_library_debug_not_fully_expanded
}
}
}