-/* Create the previous frame using the deprecated methods
- INIT_EXTRA_INFO, and INIT_FRAME_PC. */
-
-static struct frame_info *
-legacy_get_prev_frame (struct frame_info *this_frame)
-{
- CORE_ADDR address = 0;
- struct frame_info *prev;
- int fromleaf;
-
- /* Don't frame_debug print legacy_get_prev_frame() here, just
- confuses the output. */
-
- /* Allocate the new frame.
-
- There is no reason to worry about memory leaks, should the
- remainder of the function fail. The allocated memory will be
- quickly reclaimed when the frame cache is flushed, and the `we've
- been here before' check, in get_prev_frame() will stop repeated
- memory allocation calls. */
- prev = FRAME_OBSTACK_ZALLOC (struct frame_info);
- prev->level = this_frame->level + 1;
-
- /* Do not completely wire it in to the frame chain. Some (bad) code
- in INIT_FRAME_EXTRA_INFO tries to look along frame->prev to pull
- some fancy tricks (of course such code is, by definition,
- recursive).
-
- On the other hand, methods, such as get_frame_pc() and
- get_frame_base() rely on being able to walk along the frame
- chain. Make certain that at least they work by providing that
- link. Of course things manipulating prev can't go back. */
- prev->next = this_frame;
-
- /* NOTE: cagney/2002-11-18: Should have been correctly setting the
- frame's type here, before anything else, and not last, at the
- bottom of this function. The various
- DEPRECATED_INIT_EXTRA_FRAME_INFO, DEPRECATED_INIT_FRAME_PC, and
- DEPRECATED_FRAME_INIT_SAVED_REGS methods are full of work-arounds
- that handle the frame not being correctly set from the start.
- Unfortunately those same work-arounds rely on the type defaulting
- to NORMAL_FRAME. Ulgh! The new frame code does not have this
- problem. */
- prev->type = UNKNOWN_FRAME;
-
- /* A legacy frame's ID is always computed here. Mark it as valid. */
- prev->this_id.p = 1;
-
- /* Handle sentinel frame unwind as a special case. */
- if (this_frame->level < 0)
- {
- /* Try to unwind the PC. If that doesn't work, assume we've reached
- the oldest frame and simply return. Is there a better sentinal
- value? The unwound PC value is then used to initialize the new
- previous frame's type.
-
- Note that the pc-unwind is intentionally performed before the
- frame chain. This is ok since, for old targets, both
- frame_pc_unwind() (nee, DEPRECATED_FRAME_SAVED_PC) and
- DEPRECATED_FRAME_CHAIN()) assume THIS_FRAME's data structures
- have already been initialized (using
- DEPRECATED_INIT_EXTRA_FRAME_INFO) and hence the call order
- doesn't matter.
-
- By unwinding the PC first, it becomes possible to, in the case of
- a dummy frame, avoid also unwinding the frame ID. This is
- because (well ignoring the PPC) a dummy frame can be located
- using THIS_FRAME's frame ID. */
-
- deprecated_update_frame_pc_hack (prev, frame_pc_unwind (this_frame));
- if (get_frame_pc (prev) == 0)
- {
- /* The allocated PREV_FRAME will be reclaimed when the frame
- obstack is next purged. */
- if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, NULL);
- fprintf_unfiltered (gdb_stdlog,
- " // unwound legacy PC zero }\n");
- }
- return NULL;
- }
-
- /* Set the unwind functions based on that identified PC. Ditto
- for the "type" but strongly prefer the unwinder's frame type. */
- prev->unwind = frame_unwind_find_by_frame (prev->next,
- &prev->prologue_cache);
- if (prev->unwind->type == UNKNOWN_FRAME)
- prev->type = frame_type_from_pc (get_frame_pc (prev));
- else
- prev->type = prev->unwind->type;
-
- /* Find the prev's frame's ID. */
- if (prev->type == DUMMY_FRAME
- && gdbarch_unwind_dummy_id_p (current_gdbarch))
- {
- /* When unwinding a normal frame, the stack structure is
- determined by analyzing the frame's function's code (be
- it using brute force prologue analysis, or the dwarf2
- CFI). In the case of a dummy frame, that simply isn't
- possible. The The PC is either the program entry point,
- or some random address on the stack. Trying to use that
- PC to apply standard frame ID unwind techniques is just
- asking for trouble. */
- /* Use an architecture specific method to extract the prev's
- dummy ID from the next frame. Note that this method uses
- frame_register_unwind to obtain the register values
- needed to determine the dummy frame's ID. */
- prev->this_id.value = gdbarch_unwind_dummy_id (current_gdbarch,
- this_frame);
- }
- else
- {
- /* We're unwinding a sentinel frame, the PC of which is
- pointing at a stack dummy. Fake up the dummy frame's ID
- using the same sequence as is found a traditional
- unwinder. Once all architectures supply the
- unwind_dummy_id method, this code can go away. */
- prev->this_id.value = frame_id_build (deprecated_read_fp (),
- read_pc ());
- }
-
- /* Check that the unwound ID is valid. */
- if (!frame_id_p (prev->this_id.value))
- {
- if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, NULL);
- fprintf_unfiltered (gdb_stdlog,
- " // unwound legacy ID invalid }\n");
- }
- return NULL;
- }
-
- /* Check that the new frame isn't inner to (younger, below,
- next) the old frame. If that happens the frame unwind is
- going backwards. */
- /* FIXME: cagney/2003-02-25: Ignore the sentinel frame since
- that doesn't have a valid frame ID. Should instead set the
- sentinel frame's frame ID to a `sentinel'. Leave it until
- after the switch to storing the frame ID, instead of the
- frame base, in the frame object. */
-
- /* Link it in. */
- this_frame->prev = prev;
-
- /* FIXME: cagney/2002-01-19: This call will go away. Instead of
- initializing extra info, all frames will use the frame_cache
- (passed to the unwind functions) to store additional frame
- info. Unfortunately legacy targets can't use
- legacy_get_prev_frame() to unwind the sentinel frame and,
- consequently, are forced to take this code path and rely on
- the below call to DEPRECATED_INIT_EXTRA_FRAME_INFO to
- initialize the inner-most frame. */
- if (DEPRECATED_INIT_EXTRA_FRAME_INFO_P ())
- {
- DEPRECATED_INIT_EXTRA_FRAME_INFO (0, prev);
- }
-
- if (prev->type == NORMAL_FRAME)
- prev->this_id.value.code_addr
- = get_pc_function_start (prev->this_id.value.code_addr);
-
- if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, prev);
- fprintf_unfiltered (gdb_stdlog, " } // legacy innermost frame\n");
- }
- return prev;
- }
-
- /* This code only works on normal frames. A sentinel frame, where
- the level is -1, should never reach this code. */
- gdb_assert (this_frame->level >= 0);
-
- /* On some machines it is possible to call a function without
- setting up a stack frame for it. On these machines, we
- define this macro to take two args; a frameinfo pointer
- identifying a frame and a variable to set or clear if it is
- or isn't leafless. */
-
- /* Still don't want to worry about this except on the innermost
- frame. This macro will set FROMLEAF if THIS_FRAME is a frameless
- function invocation. */
- if (this_frame->level == 0)
- /* FIXME: 2002-11-09: Frameless functions can occur anywhere in
- the frame chain, not just the inner most frame! The generic,
- per-architecture, frame code should handle this and the below
- should simply be removed. */
- fromleaf = (DEPRECATED_FRAMELESS_FUNCTION_INVOCATION_P ()
- && DEPRECATED_FRAMELESS_FUNCTION_INVOCATION (this_frame));
- else
- fromleaf = 0;
-
- if (fromleaf)
- /* A frameless inner-most frame. The `FP' (which isn't an
- architecture frame-pointer register!) of the caller is the same
- as the callee. */
- /* FIXME: 2002-11-09: There isn't any reason to special case this
- edge condition. Instead the per-architecture code should handle
- it locally. */
- /* FIXME: cagney/2003-06-16: This returns the inner most stack
- address for the previous frame, that, however, is wrong. It
- should be the inner most stack address for the previous to
- previous frame. This is because it is the previous to previous
- frame's innermost stack address that is constant through out
- the lifetime of the previous frame (trust me :-). */
- address = get_frame_base (this_frame);
- else
- {
- /* Two macros defined in tm.h specify the machine-dependent
- actions to be performed here.
-
- First, get the frame's chain-pointer.
-
- If that is zero, the frame is the outermost frame or a leaf
- called by the outermost frame. This means that if start
- calls main without a frame, we'll return 0 (which is fine
- anyway).
-
- Nope; there's a problem. This also returns when the current
- routine is a leaf of main. This is unacceptable. We move
- this to after the ffi test; I'd rather have backtraces from
- start go curfluy than have an abort called from main not show
- main. */
- if (DEPRECATED_FRAME_CHAIN_P ())
- address = DEPRECATED_FRAME_CHAIN (this_frame);
- else
- {
- /* Someone is part way through coverting an old architecture
- to the new frame code. Implement FRAME_CHAIN the way the
- new frame will. */
- /* Find PREV frame's unwinder. */
- prev->unwind = frame_unwind_find_by_frame (this_frame,
- &prev->prologue_cache);
- /* FIXME: cagney/2004-05-01: Should instead just use
- ->unwind->type. Unfortunately, legacy_get_prev_frame is
- still explicitly setting the type. Eliminate that method
- and this field can be eliminated. */
- prev->type = prev->unwind->type;
- /* Find PREV frame's ID. */
- prev->unwind->this_id (this_frame,
- &prev->prologue_cache,
- &prev->this_id.value);
- prev->this_id.p = 1;
- address = prev->this_id.value.stack_addr;
- }
-
- if (!legacy_frame_chain_valid (address, this_frame))
- {
- if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, NULL);
- fprintf_unfiltered (gdb_stdlog,
- " // legacy frame chain invalid }\n");
- }
- return NULL;
- }
- }
- if (address == 0)
- {
- if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, NULL);
- fprintf_unfiltered (gdb_stdlog,
- " // legacy frame chain NULL }\n");
- }
- return NULL;
- }
-
- /* Link in the already allocated prev frame. */
- this_frame->prev = prev;
- deprecated_update_frame_base_hack (prev, address);
-
- /* This change should not be needed, FIXME! We should determine
- whether any targets *need* DEPRECATED_INIT_FRAME_PC to happen
- after DEPRECATED_INIT_EXTRA_FRAME_INFO and come up with a simple
- way to express what goes on here.
-
- DEPRECATED_INIT_EXTRA_FRAME_INFO is called from two places:
- create_new_frame (where the PC is already set up) and here (where
- it isn't). DEPRECATED_INIT_FRAME_PC is only called from here,
- always after DEPRECATED_INIT_EXTRA_FRAME_INFO.
-
- The catch is the MIPS, where DEPRECATED_INIT_EXTRA_FRAME_INFO
- requires the PC value (which hasn't been set yet). Some other
- machines appear to require DEPRECATED_INIT_EXTRA_FRAME_INFO
- before they can do DEPRECATED_INIT_FRAME_PC. Phoo.
-
- Assuming that some machines need DEPRECATED_INIT_FRAME_PC after
- DEPRECATED_INIT_EXTRA_FRAME_INFO, one possible scheme:
-
- SETUP_INNERMOST_FRAME(): Default version is just create_new_frame
- (deprecated_read_fp ()), read_pc ()). Machines with extra frame
- info would do that (or the local equivalent) and then set the
- extra fields.
-
- SETUP_ARBITRARY_FRAME(argc, argv): Only change here is that
- create_new_frame would no longer init extra frame info;
- SETUP_ARBITRARY_FRAME would have to do that.
-
- INIT_PREV_FRAME(fromleaf, prev) Replace
- DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC.
- This should also return a flag saying whether to keep the new
- frame, or whether to discard it, because on some machines (e.g.
- mips) it is really awkward to have DEPRECATED_FRAME_CHAIN_VALID
- called BEFORE DEPRECATED_INIT_EXTRA_FRAME_INFO (there is no good
- way to get information deduced in DEPRECATED_FRAME_CHAIN_VALID
- into the extra fields of the new frame). std_frame_pc(fromleaf,
- prev)
-
- This is the default setting for INIT_PREV_FRAME. It just does
- what the default DEPRECATED_INIT_FRAME_PC does. Some machines
- will call it from INIT_PREV_FRAME (either at the beginning, the
- end, or in the middle). Some machines won't use it.
-
- kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94. */
-
- /* NOTE: cagney/2002-11-09: Just ignore the above! There is no
- reason for things to be this complicated.
-
- The trick is to assume that there is always a frame. Instead of
- special casing the inner-most frame, create a fake frame
- (containing the hardware registers) that is inner to the
- user-visible inner-most frame (...) and then unwind from that.
- That way architecture code can use the standard
- frame_XX_unwind() functions and not differentiate between the
- inner most and any other case.
-
- Since there is always a frame to unwind from, there is always
- somewhere (THIS_FRAME) to store all the info needed to construct
- a new (previous) frame without having to first create it. This
- means that the convolution below - needing to carefully order a
- frame's initialization - isn't needed.
-
- The irony here though, is that DEPRECATED_FRAME_CHAIN(), at least
- for a more up-to-date architecture, always calls
- FRAME_SAVED_PC(), and FRAME_SAVED_PC() computes the PC but
- without first needing the frame! Instead of the convolution
- below, we could have simply called FRAME_SAVED_PC() and been done
- with it! Note that FRAME_SAVED_PC() is being superseded by
- frame_pc_unwind() and that function does have somewhere to cache
- that PC value. */
-
- if (DEPRECATED_INIT_EXTRA_FRAME_INFO_P ())
- DEPRECATED_INIT_EXTRA_FRAME_INFO (fromleaf, prev);
-
- /* This entry is in the frame queue now, which is good since
- FRAME_SAVED_PC may use that queue to figure out its value (see
- tm-sparc.h). We want the PC saved in the inferior frame. */
- if (DEPRECATED_INIT_FRAME_PC_P ())
- deprecated_update_frame_pc_hack (prev,
- DEPRECATED_INIT_FRAME_PC (fromleaf,
- prev));
-
- /* If ->frame and ->pc are unchanged, we are in the process of
- getting ourselves into an infinite backtrace. Some architectures
- check this in DEPRECATED_FRAME_CHAIN or thereabouts, but it seems
- like there is no reason this can't be an architecture-independent
- check. */
- if (get_frame_base (prev) == get_frame_base (this_frame)
- && get_frame_pc (prev) == get_frame_pc (this_frame))
- {
- this_frame->prev = NULL;
- obstack_free (&frame_cache_obstack, prev);
- if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, NULL);
- fprintf_unfiltered (gdb_stdlog,
- " // legacy this.id == prev.id }\n");
- }
- return NULL;
- }
-
- /* Initialize the code used to unwind the frame PREV based on the PC
- (and probably other architectural information). The PC lets you
- check things like the debug info at that point (dwarf2cfi?) and
- use that to decide how the frame should be unwound.
-
- If there isn't a FRAME_CHAIN, the code above will have already
- done this. */
- if (prev->unwind == NULL)
- prev->unwind = frame_unwind_find_by_frame (prev->next,
- &prev->prologue_cache);
-
- /* If the unwinder provides a frame type, use it. Otherwise
- continue on to that heuristic mess. */
- if (prev->unwind->type != UNKNOWN_FRAME)
- {
- prev->type = prev->unwind->type;
- if (prev->type == NORMAL_FRAME)
- /* FIXME: cagney/2003-06-16: would get_frame_pc() be better? */
- prev->this_id.value.code_addr
- = get_pc_function_start (prev->this_id.value.code_addr);
- if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, prev);
- fprintf_unfiltered (gdb_stdlog, " } // legacy with unwound type\n");
- }
- return prev;
- }
-
- /* NOTE: cagney/2002-11-18: The code segments, found in
- create_new_frame() and get_prev_frame(), that initialize the
- frame's type is subtly different. The latter only updates ->type
- when it encounters a SIGTRAMP_FRAME or DUMMY_FRAME. This stops
- get_prev_frame() overriding the frame's type when the INIT code
- has previously set it. This is really somewhat bogus. The
- initialization, as seen in create_new_frame(), should occur
- before the INIT function has been called. */
- if (deprecated_pc_in_call_dummy (get_frame_pc (prev)))
- prev->type = DUMMY_FRAME;
-
- if (prev->type == NORMAL_FRAME)
- prev->this_id.value.code_addr
- = get_pc_function_start (prev->this_id.value.code_addr);
-
- if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, prev);
- fprintf_unfiltered (gdb_stdlog, " } // legacy with confused type\n");
- }
-
- return prev;
-}
-