3 Copyright (C) 2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GDB_FRAME_INFO_H
21 #define GDB_FRAME_INFO_H
23 #include "gdbsupport/intrusive_list.h"
27 extern void reinit_frame_cache ();
29 /* A wrapper for "frame_info *". frame_info objects are invalidated
30 whenever reinit_frame_cache is called. This class arranges to
31 invalidate the pointer when appropriate. This is done to help
32 detect a GDB bug that was relatively common.
34 A small amount of code must still operate on raw pointers, so a
35 "get" method is provided. However, you should normally not use
38 class frame_info_ptr
: public intrusive_list_node
<frame_info_ptr
>
41 /* Create a frame_info_ptr from a raw pointer. */
42 explicit frame_info_ptr (struct frame_info
*ptr
)
45 frame_list
.push_back (*this);
48 /* Create a null frame_info_ptr. */
51 frame_list
.push_back (*this);
54 frame_info_ptr (std::nullptr_t
)
56 frame_list
.push_back (*this);
59 frame_info_ptr (const frame_info_ptr
&other
)
62 frame_list
.push_back (*this);
65 frame_info_ptr (frame_info_ptr
&&other
)
68 other
.m_ptr
= nullptr;
69 frame_list
.push_back (*this);
74 frame_list
.erase (frame_list
.iterator_to (*this));
77 frame_info_ptr
&operator= (const frame_info_ptr
&other
)
83 frame_info_ptr
&operator= (std::nullptr_t
)
89 frame_info_ptr
&operator= (frame_info_ptr
&&other
)
92 other
.m_ptr
= nullptr;
96 frame_info
*operator-> () const
101 /* Fetch the underlying pointer. Note that new code should
102 generally not use this -- avoid it if at all possible. */
103 frame_info
*get () const
108 /* This exists for compatibility with pre-existing code that checked
109 a "frame_info *" using "!". */
110 bool operator! () const
112 return m_ptr
== nullptr;
115 /* This exists for compatibility with pre-existing code that checked
116 a "frame_info *" like "if (ptr)". */
117 explicit operator bool () const
119 return m_ptr
!= nullptr;
122 /* Invalidate this pointer. */
130 /* The underlying pointer. */
131 frame_info
*m_ptr
= nullptr;
134 /* All frame_info_ptr objects are kept on an intrusive list.
135 This keeps their construction and destruction costs
137 static intrusive_list
<frame_info_ptr
> frame_list
;
139 /* A friend so it can invalidate the pointers. */
140 friend void reinit_frame_cache ();
144 operator== (const frame_info
*self
, const frame_info_ptr
&other
)
146 return self
== other
.get ();
150 operator== (const frame_info_ptr
&self
, const frame_info_ptr
&other
)
152 return self
.get () == other
.get ();
156 operator== (const frame_info_ptr
&self
, const frame_info
*other
)
158 return self
.get () == other
;
162 operator!= (const frame_info
*self
, const frame_info_ptr
&other
)
164 return self
!= other
.get ();
168 operator!= (const frame_info_ptr
&self
, const frame_info_ptr
&other
)
170 return self
.get () != other
.get ();
174 operator!= (const frame_info_ptr
&self
, const frame_info
*other
)
176 return self
.get () != other
;
179 #endif /* GDB_FRAME_INFO_H */