xref: /dflybsd-src/contrib/gdb-7/gdb/trad-frame.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Traditional frame unwind support, for GDB the GNU Debugger.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 2003-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "frame.h"
225796c8dcSSimon Schubert #include "trad-frame.h"
235796c8dcSSimon Schubert #include "regcache.h"
245796c8dcSSimon Schubert #include "frame-unwind.h"
255796c8dcSSimon Schubert #include "value.h"
265796c8dcSSimon Schubert 
275796c8dcSSimon Schubert struct trad_frame_cache
285796c8dcSSimon Schubert {
295796c8dcSSimon Schubert   struct frame_info *this_frame;
305796c8dcSSimon Schubert   CORE_ADDR this_base;
315796c8dcSSimon Schubert   struct trad_frame_saved_reg *prev_regs;
325796c8dcSSimon Schubert   struct frame_id this_id;
335796c8dcSSimon Schubert };
345796c8dcSSimon Schubert 
355796c8dcSSimon Schubert struct trad_frame_cache *
trad_frame_cache_zalloc(struct frame_info * this_frame)365796c8dcSSimon Schubert trad_frame_cache_zalloc (struct frame_info *this_frame)
375796c8dcSSimon Schubert {
385796c8dcSSimon Schubert   struct trad_frame_cache *this_trad_cache;
395796c8dcSSimon Schubert 
405796c8dcSSimon Schubert   this_trad_cache = FRAME_OBSTACK_ZALLOC (struct trad_frame_cache);
415796c8dcSSimon Schubert   this_trad_cache->prev_regs = trad_frame_alloc_saved_regs (this_frame);
425796c8dcSSimon Schubert   this_trad_cache->this_frame = this_frame;
435796c8dcSSimon Schubert   return this_trad_cache;
445796c8dcSSimon Schubert }
455796c8dcSSimon Schubert 
465796c8dcSSimon Schubert /* A traditional frame is unwound by analysing the function prologue
475796c8dcSSimon Schubert    and using the information gathered to track registers.  For
485796c8dcSSimon Schubert    non-optimized frames, the technique is reliable (just need to check
495796c8dcSSimon Schubert    for all potential instruction sequences).  */
505796c8dcSSimon Schubert 
515796c8dcSSimon Schubert struct trad_frame_saved_reg *
trad_frame_alloc_saved_regs(struct frame_info * this_frame)525796c8dcSSimon Schubert trad_frame_alloc_saved_regs (struct frame_info *this_frame)
535796c8dcSSimon Schubert {
545796c8dcSSimon Schubert   int regnum;
555796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (this_frame);
565796c8dcSSimon Schubert   int numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
575796c8dcSSimon Schubert   struct trad_frame_saved_reg *this_saved_regs
585796c8dcSSimon Schubert     = FRAME_OBSTACK_CALLOC (numregs, struct trad_frame_saved_reg);
59cf7f2e2dSJohn Marino 
605796c8dcSSimon Schubert   for (regnum = 0; regnum < numregs; regnum++)
615796c8dcSSimon Schubert     {
625796c8dcSSimon Schubert       this_saved_regs[regnum].realreg = regnum;
635796c8dcSSimon Schubert       this_saved_regs[regnum].addr = -1;
645796c8dcSSimon Schubert     }
655796c8dcSSimon Schubert   return this_saved_regs;
665796c8dcSSimon Schubert }
675796c8dcSSimon Schubert 
68c50c785cSJohn Marino enum { TF_REG_VALUE = -1, TF_REG_UNKNOWN = -2 };
695796c8dcSSimon Schubert 
705796c8dcSSimon Schubert int
trad_frame_value_p(struct trad_frame_saved_reg this_saved_regs[],int regnum)715796c8dcSSimon Schubert trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
725796c8dcSSimon Schubert {
73c50c785cSJohn Marino   return (this_saved_regs[regnum].realreg == TF_REG_VALUE);
745796c8dcSSimon Schubert }
755796c8dcSSimon Schubert 
765796c8dcSSimon Schubert int
trad_frame_addr_p(struct trad_frame_saved_reg this_saved_regs[],int regnum)775796c8dcSSimon Schubert trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
785796c8dcSSimon Schubert {
795796c8dcSSimon Schubert   return (this_saved_regs[regnum].realreg >= 0
805796c8dcSSimon Schubert 	  && this_saved_regs[regnum].addr != -1);
815796c8dcSSimon Schubert }
825796c8dcSSimon Schubert 
835796c8dcSSimon Schubert int
trad_frame_realreg_p(struct trad_frame_saved_reg this_saved_regs[],int regnum)845796c8dcSSimon Schubert trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs[],
855796c8dcSSimon Schubert 		      int regnum)
865796c8dcSSimon Schubert {
875796c8dcSSimon Schubert   return (this_saved_regs[regnum].realreg >= 0
885796c8dcSSimon Schubert 	  && this_saved_regs[regnum].addr == -1);
895796c8dcSSimon Schubert }
905796c8dcSSimon Schubert 
915796c8dcSSimon Schubert void
trad_frame_set_value(struct trad_frame_saved_reg this_saved_regs[],int regnum,LONGEST val)925796c8dcSSimon Schubert trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
935796c8dcSSimon Schubert 		      int regnum, LONGEST val)
945796c8dcSSimon Schubert {
955796c8dcSSimon Schubert   /* Make the REALREG invalid, indicating that the ADDR contains the
965796c8dcSSimon Schubert      register's value.  */
97c50c785cSJohn Marino   this_saved_regs[regnum].realreg = TF_REG_VALUE;
985796c8dcSSimon Schubert   this_saved_regs[regnum].addr = val;
995796c8dcSSimon Schubert }
1005796c8dcSSimon Schubert 
1015796c8dcSSimon Schubert void
trad_frame_set_reg_value(struct trad_frame_cache * this_trad_cache,int regnum,LONGEST val)1025796c8dcSSimon Schubert trad_frame_set_reg_value (struct trad_frame_cache *this_trad_cache,
1035796c8dcSSimon Schubert 			  int regnum, LONGEST val)
1045796c8dcSSimon Schubert {
1055796c8dcSSimon Schubert   /* External interface for users of trad_frame_cache
1065796c8dcSSimon Schubert      (who cannot access the prev_regs object directly).  */
1075796c8dcSSimon Schubert   trad_frame_set_value (this_trad_cache->prev_regs, regnum, val);
1085796c8dcSSimon Schubert }
1095796c8dcSSimon Schubert 
1105796c8dcSSimon Schubert void
trad_frame_set_reg_realreg(struct trad_frame_cache * this_trad_cache,int regnum,int realreg)1115796c8dcSSimon Schubert trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache,
1125796c8dcSSimon Schubert 			    int regnum, int realreg)
1135796c8dcSSimon Schubert {
1145796c8dcSSimon Schubert   this_trad_cache->prev_regs[regnum].realreg = realreg;
1155796c8dcSSimon Schubert   this_trad_cache->prev_regs[regnum].addr = -1;
1165796c8dcSSimon Schubert }
1175796c8dcSSimon Schubert 
1185796c8dcSSimon Schubert void
trad_frame_set_reg_addr(struct trad_frame_cache * this_trad_cache,int regnum,CORE_ADDR addr)1195796c8dcSSimon Schubert trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache,
1205796c8dcSSimon Schubert 			 int regnum, CORE_ADDR addr)
1215796c8dcSSimon Schubert {
1225796c8dcSSimon Schubert   this_trad_cache->prev_regs[regnum].addr = addr;
1235796c8dcSSimon Schubert }
1245796c8dcSSimon Schubert 
1255796c8dcSSimon Schubert void
trad_frame_set_unknown(struct trad_frame_saved_reg this_saved_regs[],int regnum)1265796c8dcSSimon Schubert trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[],
1275796c8dcSSimon Schubert 			int regnum)
1285796c8dcSSimon Schubert {
1295796c8dcSSimon Schubert   /* Make the REALREG invalid, indicating that the value is not known.  */
130c50c785cSJohn Marino   this_saved_regs[regnum].realreg = TF_REG_UNKNOWN;
1315796c8dcSSimon Schubert   this_saved_regs[regnum].addr = -1;
1325796c8dcSSimon Schubert }
1335796c8dcSSimon Schubert 
1345796c8dcSSimon Schubert struct value *
trad_frame_get_prev_register(struct frame_info * this_frame,struct trad_frame_saved_reg this_saved_regs[],int regnum)1355796c8dcSSimon Schubert trad_frame_get_prev_register (struct frame_info *this_frame,
1365796c8dcSSimon Schubert 			      struct trad_frame_saved_reg this_saved_regs[],
1375796c8dcSSimon Schubert 			      int regnum)
1385796c8dcSSimon Schubert {
1395796c8dcSSimon Schubert   if (trad_frame_addr_p (this_saved_regs, regnum))
1405796c8dcSSimon Schubert     /* The register was saved in memory.  */
1415796c8dcSSimon Schubert     return frame_unwind_got_memory (this_frame, regnum,
1425796c8dcSSimon Schubert 				    this_saved_regs[regnum].addr);
1435796c8dcSSimon Schubert   else if (trad_frame_realreg_p (this_saved_regs, regnum))
1445796c8dcSSimon Schubert     return frame_unwind_got_register (this_frame, regnum,
1455796c8dcSSimon Schubert 				      this_saved_regs[regnum].realreg);
1465796c8dcSSimon Schubert   else if (trad_frame_value_p (this_saved_regs, regnum))
1475796c8dcSSimon Schubert     /* The register's value is available.  */
1485796c8dcSSimon Schubert     return frame_unwind_got_constant (this_frame, regnum,
1495796c8dcSSimon Schubert 				      this_saved_regs[regnum].addr);
1505796c8dcSSimon Schubert   else
1515796c8dcSSimon Schubert     return frame_unwind_got_optimized (this_frame, regnum);
1525796c8dcSSimon Schubert }
1535796c8dcSSimon Schubert 
1545796c8dcSSimon Schubert struct value *
trad_frame_get_register(struct trad_frame_cache * this_trad_cache,struct frame_info * this_frame,int regnum)1555796c8dcSSimon Schubert trad_frame_get_register (struct trad_frame_cache *this_trad_cache,
1565796c8dcSSimon Schubert 			 struct frame_info *this_frame,
1575796c8dcSSimon Schubert 			 int regnum)
1585796c8dcSSimon Schubert {
1595796c8dcSSimon Schubert   return trad_frame_get_prev_register (this_frame, this_trad_cache->prev_regs,
1605796c8dcSSimon Schubert 				       regnum);
1615796c8dcSSimon Schubert }
1625796c8dcSSimon Schubert 
1635796c8dcSSimon Schubert void
trad_frame_set_id(struct trad_frame_cache * this_trad_cache,struct frame_id this_id)1645796c8dcSSimon Schubert trad_frame_set_id (struct trad_frame_cache *this_trad_cache,
1655796c8dcSSimon Schubert 		   struct frame_id this_id)
1665796c8dcSSimon Schubert {
1675796c8dcSSimon Schubert   this_trad_cache->this_id = this_id;
1685796c8dcSSimon Schubert }
1695796c8dcSSimon Schubert 
1705796c8dcSSimon Schubert void
trad_frame_get_id(struct trad_frame_cache * this_trad_cache,struct frame_id * this_id)1715796c8dcSSimon Schubert trad_frame_get_id (struct trad_frame_cache *this_trad_cache,
1725796c8dcSSimon Schubert 		   struct frame_id *this_id)
1735796c8dcSSimon Schubert {
1745796c8dcSSimon Schubert   (*this_id) = this_trad_cache->this_id;
1755796c8dcSSimon Schubert }
1765796c8dcSSimon Schubert 
1775796c8dcSSimon Schubert void
trad_frame_set_this_base(struct trad_frame_cache * this_trad_cache,CORE_ADDR this_base)1785796c8dcSSimon Schubert trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache,
1795796c8dcSSimon Schubert 			  CORE_ADDR this_base)
1805796c8dcSSimon Schubert {
1815796c8dcSSimon Schubert   this_trad_cache->this_base = this_base;
1825796c8dcSSimon Schubert }
1835796c8dcSSimon Schubert 
1845796c8dcSSimon Schubert CORE_ADDR
trad_frame_get_this_base(struct trad_frame_cache * this_trad_cache)1855796c8dcSSimon Schubert trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache)
1865796c8dcSSimon Schubert {
1875796c8dcSSimon Schubert   return this_trad_cache->this_base;
1885796c8dcSSimon Schubert }
189