mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
f71e3f86e8
I noticed this problem while preparing the initial submission for the ROCm GDB port. One particularity of this patch set is that it does not support unwinding frames, that requires support of some DWARF extensions that will come later. It was still possible to run to a breakpoint and print frame #0, though. When rebasing on top of the frame_info_ptr work, GDB started tripping on a prepare_reinflate call, making it not possible anymore to event print the frame when stopping on a breakpoint. One thing to know about frame 0 is that its id is lazily computed when something requests it through get_frame_id. See:23912acd40/gdb/frame.c (L2070-2080)
So, up to that prepare_reinflate call, frame 0's id was not computed, and prepare_reinflate, calling get_frame_id, forces it to be computed. Computing the frame id generally requires unwinding the previous frame, which with my ROCm GDB patch fails. An exception is thrown and the printing of the frame is simply abandonned. Regardless of this ROCm GDB problem (which is admittedly temporary, it will be possible to unwind with subsequent patches), we want to avoid prepare_reinflate to force the computing of the frame id, for the same reasons we lazily compute it in the first place. In addition, frame 0's id is subject to change across a frame cache reset. This is why save_selected_frame and restore_selected_frame have special handling for frame 0:23912acd40/gdb/frame.c (L1841-1863)
For this last reason, we also need to handle frame 0 specially in prepare_reinflate / reinflate. Because the frame id of frame 0 can change across a frame cache reset, we must not rely on the frame id from that frame to reinflate it. We should instead just re-fetch the current frame at that point. This patch adds a frame_info_ptr::m_cached_level field, set in frame_info_ptr::prepare_reinflate, so we can tell if a frame is frame 0. There are cases where a frame_info_ptr object wraps a sentinel frame, for which frame_relative_level returns -1, so I have chosen the value -2 to represent "invalid frame level", for when the frame_info_ptr object is empty. In frame_info_ptr::prepare_reinflate, only cache the frame id if the frame level is not 0. It's fine to cache the frame id for the sentinel frame, it will be properly handled by frame_find_by_id later. In frame_info_ptr::reinflate, if the frame level is 0, call get_current_frame to get the target's current frame. Otherwise, use frame_find_by_id just as before. This patch should not have user-visible changes with upstream GDB. But it will avoid forcing the computation of frame 0's when calling prepare_reinflate. And, well, it fixes the upcoming ROCm GDB patch series. Change-Id: I176ed7ee9317ddbb190acee8366e087e08e4d266 Reviewed-By: Bruno Larsen <blarsen@redhat.com>
66 lines
1.7 KiB
C
66 lines
1.7 KiB
C
/* Frame info pointer
|
|
|
|
Copyright (C) 2022 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
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/>. */
|
|
|
|
#include "defs.h"
|
|
|
|
#include "frame-info.h"
|
|
#include "frame.h"
|
|
|
|
/* See frame-info-ptr.h. */
|
|
|
|
intrusive_list<frame_info_ptr> frame_info_ptr::frame_list;
|
|
|
|
/* See frame-info-ptr.h. */
|
|
|
|
void
|
|
frame_info_ptr::prepare_reinflate ()
|
|
{
|
|
m_cached_level = frame_relative_level (*this);
|
|
|
|
if (m_cached_level != 0)
|
|
m_cached_id = get_frame_id (*this);
|
|
}
|
|
|
|
/* See frame-info-ptr.h. */
|
|
|
|
void
|
|
frame_info_ptr::reinflate ()
|
|
{
|
|
/* Ensure we have a valid frame level (sentinel frame or above), indicating
|
|
prepare_reinflate was called. */
|
|
gdb_assert (m_cached_level >= -1);
|
|
|
|
if (m_ptr != nullptr)
|
|
{
|
|
/* The frame_info wasn't invalidated, no need to reinflate. */
|
|
return;
|
|
}
|
|
|
|
/* Frame #0 needs special handling, see comment in select_frame. */
|
|
if (m_cached_level == 0)
|
|
m_ptr = get_current_frame ().get ();
|
|
else
|
|
{
|
|
gdb_assert (frame_id_p (m_cached_id));
|
|
m_ptr = frame_find_by_id (m_cached_id).get ();
|
|
}
|
|
|
|
gdb_assert (m_ptr != nullptr);
|
|
}
|