/* Inline frame unwinder for GDB.
- Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2008-2018 Free Software Foundation, Inc.
This file is part of GDB.
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include "inline-frame.h"
#include "addrmap.h"
#include "block.h"
#include "frame-unwind.h"
#include "inferior.h"
+#include "regcache.h"
#include "symtab.h"
#include "vec.h"
-
-#include "gdb_assert.h"
+#include "frame.h"
+#include <algorithm>
/* We need to save a few variables for every thread stopped at the
virtual call site of an inlined function. If there was always a
keep our own list. */
struct inline_state
{
+ inline_state (ptid_t ptid_, int skipped_frames_, CORE_ADDR saved_pc_,
+ symbol *skipped_symbol_)
+ : ptid (ptid_), skipped_frames (skipped_frames_), saved_pc (saved_pc_),
+ skipped_symbol (skipped_symbol_)
+ {}
+
/* The thread this data relates to. It should be a currently
stopped thread; we assume thread IDs never change while the
thread is stopped. */
struct symbol *skipped_symbol;
};
-typedef struct inline_state inline_state_s;
-DEF_VEC_O(inline_state_s);
-
-static VEC(inline_state_s) *inline_states;
+static std::vector<inline_state> inline_states;
-/* Locate saved inlined frame state for PTID, if it exists. */
+/* Locate saved inlined frame state for PTID, if it exists
+ and is valid. */
static struct inline_state *
find_inline_frame_state (ptid_t ptid)
{
- struct inline_state *state;
- int ix;
-
- for (ix = 0; VEC_iterate (inline_state_s, inline_states, ix, state); ix++)
- {
- if (ptid_equal (state->ptid, ptid))
- return state;
- }
+ auto state_it = std::find_if (inline_states.begin (), inline_states.end (),
+ [&ptid] (const inline_state &state)
+ {
+ return ptid == state.ptid;
+ });
- return NULL;
-}
+ if (state_it == inline_states.end ())
+ return nullptr;
-/* Allocate saved inlined frame state for PTID. */
+ inline_state &state = *state_it;
+ struct regcache *regcache = get_thread_regcache (ptid);
+ CORE_ADDR current_pc = regcache_read_pc (regcache);
-static struct inline_state *
-allocate_inline_frame_state (ptid_t ptid)
-{
- struct inline_state *state;
+ if (current_pc != state.saved_pc)
+ {
+ /* PC has changed - this context is invalid. Use the
+ default behavior. */
- state = VEC_safe_push (inline_state_s, inline_states, NULL);
- memset (state, 0, sizeof (*state));
- state->ptid = ptid;
+ unordered_remove (inline_states, state_it);
+ return nullptr;
+ }
- return state;
+ return &state;
}
/* Forget about any hidden inlined functions in PTID, which is new or
void
clear_inline_frame_state (ptid_t ptid)
{
- struct inline_state *state;
- int ix;
-
- if (ptid_equal (ptid, minus_one_ptid))
+ if (ptid == minus_one_ptid)
{
- VEC_free (inline_state_s, inline_states);
+ inline_states.clear ();
return;
}
- if (ptid_is_pid (ptid))
+ if (ptid.is_pid ())
{
- VEC (inline_state_s) *new_states = NULL;
- int pid = ptid_get_pid (ptid);
- for (ix = 0; VEC_iterate (inline_state_s, inline_states, ix, state); ix++)
- if (pid != ptid_get_pid (state->ptid))
- VEC_safe_push (inline_state_s, new_states, state);
- VEC_free (inline_state_s, inline_states);
- inline_states = new_states;
+ int pid = ptid.pid ();
+ auto it = std::remove_if (inline_states.begin (), inline_states.end (),
+ [pid] (const inline_state &state)
+ {
+ return pid == state.ptid.pid ();
+ });
+
+ inline_states.erase (it, inline_states.end ());
+
return;
}
- for (ix = 0; VEC_iterate (inline_state_s, inline_states, ix, state); ix++)
- if (ptid_equal (state->ptid, ptid))
- {
- VEC_unordered_remove (inline_state_s, inline_states, ix);
- return;
- }
+ auto it = std::find_if (inline_states.begin (), inline_states.end (),
+ [&ptid] (const inline_state &state)
+ {
+ return ptid == state.ptid;
+ });
+
+ if (it != inline_states.end ())
+ unordered_remove (inline_states, it);
}
static void
/* In order to have a stable frame ID for a given inline function,
we must get the stack / special addresses from the underlying
- real frame's this_id method. So we must call get_prev_frame.
- Because we are inlined into some function, there must be previous
- frames, so this is safe - as long as we're careful not to
- create any cycles. */
- *this_id = get_frame_id (get_prev_frame (this_frame));
+ real frame's this_id method. So we must call
+ get_prev_frame_always. Because we are inlined into some
+ function, there must be previous frames, so this is safe - as
+ long as we're careful not to create any cycles. */
+ *this_id = get_frame_id (get_prev_frame_always (this_frame));
/* We need a valid frame ID, so we need to be based on a valid
frame. FSF submission NOTE: this would be a good assertion to
func = get_frame_function (this_frame);
gdb_assert (func != NULL);
(*this_id).code_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (func));
- (*this_id).inline_depth++;
+ (*this_id).artificial_depth++;
}
static struct value *
void **this_cache)
{
CORE_ADDR this_pc;
- struct block *frame_block, *cur_block;
+ const struct block *frame_block, *cur_block;
int depth;
struct frame_info *next_frame;
struct inline_state *state = find_inline_frame_state (inferior_ptid);
{
if (block_inlined_p (cur_block))
depth++;
+ else if (BLOCK_FUNCTION (cur_block) != NULL)
+ break;
cur_block = BLOCK_SUPERBLOCK (cur_block);
}
can be stepped into later). */
if (state != NULL && state->skipped_frames > 0 && next_frame == NULL)
{
- if (this_pc != state->saved_pc)
- state->skipped_frames = 0;
- else
- {
- gdb_assert (depth >= state->skipped_frames);
- depth -= state->skipped_frames;
- }
+ gdb_assert (depth >= state->skipped_frames);
+ depth -= state->skipped_frames;
}
/* If all the inlined functions here already have frames, then pass
return 1;
}
-const struct frame_unwind inline_frame_unwinder = {
+const struct frame_unwind inline_frame_unwind = {
INLINE_FRAME,
+ default_frame_unwind_stop_reason,
inline_frame_this_id,
inline_frame_prev_register,
NULL,
inline_frame_sniffer
};
-const struct frame_unwind *const inline_frame_unwind = &inline_frame_unwinder;
-
/* Return non-zero if BLOCK, an inlined function block containing PC,
has a group of contiguous instructions starting at PC (but not
before it). */
static int
-block_starting_point_at (CORE_ADDR pc, struct block *block)
+block_starting_point_at (CORE_ADDR pc, const struct block *block)
{
- struct blockvector *bv;
+ const struct blockvector *bv;
struct block *new_block;
bv = blockvector_for_pc (pc, NULL);
if (BLOCKVECTOR_MAP (bv) == NULL)
return 0;
- new_block = addrmap_find (BLOCKVECTOR_MAP (bv), pc - 1);
+ new_block = (struct block *) addrmap_find (BLOCKVECTOR_MAP (bv), pc - 1);
if (new_block == NULL)
return 1;
if (new_block == block || contained_in (new_block, block))
return 0;
- /* The immediately preceeding address belongs to a different block,
+ /* The immediately preceding address belongs to a different block,
which is not a child of this one. Treat this as an entrance into
BLOCK. */
return 1;
void
skip_inline_frames (ptid_t ptid)
{
- CORE_ADDR this_pc;
- struct block *frame_block, *cur_block;
+ const struct block *frame_block, *cur_block;
struct symbol *last_sym = NULL;
int skip_count = 0;
- struct inline_state *state;
/* This function is called right after reinitializing the frame
cache. We try not to do more unwinding than absolutely
necessary, for performance. */
- this_pc = get_frame_pc (get_current_frame ());
+ CORE_ADDR this_pc = get_frame_pc (get_current_frame ());
frame_block = block_for_pc (this_pc);
if (frame_block != NULL)
else
break;
}
+ else if (BLOCK_FUNCTION (cur_block) != NULL)
+ break;
+
cur_block = BLOCK_SUPERBLOCK (cur_block);
}
}
gdb_assert (find_inline_frame_state (ptid) == NULL);
- state = allocate_inline_frame_state (ptid);
- state->skipped_frames = skip_count;
- state->saved_pc = this_pc;
- state->skipped_symbol = last_sym;
+ inline_states.emplace_back (ptid, skip_count, this_pc, last_sym);
if (skip_count != 0)
reinit_frame_cache ();