binutils-gdb/gdb/testsuite/gdb.cp/cp-relocate.exp
Andreas Arnez b744723f57 Show line numbers in output for "info var/func/type"
The GDB commands "info variables", "info functions", and "info types" show
the appropriate list of definitions matching the given pattern.  They also
group them by source files.  But no line numbers within these source files
are shown.

The line number information is particularly useful to the user when a
simple "grep" doesn't readily point to a definition.  This is often the
case when the definition involves a macro, occurs within a namespace, or
when the identifier appears very frequently in the source file.

This patch enriches the printout of these commands by the line numbers and
adjusts affected test cases to the changed output where necessary.  The
new output looks like this:

  (gdb) i variables
  All defined variables:

  File foo.c:
  3:	const char * const foo;
  1:	int x;

The line number is followed by a colon and a tab character, which is then
followed by the symbol definition.  If no line number is available, the
tab is printed out anyhow, so definitions line up.

gdb/ChangeLog:

	* symtab.c (print_symbol_info): Precede the symbol definition by
	the line number when available.
	* NEWS: Advertise this enhancement.

gdb/doc/ChangeLog:

	* gdb.texinfo (Symbols): Mention the fact that "info
	variables/functions/types" show source files and line numbers.

gdb/testsuite/ChangeLog:

	* gdb.ada/info_types.exp: Adjust expected output to the line
	numbers now printed by "info var/func/type".
	* gdb.base/completion.exp: Likewise.
	* gdb.base/included.exp: Likewise.
	* gdb.cp/cp-relocate.exp: Likewise.
	* gdb.cp/cplusfuncs.exp: Likewise.
	* gdb.cp/namespace.exp: Likewise.
	* gdb.dwarf2/dw2-case-insensitive.exp: Likewise.
2018-04-13 19:26:05 +02:00

136 lines
4.0 KiB
Plaintext

# Copyright 2007-2018 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/>. */
# Test loading symbols from unrelocated C++ object files.
standard_testfile .cc
append binfile .o
if { [skip_cplus_tests] } { continue }
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {c++ debug}] != "" } {
untested "failed to compile"
return -1
}
proc get_func_address { func } {
global gdb_prompt hex
set rfunc [string_to_regexp $func]
gdb_test_multiple "print ${func}" "get address of ${func}" {
-re "\\\$\[0-9\]+ = \\{.*\\} (($hex) <${rfunc}.*>)\[\r\n\]+${gdb_prompt} $" {
# $1 = {int ()} 0x24 <function_bar>
# But if the function is at zero, the name may be omitted.
pass "get address of ${func}"
if { $expect_out(1,string) == "0x0" } {
return "0x0"
} else {
return $expect_out(2,string)
}
}
}
return ""
}
# Load the file as an executable; GDB should assign non-overlapping
# section offsets.
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_file_cmd ${binfile}
# Find the interesting functions. We go to a little effort to find
# the right function names here, to work around PR c++/40.
set func1_name ""
set func2_name ""
gdb_test_multiple "info functions func<.>" "info functions" {
-re "\tint (\[^\r\]*func<1>\[^\r]*);" {
set func1_name $expect_out(1,string)
exp_continue
}
-re "\tint (\[^\r\]*func<2>\[^\r]*);" {
set func2_name $expect_out(1,string)
exp_continue
}
-re "$gdb_prompt $" {
if { ${func1_name} != "" && ${func2_name} != "" } {
pass "info functions"
} else {
fail "info functions"
return -1
}
}
}
# Check that all the functions have different addresses.
set func1_addr [get_func_address "$func1_name"]
set func2_addr [get_func_address "$func2_name"]
set caller_addr [get_func_address "caller"]
if { "${func1_addr}" == "${func2_addr}"
|| "${func1_addr}" == "${func2_addr}"
|| "${func2_addr}" == "${caller_addr}" } {
fail "C++ functions have different addresses"
} else {
pass "C++ functions have different addresses"
}
# Figure out the names of the sections containing the template
# functions.
set func1_sec ""
set func2_sec ""
gdb_test_multiple "info file" "info file" {
-re "($hex) - ($hex) is (\[^\r\]*)\r" {
if { $expect_out(1,string) <= $func1_addr
&& $expect_out(2,string) > $func1_addr } {
set func1_sec $expect_out(3,string)
} elseif { $expect_out(1,string) <= $func2_addr
&& $expect_out(2,string) > $func2_addr } {
set func2_sec $expect_out(3,string)
}
exp_continue
}
-re "$gdb_prompt $" {
if { ${func1_sec} != "" && ${func2_sec} != "" } {
pass "info file"
} else {
fail "info file"
return -1
}
}
}
if { $func1_sec == $func2_sec } {
untested "cp-relocate.exp - template functions in same sections"
return -1
}
# Now start a clean GDB, for add-symbol-file tests.
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_test "add-symbol-file ${binfile} 0 -s ${func1_sec} 0x10000 -s ${func2_sec} 0x20000" \
"Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
"add-symbol-file ${testfile}.o" \
"add symbol table from file \".*${testfile}\\.o\" at.*\\(y or n\\) " \
"y"
# Make sure the function addresses were updated.
gdb_test "break *$func1_name" \
"Breakpoint $decimal at 0x1....: file .*"
gdb_test "break *$func2_name" \
"Breakpoint $decimal at 0x2....: file .*"