aboutsummaryrefslogtreecommitdiff
path: root/gdb/frame.h
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2022-12-13 22:34:41 -0500
committerSimon Marchi <simon.marchi@efficios.com>2023-01-20 14:48:57 -0500
commit908de5e67156068f3da74c60dea6f360246a3d0b (patch)
tree2f8e8934f1212a0c69d30010270499dc3f9bcac4 /gdb/frame.h
parent93e39555dd0fcd222ce68fc7162f511056361bc7 (diff)
downloadgdb-908de5e67156068f3da74c60dea6f360246a3d0b.zip
gdb-908de5e67156068f3da74c60dea6f360246a3d0b.tar.gz
gdb-908de5e67156068f3da74c60dea6f360246a3d0b.tar.bz2
gdb: make frame_info_ptr auto-reinflatable
This is the second step of making frame_info_ptr automatic, reinflate on demand whenever trying to obtain the wrapper frame_info pointer, either through the get method or operator->. Make the reinflate method private, it is used as a convenience method in those two. Add an "is_null" method, because it is often needed to know whether the frame_info_ptr wraps an frame_info or is empty. Make m_ptr mutable, so that it's possible to reinflate const frame_info_ptr objects. Whether m_ptr is nullptr or not does not change the logical state of the object, because we re-create it on demand. I believe this is the right use case for mutable. Change-Id: Icb0552d0035e227f81eb3c121d8a9bb2f9d25794 Reviewed-By: Bruno Larsen <blarsen@redhat.com>
Diffstat (limited to 'gdb/frame.h')
-rw-r--r--gdb/frame.h45
1 files changed, 32 insertions, 13 deletions
diff --git a/gdb/frame.h b/gdb/frame.h
index 105b9fb..c4f7c12 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -275,29 +275,38 @@ public:
}
frame_info *operator-> () const
- {
- return m_ptr;
- }
+ { return this->reinflate (); }
/* Fetch the underlying pointer. Note that new code should
generally not use this -- avoid it if at all possible. */
frame_info *get () const
{
- return m_ptr;
+ if (this->is_null ())
+ return nullptr;
+
+ return this->reinflate ();
}
+ /* Return true if this object is empty (does not wrap a frame_info
+ object). */
+
+ bool is_null () const
+ {
+ return m_cached_level == this->invalid_level;
+ };
+
/* This exists for compatibility with pre-existing code that checked
a "frame_info *" using "!". */
bool operator! () const
{
- return m_ptr == nullptr;
+ return this->is_null ();
}
/* This exists for compatibility with pre-existing code that checked
a "frame_info *" like "if (ptr)". */
explicit operator bool () const
{
- return m_ptr != nullptr;
+ return !this->is_null ();
}
/* Invalidate this pointer. */
@@ -306,17 +315,18 @@ public:
m_ptr = nullptr;
}
- /* Use the cached frame_id to reinflate the pointer. */
- void reinflate ();
-
private:
/* We sometimes need to construct frame_info_ptr objects around the
sentinel_frame, which has level -1. Therefore, make the invalid frame
level value -2. */
static constexpr int invalid_level = -2;
+ /* Use the cached frame level and id to reinflate the pointer, and return
+ it. */
+ frame_info *reinflate () const;
+
/* The underlying pointer. */
- frame_info *m_ptr = nullptr;
+ mutable frame_info *m_ptr = nullptr;
/* The frame_id of the underlying pointer.
@@ -341,37 +351,46 @@ private:
static inline bool
operator== (const frame_info *self, const frame_info_ptr &other)
{
+ if (self == nullptr || other.is_null ())
+ return self == nullptr && other.is_null ();
+
return self == other.get ();
}
static inline bool
operator== (const frame_info_ptr &self, const frame_info_ptr &other)
{
+ if (self.is_null () || other.is_null ())
+ return self.is_null () && other.is_null ();
+
return self.get () == other.get ();
}
static inline bool
operator== (const frame_info_ptr &self, const frame_info *other)
{
+ if (self.is_null () || other == nullptr)
+ return self.is_null () && other == nullptr;
+
return self.get () == other;
}
static inline bool
operator!= (const frame_info *self, const frame_info_ptr &other)
{
- return self != other.get ();
+ return !(self == other);
}
static inline bool
operator!= (const frame_info_ptr &self, const frame_info_ptr &other)
{
- return self.get () != other.get ();
+ return !(self == other);
}
static inline bool
operator!= (const frame_info_ptr &self, const frame_info *other)
{
- return self.get () != other;
+ return !(self == other);
}
/* For every stopped thread, GDB tracks two frames: current and