xref: /dflybsd-src/contrib/gdb-7/gdb/sentinel-frame.c (revision cf7f2e2d389e8012d562650bd94d7e433f449d6e)
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*cf7f2e2dSJohn Marino    1996, 1997, 1998, 1999, 2000, 2001, 2002, 2007, 2008, 2009, 2010
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);
39*cf7f2e2dSJohn 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;
545796c8dcSSimon Schubert 
555796c8dcSSimon Schubert   /* Return the actual value.  */
565796c8dcSSimon Schubert   value = allocate_value (register_type (gdbarch, regnum));
575796c8dcSSimon Schubert   VALUE_LVAL (value) = lval_register;
585796c8dcSSimon Schubert   VALUE_REGNUM (value) = regnum;
595796c8dcSSimon Schubert   VALUE_FRAME_ID (value) = get_frame_id (this_frame);
605796c8dcSSimon Schubert 
615796c8dcSSimon Schubert   /* Use the regcache_cooked_read() method so that it, on the fly,
625796c8dcSSimon Schubert      constructs either a raw or pseudo register from the raw
635796c8dcSSimon Schubert      register cache.  */
645796c8dcSSimon Schubert   regcache_cooked_read (cache->regcache, regnum, value_contents_raw (value));
655796c8dcSSimon Schubert 
665796c8dcSSimon Schubert   return value;
675796c8dcSSimon Schubert }
685796c8dcSSimon Schubert 
695796c8dcSSimon Schubert static void
705796c8dcSSimon Schubert sentinel_frame_this_id (struct frame_info *this_frame,
715796c8dcSSimon Schubert 			void **this_prologue_cache,
725796c8dcSSimon Schubert 			struct frame_id *this_id)
735796c8dcSSimon Schubert {
745796c8dcSSimon Schubert   /* The sentinel frame is used as a starting point for creating the
755796c8dcSSimon Schubert      previous (inner most) frame.  That frame's THIS_ID method will be
765796c8dcSSimon Schubert      called to determine the inner most frame's ID.  Not this one.  */
775796c8dcSSimon Schubert   internal_error (__FILE__, __LINE__, _("sentinel_frame_this_id called"));
785796c8dcSSimon Schubert }
795796c8dcSSimon Schubert 
805796c8dcSSimon Schubert static struct gdbarch *
815796c8dcSSimon Schubert sentinel_frame_prev_arch (struct frame_info *this_frame,
825796c8dcSSimon Schubert 			  void **this_prologue_cache)
835796c8dcSSimon Schubert {
845796c8dcSSimon Schubert   struct frame_unwind_cache *cache = *this_prologue_cache;
85*cf7f2e2dSJohn Marino 
865796c8dcSSimon Schubert   return get_regcache_arch (cache->regcache);
875796c8dcSSimon Schubert }
885796c8dcSSimon Schubert 
895796c8dcSSimon Schubert const struct frame_unwind sentinel_frame_unwinder =
905796c8dcSSimon Schubert {
915796c8dcSSimon Schubert   SENTINEL_FRAME,
925796c8dcSSimon Schubert   sentinel_frame_this_id,
935796c8dcSSimon Schubert   sentinel_frame_prev_register,
945796c8dcSSimon Schubert   NULL,
955796c8dcSSimon Schubert   NULL,
965796c8dcSSimon Schubert   NULL,
975796c8dcSSimon Schubert   sentinel_frame_prev_arch,
985796c8dcSSimon Schubert };
995796c8dcSSimon Schubert 
1005796c8dcSSimon Schubert const struct frame_unwind *const sentinel_frame_unwind = &sentinel_frame_unwinder;
101