binutils-gdb/gdb/testsuite/gdb.cp/nsalias.exp
Maciej W. Rozycki 621661e3fa Correct invalid assumptions made by (mostly) DWARF-2 tests
Address issues triggered by the MIPS ISA bit handling change, usually in
tests that make artificial DWARF-2 records:

* gdb.cp/expand-psymtabs-cxx.exp -- this test is debugging an object file
  and assuming addresses will be 0; with the ISA bit set code addresses
  are 1 instead:

(gdb) PASS: gdb.cp/expand-psymtabs-cxx.exp: set language c++
p 'method(long)'
$1 = {void (long)} 0x1 <method(long)>
(gdb) FAIL: gdb.cp/expand-psymtabs-cxx.exp: before expand
p method
$2 = {void (long)} 0x1 <method(long)>
(gdb) FAIL: gdb.cp/expand-psymtabs-cxx.exp: force expand
p 'method(long)'
$3 = {void (long)} 0x1 <method(long)>
(gdb) FAIL: gdb.cp/expand-psymtabs-cxx.exp: after expand

  Fix by matching any hex number, there's no value AFAICT for the test
  in matching 0 exactly, and I suppose the method's offset within
  section can be non-zero for some other reasons on other targets too.

* gdb.cp/nsalias.exp -- this assumes instructions can be aligned
  arbitrarily and places code labels at odd addreses, setting the ISA
  bit and wreaking havoc:

(gdb) PASS: gdb.cp/nsalias.exp: print outer::inner::innermost::x
list outer::inner::innermost::foo
Function "outer::inner::innermost::foo" not defined.
(gdb) FAIL: gdb.cp/nsalias.exp: list outer::inner::innermost::foo
break *outer::inner::innermost::foo
No symbol "foo" in namespace "outer::inner::innermost".
(gdb) FAIL: gdb.cp/nsalias.exp: setting breakpoint at
*outer::inner::innermost::foo
delete $bpnum
No breakpoint number 6.
(gdb) FAIL: gdb.cp/nsalias.exp: (outer::inner::innermost): delete $bpnum

  -- etc., etc...  Fix by aligning labels to 4; required by many
  processors.

* gdb.dwarf2/dw2-canonicalize-type.exp, gdb.dwarf2/dw2-empty-pc-range.exp,
  gdb.dwarf2/pr11465.exp -- these assume an instruction and consequently
  a function can take as little as 1 byte, which makes it impossible to
  look up a code symbol by an address with the ISA bit set as the
  address is already beyond the end of the function:

(gdb) ptype f
No symbol "f" in current context.
(gdb) FAIL: gdb.dwarf2/dw2-canonicalize-type.exp: ptype f

(gdb) PASS: gdb.dwarf2/dw2-empty-pc-range.exp: empty range before CU load
ptype realrange
No symbol "realrange" in current context.
(gdb) FAIL: gdb.dwarf2/dw2-empty-pc-range.exp: valid range after CU load

(gdb) p N::c.C
Cannot take address of method C.
(gdb) FAIL: gdb.dwarf2/pr11465.exp: p N::c.C

  -- fix by increasing the size of the function to 4 (perhaps code in
  gdb/mips-tdep.c could look up code symbols up to twice, with and
  failing that without the ISA bit set, but it seems wrong to me to
  implement specific handling for invalid code just to satisfy test
  cases that assume too much about the target).

