xref: /dflybsd-src/contrib/gdb-7/gdb/sentinel-frame.c (revision 5796c8dc12c637f18a1740c26afd8d40ffa9b719)
1*5796c8dcSSimon Schubert /* Code dealing with register stack frames, for GDB, the GNU debugger.
2*5796c8dcSSimon Schubert 
3*5796c8dcSSimon Schubert    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4*5796c8dcSSimon Schubert    1996, 1997, 1998, 1999, 2000, 2001, 2002, 2007, 2008, 2009
5*5796c8dcSSimon Schubert    Free Software Foundation, Inc.
6*5796c8dcSSimon Schubert 
7*5796c8dcSSimon Schubert    This file is part of GDB.
8*5796c8dcSSimon Schubert 
9*5796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
10*5796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
11*5796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
12*5796c8dcSSimon Schubert    (at your option) any later version.
13*5796c8dcSSimon Schubert 
14*5796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
15*5796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
16*5796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*5796c8dcSSimon Schubert    GNU General Public License for more details.
18*5796c8dcSSimon Schubert 
19*5796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
20*5796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21*5796c8dcSSimon Schubert 
22*5796c8dcSSimon Schubert 
23*5796c8dcSSimon Schubert #include "defs.h"
24*5796c8dcSSimon Schubert #include "regcache.h"
25*5796c8dcSSimon Schubert #include "sentinel-frame.h"
26*5796c8dcSSimon Schubert #include "inferior.h"
27*5796c8dcSSimon Schubert #include "frame-unwind.h"
28*5796c8dcSSimon Schubert 
29*5796c8dcSSimon Schubert struct frame_unwind_cache
30*5796c8dcSSimon Schubert {
31*5796c8dcSSimon Schubert   struct regcache *regcache;
32*5796c8dcSSimon Schubert };
33*5796c8dcSSimon Schubert 
34*5796c8dcSSimon Schubert void *
35*5796c8dcSSimon Schubert sentinel_frame_cache (struct regcache *regcache)
36*5796c8dcSSimon Schubert {
37*5796c8dcSSimon Schubert   struct frame_unwind_cache *cache =
38*5796c8dcSSimon Schubert     FRAME_OBSTACK_ZALLOC (struct frame_unwind_cache);
39*5796c8dcSSimon Schubert   cache->regcache = regcache;
40*5796c8dcSSimon Schubert   return cache;
41*5796c8dcSSimon Schubert }
42*5796c8dcSSimon Schubert 
43*5796c8dcSSimon Schubert /* Here the register value is taken direct from the register cache.  */
44*5796c8dcSSimon Schubert 
45*5796c8dcSSimon Schubert static struct value *
46*5796c8dcSSimon Schubert sentinel_frame_prev_register (struct frame_info *this_frame,
47*5796c8dcSSimon Schubert 			      void **this_prologue_cache,
48*5796c8dcSSimon Schubert 			      int regnum)
49*5796c8dcSSimon Schubert {
50*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (this_frame);
51*5796c8dcSSimon Schubert   struct frame_unwind_cache *cache = *this_prologue_cache;
52*5796c8dcSSimon Schubert   struct value *value;
53*5796c8dcSSimon Schubert 
54*5796c8dcSSimon Schubert   /* Return the actual value.  */
55*5796c8dcSSimon Schubert   value = allocate_value (register_type (gdbarch, regnum));
56*5796c8dcSSimon Schubert   VALUE_LVAL (value) = lval_register;
57*5796c8dcSSimon Schubert   VALUE_REGNUM (value) = regnum;
58*5796c8dcSSimon Schubert   VALUE_FRAME_ID (value) = get_frame_id (this_frame);
59*5796c8dcSSimon Schubert 
60*5796c8dcSSimon Schubert   /* Use the regcache_cooked_read() method so that it, on the fly,
61*5796c8dcSSimon Schubert      constructs either a raw or pseudo register from the raw
62*5796c8dcSSimon Schubert      register cache.  */
63*5796c8dcSSimon Schubert   regcache_cooked_read (cache->regcache, regnum, value_contents_raw (value));
64*5796c8dcSSimon Schubert 
65*5796c8dcSSimon Schubert   return value;
66*5796c8dcSSimon Schubert }
67*5796c8dcSSimon Schubert 
68*5796c8dcSSimon Schubert static void
69*5796c8dcSSimon Schubert sentinel_frame_this_id (struct frame_info *this_frame,
70*5796c8dcSSimon Schubert 			void **this_prologue_cache,
71*5796c8dcSSimon Schubert 			struct frame_id *this_id)
72*5796c8dcSSimon Schubert {
73*5796c8dcSSimon Schubert   /* The sentinel frame is used as a starting point for creating the
74*5796c8dcSSimon Schubert      previous (inner most) frame.  That frame's THIS_ID method will be
75*5796c8dcSSimon Schubert      called to determine the inner most frame's ID.  Not this one.  */
76*5796c8dcSSimon Schubert   internal_error (__FILE__, __LINE__, _("sentinel_frame_this_id called"));
77*5796c8dcSSimon Schubert }
78*5796c8dcSSimon Schubert 
79*5796c8dcSSimon Schubert static struct gdbarch *
80*5796c8dcSSimon Schubert sentinel_frame_prev_arch (struct frame_info *this_frame,
81*5796c8dcSSimon Schubert 			  void **this_prologue_cache)
82*5796c8dcSSimon Schubert {
83*5796c8dcSSimon Schubert   struct frame_unwind_cache *cache = *this_prologue_cache;
84*5796c8dcSSimon Schubert   return get_regcache_arch (cache->regcache);
85*5796c8dcSSimon Schubert }
86*5796c8dcSSimon Schubert 
87*5796c8dcSSimon Schubert const struct frame_unwind sentinel_frame_unwinder =
88*5796c8dcSSimon Schubert {
89*5796c8dcSSimon Schubert   SENTINEL_FRAME,
90*5796c8dcSSimon Schubert   sentinel_frame_this_id,
91*5796c8dcSSimon Schubert   sentinel_frame_prev_register,
92*5796c8dcSSimon Schubert   NULL,
93*5796c8dcSSimon Schubert   NULL,
94*5796c8dcSSimon Schubert   NULL,
95*5796c8dcSSimon Schubert   sentinel_frame_prev_arch,
96*5796c8dcSSimon Schubert };
97*5796c8dcSSimon Schubert 
98*5796c8dcSSimon Schubert const struct frame_unwind *const sentinel_frame_unwind = &sentinel_frame_unwinder;
99