OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc3/] [gdb/] [testsuite/] [gdb.cp/] [hang.exp] - Blame information for rev 579

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
#   Copyright 2002, 2004, 2007, 2008, 2009, 2010
2
#   Free Software Foundation, Inc.
3
 
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program.  If not, see .
16
 
17
if $tracelevel then {
18
        strace $tracelevel
19
}
20
 
21
 
22
if { [skip_cplus_tests] } { continue }
23
 
24
set testfile hang
25
set binfile ${objdir}/${subdir}/${testfile}
26
 
27
foreach file {hang1 hang2 hang3} {
28
    if {[gdb_compile "${srcdir}/${subdir}/${file}.cc" "${file}.o" object {c++ debug}] != ""} {
29
        untested hang.exp
30
        return -1
31
    }
32
}
33
 
34
if {[gdb_compile "hang1.o hang2.o hang3.o" ${binfile} executable {c++ debug}] != "" } {
35
     untested hang.exp
36
     return -1
37
}
38
 
39
 
40
gdb_exit
41
gdb_start
42
gdb_reinitialize_dir $srcdir/$subdir
43
gdb_load ${binfile}
44
 
45
 
46
# As of May 1, 2002, GDB hangs trying to read the debug info for the
47
# `hang2.o' compilation unit from the executable `hang', when compiled
48
# by g++ 2.96 with STABS debugging info.  Here's what's going on, as
49
# best as I can tell.
50
#
51
# The definition of `struct A' in `hang.H' refers to `struct B' as an
52
# incomplete type.  The stabs declare type number (1,3) to be a cross-
53
# reference type, `xsB:'.
54
#
55
# The definition of `struct C' contains a nested definition for
56
# `struct B' --- or more properly, `struct C::B'.  However, the stabs
57
# fail to qualify the structure tag: it just looks like a definition
58
# for `struct B'.  I think this is a compiler bug, but perhaps GCC
59
# doesn't emit qualified names for a reason.
60
#
61
# `hang.H' gets #included by both `hang1.C' and `hang2.C'.  So the
62
# stabs for `struct A', the incomplete `struct B', and `struct C'
63
# appear in both hang1.o's and hang2.o's stabs.
64
#
65
# When those two files are linked together, since hang2.o appears
66
# later in the command line, its #inclusion of `hang.H' gets replaced
67
# with an N_EXCL stab, referring back to hang1.o's stabs for the
68
# header file.
69
#
70
# When GDB builds psymtabs for the executable hang, it notes that
71
# hang2.o's stabs contain an N_EXCL referring to a header that appears
72
# in full in hang1.o's stabs.  So hang2.o's psymtab lists a dependency
73
# on hang1.o's psymtab.
74
#
75
# When the user types the command `print var_in_b', GDB scans the
76
# psymtabs for a symbol by that name, and decides to read full symbols
77
# for `hang2.o'.
78
#
79
# Since `hang2.o''s psymtab lists `hang1.o' as a dependency, GDB first
80
# reads `hang1.o''s symbols.  When GDB sees `(1,3)=xsB:', it creates a
81
# type object for `struct B', sets its TYPE_FLAG_STUB flag, and
82
# records it as type number `(1,3)'.
83
#
84
# When GDB finds the definition of `struct C::B', since the stabs
85
# don't indicate that the type is nested within C, it treats it as
86
# a definition of `struct B'.
87
#
88
# When GDB is finished reading `hang1.o''s symbols, it calls
89
# `cleanup_undefined_types'.  This function mistakes the definition of
90
# `struct C::B' for a definition for `struct B', and overwrites the
91
# incomplete type object for the real `struct B', using `memcpy'.  Now
92
# stabs type number `(1,3)' refers to this (incorrect) complete type.
93
# Furthermore, the `memcpy' simply copies the original's `cv_type'
94
# field to the target, giving the target a corrupt `cv_type' ring: the
95
# chain does not point back to the target type.
96
#
97
# Having satisfied `hang2.o''s psymtab's dependencies, GDB begins to
98
# read `hang2.o''s symbols.  These contain the true definition for
99
# `struct B', which refers to type number `(1,3)' as the type it's
100
# defining.  GDB looks up type `(1,3)', and finds the (incorrect)
101
# complete type established by the call to `cleanup_undefined_types'
102
# above.  However, it doesn't notice that the type is already defined,
103
# and passes it to `read_struct_type', which then writes the new
104
# definition's size, field list, etc. into the type object which
105
# already has those fields initialized.  Adding insult to injury,
106
# `read_struct_type' then calls `finish_cv_type'; since the `memcpy'
107
# in `cleanup_undefined_types' corrupted the target type's `cv_type'
108
# ring, `finish_cv_type' enters an infinite loop.
109
 
110
# This checks that GDB recognizes when a structure is about to be
111
# overwritten, and refuses, with a complaint.
112
gdb_test "print var_in_b" " = 1729" "doesn't overwrite struct type"
113
 
114
# This checks that cleanup_undefined_types doesn't create corrupt
115
# cv_type chains.  Note that var_in_hang3 does need to be declared in
116
# a separate compilation unit, whose psymtab depends on hang1.o's
117
# psymtab.  Otherwise, GDB won't call cleanup_undefined_types (as it
118
# finishes hang1.o's symbols) before it calls make_cv_type (while
119
# reading hang3.o's symbols).
120
#
121
# The bug only happens when you compile with -gstabs+; Otherwise, GCC
122
# won't include the `const' qualifier on `const_B_ptr' in `hang3.o''s
123
# STABS, so GDB won't try to create a const variant of the smashed
124
# struct type, and get caught by the corrupted cv_type chain.
125
gdb_test "print var_in_hang3" " = 42" "doesn't corrupt cv_type chain"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.