* gdb.dwarf2/dw2-case-insensitive.exp -- an artificial code label is
  created, but does not work because data (a `.align' pseudo-op in this
  case) follows and as a result the label has no MIPS16 or microMIPS
  annotation in the symbol table:

(gdb) PASS: gdb.dwarf2/dw2-case-insensitive.exp: set case-sensitive off
info functions fUnC_lang
All functions matching regular expression "fUnC_lang":

File file1.txt:
foo FUNC_lang(void);

Non-debugging symbols:
0x004006e0  FUNC_lang_start
(gdb) FAIL: gdb.dwarf2/dw2-case-insensitive.exp: regexp case-sensitive off

  -- fix by adding a `.insn' pseudo-op on MIPS targets; the pseudo-op
  marks data as instructions.

* gdb.dwarf2/dw2-stack-boundary.exp -- the test case enables complaints
  and assumes none will be issued beyond ones explicitly arranged by the
  test case, however overlapping sections are noticed while minimal
  symbols are looked up by `mips_adjust_dwarf2_addr' in DWARF-2 record
  processing:

(gdb) set complaints 100
(gdb) PASS: gdb.dwarf2/dw2-stack-boundary.exp: set complaints 100
file ./dw2-stack-boundary
Reading symbols from ./dw2-stack-boundary...location description stack
underflow...location description stack overflow...unexpected overlap
between:
 (A) section `.reginfo' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x18)
 (B) section `*COM*' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x0).
Will ignore section B...unexpected overlap between:
 (A) section `.reginfo' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x18)
 (B) section `*UND*' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x0).
Will ignore section B...unexpected overlap between:
 (A) section `.reginfo' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x18)
 (B) section `*ABS*' from `.../gdb.dwarf2/dw2-stack-boundary' [0x0, 0x0).
Will ignore section B...done.

(gdb) FAIL: gdb.dwarf2/dw2-stack-boundary.exp: check partial symtab errors

  -- fix by ignoring any extra noise as long as what we look for is
  found.

	* gdb.cp/expand-psymtabs-cxx.exp: Accept any address of
	`method(long)', not just 0x0.
	* gdb.cp/nsalias.exp: Align code labels to 4.
	* gdb.dwarf2/dw2-canonicalize-type.S (main): Expand to 4-bytes.
	* gdb.dwarf2/dw2-empty-pc-range.S (main): Likewise.
	* gdb.dwarf2/pr11465.S (_ZN1N1cE): Likewise.
	* gdb.dwarf2/dw2-case-insensitive.c (START_INSNS): New macro.
	(cu_text_start, FUNC_lang_start): Use `START_INSNS'.
	* gdb.dwarf2/dw2-stack-boundary.exp: Accept noise in complaints.
2014-12-04 00:06:10 +00:00

323 lines
7.0 KiB
Plaintext

# Copyright 2013-2014 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 namespace aliases.
# PRs c++/7935, c++/10541
load_lib dwarf.exp
if {![dwarf2_support]} {
return 0
}
if {[skip_cplus_tests]} {
continue
}
standard_testfile .cc nsalias-dw.S
# Make the DWARF used for the test. This is necessary to work
# around compiler issues. Not all versions of gcc output the
# correct debuginfo we need.
#
# This should create the equivalent DWARF to:
#
# namespace outer
# {
# namespace inner
# {
# namespace innermost
# {
# const int x = 2;
# int foo (void) { return x; }
# }
#
# namespace Innermost = innermost;
#
# const int x = 1;
# int foo (void) { return x + Innermost::foo (); }
# }
#
# namespace Inner = inner;
#
# const int x = 0;
# int foo (void) { return x + Inner::foo (); }
# }
#
# namespace Outer = outer;
# namespace oi = Outer::Inner;
set asm_file [standard_output_file $srcfile2]
Dwarf::assemble $asm_file {
cu {} {
compile_unit {{language @DW_LANG_C_plus_plus}} {
declare_labels int_label outer_label inner_label innermost_label
declare_labels im_foo_label i_foo_label o_foo_label
declare_labels OuterInner_label oi1_label oi2_label
int_label: base_type {
{name int}
{encoding @DW_ATE_signed}
{byte_size 4 DW_FORM_sdata}
}
outer_label: DW_TAG_namespace {
{name outer}
} {
inner_label: DW_TAG_namespace {
{name inner}
} {
innermost_label: DW_TAG_namespace {
{name innermost}
} {
DW_TAG_variable {
{name x}
{type :$int_label}
{const_value 2 DW_FORM_data1}
}
im_foo_label: DW_TAG_subprogram {
{name foo}
{external 1}
{declaration 1}
}
}
imported_declaration {
{name Innermost}
{import :$innermost_label}
}
DW_TAG_variable {
{name x}
{type :$int_label}
{const_value 1 DW_FORM_data1}
}
i_foo_label: subprogram {
{name foo}
{external 1}
{declaration 1}
}
}
OuterInner_label: imported_declaration {
{name Inner}
{import :$inner_label}
}
DW_TAG_variable {
{name x}
{type :$int_label}
{const_value 0 DW_FORM_data1}
}
o_foo_label: subprogram {
{name foo}
{external 1}
{declaration 1}
}
}
imported_declaration {
{name Outer}
{import :$outer_label}
}
oi1_label: imported_declaration {
{name oi1}
{import :$OuterInner_label}
}
oi2_label: imported_declaration {
{name oi2}
{import :$oi1_label}
}
imported_declaration {
{name oi3}
{import :$oi2_label}
}
subprogram {
{specification :$im_foo_label}
{low_pc 0x4 DW_FORM_addr}
{high_pc 0x7 DW_FORM_addr}
}
subprogram {
{specification :$i_foo_label}
{low_pc 0x8 DW_FORM_addr}
{high_pc 0xb DW_FORM_addr}
}
subprogram {
{specification :$o_foo_label}
{low_pc 0xc DW_FORM_addr}
{high_pc 0xf DW_FORM_addr}
}
}
}
}
if {[gdb_compile $srcdir/$subdir/$srcfile ${binfile}1.o \
object {c++ debug}] != ""} {
return -1
}
if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
return -1
}
if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
$binfile executable {c++}] != ""} {
return -1
}
clean_restart $testfile
# A procedure to run various tests on aliased namespaces.
proc do_alias_tests {ns {real ""} {x ""}} {
# The "real" namespace is simply NS in all lowercase.
if {$real == ""} {
set real [string tolower $ns]
}
# The value of `x' is the number of '::' in NS.
if {$x == ""} {
set x [expr {[llength [split $ns ":"]] / 2}]
}
# Test "whatis"
gdb_test "whatis $ns" "type = $real"
# Test "ptype"
gdb_test "ptype $ns" "type = namespace $real"
# Print 'x'
send_log "expecting x = $x\n"
gdb_test "print ${ns}::x" " = $x"
# Attempt to list the function.
gdb_test_no_output "list ${ns}::foo"
# Attempt to break on the start of the function.
gdb_breakpoint "*${ns}::foo"
# And then erase it
with_test_prefix "($ns)" {
gdb_test_no_output "delete \$bpnum"
}
}
# This is a list of all the permutations to be tested. For troubleshooting
# purposes, this list is explicitly enumerated.
set permutations {}
lappend permutations "outer"
lappend permutations "Outer"
lappend permutations "outer::inner"
lappend permutations "Outer::inner"
lappend permutations "outer::Inner"
lappend permutations "Outer::Inner"
lappend permutations "outer::inner::innermost"
lappend permutations "outer::inner::Innermost"
lappend permutations "outer::Inner::innermost"
lappend permutations "outer::Inner::Innermost"
lappend permutations "Outer::inner::innermost"
lappend permutations "Outer::inner::Innermost"
lappend permutations "Outer::Inner::innermost"
lappend permutations "Outer::Inner::Innermost"
foreach p $permutations {
do_alias_tests $p
}
# Test recursively imported aliases.
foreach ns {"oi1" "oi2" "oi3"} {
do_alias_tests $ns "outer::inner" 1
do_alias_tests "${ns}::innermost" "outer::inner::innermost" 2
do_alias_tests "${ns}::Innermost" "outer::inner::innermost" 2
}
# Generate another objfile with nested imported declarations.
set imports {
declare_labels n0_label
n0_label: DW_TAG_namespace {
{name n0}
} {
DW_TAG_variable {
{name x}
{type :$int_label}
{const_value 3 DW_FORM_data1}
}
}
declare_labels n0_import
n0_import: imported_declaration {
{name N0}
{import :$n0_label}
}
}
for {set i 1} {$i <= 100} {incr i} {
append imports [format "
declare_labels n%d_import
n%d_import: imported_declaration {
{name N%d}
{import :\$n%d_import}
}" $i $i $i [expr {$i - 1}]]
}
standard_testfile .cc nsalias-r-dw.S
set asm_file [standard_output_file $srcfile2]
set the_dwarf [format {
cu {} {
compile_unit {{language @DW_LANG_C_plus_plus}} {
declare_labels int_label n0_label
int_label: base_type {
{name int}
{encoding @DW_ATE_signed}
{byte_size 4 DW_FORM_sdata}
}
%s
}
}
} $imports]
Dwarf::assemble $asm_file $the_dwarf
if {[gdb_compile $asm_file ${binfile}3.o object {nodebug}] != ""} {
return -1
}
if {[gdb_compile [list ${binfile}1.o ${binfile}3.o] \
${binfile}-r executable {c++}] != ""} {
return -1
}
clean_restart ${testfile}-r
gdb_test_no_output "set complaints 1"
gdb_test "print N100::x" \
".* has too many recursively imported declarations.*" \
"compaint for too many recursively imported declarations"