1130803Smarcel/* Code dealing with register stack frames, for GDB, the GNU debugger.
2130803Smarcel
3130803Smarcel   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4130803Smarcel   1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
5130803Smarcel   Foundation, Inc.
6130803Smarcel
7130803Smarcel   This file is part of GDB.
8130803Smarcel
9130803Smarcel   This program is free software; you can redistribute it and/or modify
10130803Smarcel   it under the terms of the GNU General Public License as published by
11130803Smarcel   the Free Software Foundation; either version 2 of the License, or
12130803Smarcel   (at your option) any later version.
13130803Smarcel
14130803Smarcel   This program is distributed in the hope that it will be useful,
15130803Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
16130803Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17130803Smarcel   GNU General Public License for more details.
18130803Smarcel
19130803Smarcel   You should have received a copy of the GNU General Public License
20130803Smarcel   along with this program; if not, write to the Free Software
21130803Smarcel   Foundation, Inc., 59 Temple Place - Suite 330,
22130803Smarcel   Boston, MA 02111-1307, USA.  */
23130803Smarcel
24130803Smarcel
25130803Smarcel#include "defs.h"
26130803Smarcel#include "regcache.h"
27130803Smarcel#include "sentinel-frame.h"
28130803Smarcel#include "inferior.h"
29130803Smarcel#include "frame-unwind.h"
30130803Smarcel
31130803Smarcelstruct frame_unwind_cache
32130803Smarcel{
33130803Smarcel  struct regcache *regcache;
34130803Smarcel};
35130803Smarcel
36130803Smarcelvoid *
37130803Smarcelsentinel_frame_cache (struct regcache *regcache)
38130803Smarcel{
39130803Smarcel  struct frame_unwind_cache *cache =
40130803Smarcel    FRAME_OBSTACK_ZALLOC (struct frame_unwind_cache);
41130803Smarcel  cache->regcache = regcache;
42130803Smarcel  return cache;
43130803Smarcel}
44130803Smarcel
45130803Smarcel/* Here the register value is taken direct from the register cache.  */
46130803Smarcel
47130803Smarcelstatic void
48130803Smarcelsentinel_frame_prev_register (struct frame_info *next_frame,
49130803Smarcel			      void **this_prologue_cache,
50130803Smarcel			      int regnum, int *optimized,
51130803Smarcel			      enum lval_type *lvalp, CORE_ADDR *addrp,
52130803Smarcel			      int *realnum, void *bufferp)
53130803Smarcel{
54130803Smarcel  struct frame_unwind_cache *cache = *this_prologue_cache;
55130803Smarcel  /* Describe the register's location.  A reg-frame maps all registers
56130803Smarcel     onto the corresponding hardware register.  */
57130803Smarcel  *optimized = 0;
58130803Smarcel  *lvalp = lval_register;
59130803Smarcel  *addrp = register_offset_hack (current_gdbarch, regnum);
60130803Smarcel  *realnum = regnum;
61130803Smarcel
62130803Smarcel  /* If needed, find and return the value of the register.  */
63130803Smarcel  if (bufferp != NULL)
64130803Smarcel    {
65130803Smarcel      /* Return the actual value.  */
66130803Smarcel      /* Use the regcache_cooked_read() method so that it, on the fly,
67130803Smarcel         constructs either a raw or pseudo register from the raw
68130803Smarcel         register cache.  */
69130803Smarcel      regcache_cooked_read (cache->regcache, regnum, bufferp);
70130803Smarcel    }
71130803Smarcel}
72130803Smarcel
73130803Smarcelstatic void
74130803Smarcelsentinel_frame_this_id (struct frame_info *next_frame,
75130803Smarcel			void **this_prologue_cache,
76130803Smarcel			struct frame_id *this_id)
77130803Smarcel{
78130803Smarcel  /* The sentinel frame is used as a starting point for creating the
79130803Smarcel     previous (inner most) frame.  That frame's THIS_ID method will be
80130803Smarcel     called to determine the inner most frame's ID.  Not this one.  */
81130803Smarcel  internal_error (__FILE__, __LINE__, "sentinel_frame_this_id called");
82130803Smarcel}
83130803Smarcel
84130803Smarcelconst struct frame_unwind sentinel_frame_unwinder =
85130803Smarcel{
86130803Smarcel  /* Should the sentinel frame be given a special type?  */
87130803Smarcel  NORMAL_FRAME,
88130803Smarcel  sentinel_frame_this_id,
89130803Smarcel  sentinel_frame_prev_register
90130803Smarcel};
91130803Smarcel
92130803Smarcelconst struct frame_unwind *const sentinel_frame_unwind = &sentinel_frame_unwinder;
93