annotate libstdc++-v3/libsupc++/eh_catch.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // -*- C++ -*- Exception handling routines for catching.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 // Copyright (C) 2001-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 //
kono
parents:
diff changeset
4 // This file is part of GCC.
kono
parents:
diff changeset
5 //
kono
parents:
diff changeset
6 // GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 // it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 // the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 // any later version.
kono
parents:
diff changeset
10 //
kono
parents:
diff changeset
11 // GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public License for more details.
kono
parents:
diff changeset
15 //
kono
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include <cstdlib>
kono
parents:
diff changeset
26 #include "unwind-cxx.h"
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 using namespace __cxxabiv1;
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 extern "C" void *
kono
parents:
diff changeset
31 __cxxabiv1::__cxa_get_exception_ptr(void *exc_obj_in) _GLIBCXX_NOTHROW
kono
parents:
diff changeset
32 {
kono
parents:
diff changeset
33 _Unwind_Exception *exceptionObject
kono
parents:
diff changeset
34 = reinterpret_cast <_Unwind_Exception *>(exc_obj_in);
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 return __gxx_caught_object(exceptionObject);
kono
parents:
diff changeset
37 }
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 extern "C" void *
kono
parents:
diff changeset
40 __cxxabiv1::__cxa_begin_catch (void *exc_obj_in) _GLIBCXX_NOTHROW
kono
parents:
diff changeset
41 {
kono
parents:
diff changeset
42 _Unwind_Exception *exceptionObject
kono
parents:
diff changeset
43 = reinterpret_cast <_Unwind_Exception *>(exc_obj_in);
kono
parents:
diff changeset
44 __cxa_eh_globals *globals = __cxa_get_globals ();
kono
parents:
diff changeset
45 __cxa_exception *prev = globals->caughtExceptions;
kono
parents:
diff changeset
46 __cxa_exception *header = __get_exception_header_from_ue (exceptionObject);
kono
parents:
diff changeset
47 void* objectp;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 // Foreign exceptions can't be stacked here. If the exception stack is
kono
parents:
diff changeset
50 // empty, then fine. Otherwise we really have no choice but to terminate.
kono
parents:
diff changeset
51 // Note that this use of "header" is a lie. It's fine so long as we only
kono
parents:
diff changeset
52 // examine header->unwindHeader though.
kono
parents:
diff changeset
53 if (!__is_gxx_exception_class(header->unwindHeader.exception_class))
kono
parents:
diff changeset
54 {
kono
parents:
diff changeset
55 if (prev != 0)
kono
parents:
diff changeset
56 std::terminate ();
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 // Remember for end_catch and rethrow.
kono
parents:
diff changeset
59 globals->caughtExceptions = header;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 // ??? No sensible value to return; we don't know what the
kono
parents:
diff changeset
62 // object is, much less where it is in relation to the header.
kono
parents:
diff changeset
63 return 0;
kono
parents:
diff changeset
64 }
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 int count = header->handlerCount;
kono
parents:
diff changeset
67 // Count is less than zero if this exception was rethrown from an
kono
parents:
diff changeset
68 // immediately enclosing region.
kono
parents:
diff changeset
69 if (count < 0)
kono
parents:
diff changeset
70 count = -count + 1;
kono
parents:
diff changeset
71 else
kono
parents:
diff changeset
72 count += 1;
kono
parents:
diff changeset
73 header->handlerCount = count;
kono
parents:
diff changeset
74 globals->uncaughtExceptions -= 1;
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 if (header != prev)
kono
parents:
diff changeset
77 {
kono
parents:
diff changeset
78 header->nextException = prev;
kono
parents:
diff changeset
79 globals->caughtExceptions = header;
kono
parents:
diff changeset
80 }
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 objectp = __gxx_caught_object(exceptionObject);
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 PROBE2 (catch, objectp, header->exceptionType);
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 #ifdef __ARM_EABI_UNWINDER__
kono
parents:
diff changeset
87 _Unwind_Complete(exceptionObject);
kono
parents:
diff changeset
88 #endif
kono
parents:
diff changeset
89 return objectp;
kono
parents:
diff changeset
90 }
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 extern "C" void
kono
parents:
diff changeset
94 __cxxabiv1::__cxa_end_catch ()
kono
parents:
diff changeset
95 {
kono
parents:
diff changeset
96 __cxa_eh_globals *globals = __cxa_get_globals_fast ();
kono
parents:
diff changeset
97 __cxa_exception *header = globals->caughtExceptions;
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 // A rethrow of a foreign exception will be removed from the
kono
parents:
diff changeset
100 // the exception stack immediately by __cxa_rethrow.
kono
parents:
diff changeset
101 if (!header)
kono
parents:
diff changeset
102 return;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 // A foreign exception couldn't have been stacked (see above),
kono
parents:
diff changeset
105 // so by definition processing must be complete.
kono
parents:
diff changeset
106 if (!__is_gxx_exception_class(header->unwindHeader.exception_class))
kono
parents:
diff changeset
107 {
kono
parents:
diff changeset
108 globals->caughtExceptions = 0;
kono
parents:
diff changeset
109 _Unwind_DeleteException (&header->unwindHeader);
kono
parents:
diff changeset
110 return;
kono
parents:
diff changeset
111 }
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 int count = header->handlerCount;
kono
parents:
diff changeset
114 if (count < 0)
kono
parents:
diff changeset
115 {
kono
parents:
diff changeset
116 // This exception was rethrown. Decrement the (inverted) catch
kono
parents:
diff changeset
117 // count and remove it from the chain when it reaches zero.
kono
parents:
diff changeset
118 if (++count == 0)
kono
parents:
diff changeset
119 globals->caughtExceptions = header->nextException;
kono
parents:
diff changeset
120 }
kono
parents:
diff changeset
121 else if (--count == 0)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 // Handling for this exception is complete. Destroy the object.
kono
parents:
diff changeset
124 globals->caughtExceptions = header->nextException;
kono
parents:
diff changeset
125 _Unwind_DeleteException (&header->unwindHeader);
kono
parents:
diff changeset
126 return;
kono
parents:
diff changeset
127 }
kono
parents:
diff changeset
128 else if (count < 0)
kono
parents:
diff changeset
129 // A bug in the exception handling library or compiler.
kono
parents:
diff changeset
130 std::terminate ();
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 header->handlerCount = count;
kono
parents:
diff changeset
133 }
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 bool
kono
parents:
diff changeset
137 std::uncaught_exception() throw()
kono
parents:
diff changeset
138 {
kono
parents:
diff changeset
139 #if __cpp_exceptions
kono
parents:
diff changeset
140 __cxa_eh_globals *globals = __cxa_get_globals ();
kono
parents:
diff changeset
141 return globals->uncaughtExceptions != 0;
kono
parents:
diff changeset
142 #else
kono
parents:
diff changeset
143 return false;
kono
parents:
diff changeset
144 #endif
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 int
kono
parents:
diff changeset
148 std::uncaught_exceptions() throw()
kono
parents:
diff changeset
149 {
kono
parents:
diff changeset
150 #if __cpp_exceptions
kono
parents:
diff changeset
151 __cxa_eh_globals *globals = __cxa_get_globals ();
kono
parents:
diff changeset
152 return globals->uncaughtExceptions;
kono
parents:
diff changeset
153 #else
kono
parents:
diff changeset
154 return 0;
kono
parents:
diff changeset
155 #endif
kono
parents:
diff changeset
156 }