xref: /dflybsd-src/contrib/gdb-7/gdb/sentinel-frame.c (revision c50c785cb49e9377ca78104c5540c7b33f768771)
15796c8dcSSimon Schubert /* Code dealing with register stack frames, for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
35796c8dcSSimon Schubert    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4*c50c785cSJohn Marino    1996, 1997, 1998, 1999, 2000, 2001, 2002, 2007, 2008, 2009, 2010, 2011
55796c8dcSSimon Schubert    Free Software Foundation, Inc.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This file is part of GDB.
85796c8dcSSimon Schubert 
95796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
105796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
115796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
125796c8dcSSimon Schubert    (at your option) any later version.
135796c8dcSSimon Schubert 
145796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
155796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
165796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
175796c8dcSSimon Schubert    GNU General Public License for more details.
185796c8dcSSimon Schubert 
195796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
205796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
215796c8dcSSimon Schubert 
225796c8dcSSimon Schubert 
235796c8dcSSimon Schubert #include "defs.h"
245796c8dcSSimon Schubert #include "regcache.h"
255796c8dcSSimon Schubert #include "sentinel-frame.h"
265796c8dcSSimon Schubert #include "inferior.h"
275796c8dcSSimon Schubert #include "frame-unwind.h"
285796c8dcSSimon Schubert 
295796c8dcSSimon Schubert struct frame_unwind_cache
305796c8dcSSimon Schubert {
315796c8dcSSimon Schubert   struct regcache *regcache;
325796c8dcSSimon Schubert };
335796c8dcSSimon Schubert 
345796c8dcSSimon Schubert void *
355796c8dcSSimon Schubert sentinel_frame_cache (struct regcache *regcache)
365796c8dcSSimon Schubert {
375796c8dcSSimon Schubert   struct frame_unwind_cache *cache =
385796c8dcSSimon Schubert     FRAME_OBSTACK_ZALLOC (struct frame_unwind_cache);
39cf7f2e2dSJohn Marino 
405796c8dcSSimon Schubert   cache->regcache = regcache;
415796c8dcSSimon Schubert   return cache;
425796c8dcSSimon Schubert }
435796c8dcSSimon Schubert 
445796c8dcSSimon Schubert /* Here the register value is taken direct from the register cache.  */
455796c8dcSSimon Schubert 
465796c8dcSSimon Schubert static struct value *
475796c8dcSSimon Schubert sentinel_frame_prev_register (struct frame_info *this_frame,
485796c8dcSSimon Schubert 			      void **this_prologue_cache,
495796c8dcSSimon Schubert 			      int regnum)
505796c8dcSSimon Schubert {
515796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (this_frame);
525796c8dcSSimon Schubert   struct frame_unwind_cache *cache = *this_prologue_cache;
535796c8dcSSimon Schubert   struct value *value;
54*c50c785cSJohn Marino   struct type *regtype = register_type (gdbarch, regnum);
555796c8dcSSimon Schubert 
565796c8dcSSimon Schubert   /* Return the actual value.  */
57*c50c785cSJohn Marino   value = allocate_value (regtype);
585796c8dcSSimon Schubert   VALUE_LVAL (value) = lval_register;
595796c8dcSSimon Schubert   VALUE_REGNUM (value) = regnum;
605796c8dcSSimon Schubert   VALUE_FRAME_ID (value) = get_frame_id (this_frame);
615796c8dcSSimon Schubert 
625796c8dcSSimon Schubert   /* Use the regcache_cooked_read() method so that it, on the fly,
635796c8dcSSimon Schubert      constructs either a raw or pseudo register from the raw
645796c8dcSSimon Schubert      register cache.  */
65*c50c785cSJohn Marino   if (regcache_cooked_read (cache->regcache,
66*c50c785cSJohn Marino 			    regnum,
67*c50c785cSJohn Marino 			    value_contents_raw (value)) == REG_UNAVAILABLE)
68*c50c785cSJohn Marino     mark_value_bytes_unavailable (value, 0, TYPE_LENGTH (regtype));
695796c8dcSSimon Schubert 
705796c8dcSSimon Schubert   return value;
715796c8dcSSimon Schubert }
725796c8dcSSimon Schubert 
735796c8dcSSimon Schubert static void
745796c8dcSSimon Schubert sentinel_frame_this_id (struct frame_info *this_frame,
755796c8dcSSimon Schubert 			void **this_prologue_cache,
765796c8dcSSimon Schubert 			struct frame_id *this_id)
775796c8dcSSimon Schubert {
785796c8dcSSimon Schubert   /* The sentinel frame is used as a starting point for creating the
795796c8dcSSimon Schubert      previous (inner most) frame.  That frame's THIS_ID method will be
805796c8dcSSimon Schubert      called to determine the inner most frame's ID.  Not this one.  */
815796c8dcSSimon Schubert   internal_error (__FILE__, __LINE__, _("sentinel_frame_this_id called"));
825796c8dcSSimon Schubert }
835796c8dcSSimon Schubert 
845796c8dcSSimon Schubert static struct gdbarch *
855796c8dcSSimon Schubert sentinel_frame_prev_arch (struct frame_info *this_frame,
865796c8dcSSimon Schubert 			  void **this_prologue_cache)
875796c8dcSSimon Schubert {
885796c8dcSSimon Schubert   struct frame_unwind_cache *cache = *this_prologue_cache;
89cf7f2e2dSJohn Marino 
905796c8dcSSimon Schubert   return get_regcache_arch (cache->regcache);
915796c8dcSSimon Schubert }
925796c8dcSSimon Schubert 
93*c50c785cSJohn Marino const struct frame_unwind sentinel_frame_unwind =
945796c8dcSSimon Schubert {
955796c8dcSSimon Schubert   SENTINEL_FRAME,
96*c50c785cSJohn Marino   default_frame_unwind_stop_reason,
975796c8dcSSimon Schubert   sentinel_frame_this_id,
985796c8dcSSimon Schubert   sentinel_frame_prev_register,
995796c8dcSSimon Schubert   NULL,
1005796c8dcSSimon Schubert   NULL,
1015796c8dcSSimon Schubert   NULL,
1025796c8dcSSimon Schubert   sentinel_frame_prev_arch,
1035796c8dcSSimon Schubert };
104