xref: /dflybsd-src/contrib/gdb-7/gdb/std-regs.c (revision 5796c8dc12c637f18a1740c26afd8d40ffa9b719)
1*5796c8dcSSimon Schubert /* Builtin frame register, for GDB, the GNU debugger.
2*5796c8dcSSimon Schubert 
3*5796c8dcSSimon Schubert    Copyright (C) 2002, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
4*5796c8dcSSimon Schubert 
5*5796c8dcSSimon Schubert    Contributed by Red Hat.
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 #include "defs.h"
23*5796c8dcSSimon Schubert #include "user-regs.h"
24*5796c8dcSSimon Schubert #include "frame.h"
25*5796c8dcSSimon Schubert #include "gdbtypes.h"
26*5796c8dcSSimon Schubert #include "value.h"
27*5796c8dcSSimon Schubert #include "gdb_string.h"
28*5796c8dcSSimon Schubert 
29*5796c8dcSSimon Schubert 
30*5796c8dcSSimon Schubert static struct value *
31*5796c8dcSSimon Schubert value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
32*5796c8dcSSimon Schubert {
33*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
34*5796c8dcSSimon Schubert   if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0)
35*5796c8dcSSimon Schubert     /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
36*5796c8dcSSimon Schubert        register name table overrides this built-in $fp register, there
37*5796c8dcSSimon Schubert        is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
38*5796c8dcSSimon Schubert        An architecture wanting to implement "$fp" as alias for a raw
39*5796c8dcSSimon Schubert        register can do so by adding "fp" to register name table (mind
40*5796c8dcSSimon Schubert        you, doing this is probably a dangerous thing).  */
41*5796c8dcSSimon Schubert     return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch),
42*5796c8dcSSimon Schubert 			      frame);
43*5796c8dcSSimon Schubert   else
44*5796c8dcSSimon Schubert     {
45*5796c8dcSSimon Schubert       struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
46*5796c8dcSSimon Schubert       struct value *val = allocate_value (data_ptr_type);
47*5796c8dcSSimon Schubert       gdb_byte *buf = value_contents_raw (val);
48*5796c8dcSSimon Schubert       if (frame == NULL)
49*5796c8dcSSimon Schubert 	memset (buf, 0, TYPE_LENGTH (value_type (val)));
50*5796c8dcSSimon Schubert       else
51*5796c8dcSSimon Schubert 	gdbarch_address_to_pointer (gdbarch, data_ptr_type,
52*5796c8dcSSimon Schubert 				    buf, get_frame_base_address (frame));
53*5796c8dcSSimon Schubert       return val;
54*5796c8dcSSimon Schubert     }
55*5796c8dcSSimon Schubert }
56*5796c8dcSSimon Schubert 
57*5796c8dcSSimon Schubert static struct value *
58*5796c8dcSSimon Schubert value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton)
59*5796c8dcSSimon Schubert {
60*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
61*5796c8dcSSimon Schubert   if (gdbarch_pc_regnum (gdbarch) >= 0)
62*5796c8dcSSimon Schubert     return value_of_register (gdbarch_pc_regnum (gdbarch), frame);
63*5796c8dcSSimon Schubert   else
64*5796c8dcSSimon Schubert     {
65*5796c8dcSSimon Schubert       struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
66*5796c8dcSSimon Schubert       struct value *val = allocate_value (func_ptr_type);
67*5796c8dcSSimon Schubert       gdb_byte *buf = value_contents_raw (val);
68*5796c8dcSSimon Schubert       if (frame == NULL)
69*5796c8dcSSimon Schubert 	memset (buf, 0, TYPE_LENGTH (value_type (val)));
70*5796c8dcSSimon Schubert       else
71*5796c8dcSSimon Schubert 	gdbarch_address_to_pointer (gdbarch, func_ptr_type,
72*5796c8dcSSimon Schubert 				    buf, get_frame_pc (frame));
73*5796c8dcSSimon Schubert       return val;
74*5796c8dcSSimon Schubert     }
75*5796c8dcSSimon Schubert }
76*5796c8dcSSimon Schubert 
77*5796c8dcSSimon Schubert static struct value *
78*5796c8dcSSimon Schubert value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
79*5796c8dcSSimon Schubert {
80*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
81*5796c8dcSSimon Schubert   if (gdbarch_sp_regnum (gdbarch) >= 0)
82*5796c8dcSSimon Schubert     return value_of_register (gdbarch_sp_regnum (gdbarch), frame);
83*5796c8dcSSimon Schubert   error (_("Standard register ``$sp'' is not available for this target"));
84*5796c8dcSSimon Schubert }
85*5796c8dcSSimon Schubert 
86*5796c8dcSSimon Schubert static struct value *
87*5796c8dcSSimon Schubert value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
88*5796c8dcSSimon Schubert {
89*5796c8dcSSimon Schubert   struct gdbarch *gdbarch = get_frame_arch (frame);
90*5796c8dcSSimon Schubert   if (gdbarch_ps_regnum (gdbarch) >= 0)
91*5796c8dcSSimon Schubert     return value_of_register (gdbarch_ps_regnum (gdbarch), frame);
92*5796c8dcSSimon Schubert   error (_("Standard register ``$ps'' is not available for this target"));
93*5796c8dcSSimon Schubert }
94*5796c8dcSSimon Schubert 
95*5796c8dcSSimon Schubert extern initialize_file_ftype _initialize_frame_reg; /* -Wmissing-prototypes */
96*5796c8dcSSimon Schubert 
97*5796c8dcSSimon Schubert void
98*5796c8dcSSimon Schubert _initialize_frame_reg (void)
99*5796c8dcSSimon Schubert {
100*5796c8dcSSimon Schubert   /* Frame based $fp, $pc, $sp and $ps.  These only come into play
101*5796c8dcSSimon Schubert      when the target does not define its own version of these
102*5796c8dcSSimon Schubert      registers.  */
103*5796c8dcSSimon Schubert   user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
104*5796c8dcSSimon Schubert   user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
105*5796c8dcSSimon Schubert   user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
106*5796c8dcSSimon Schubert   user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);
107*5796c8dcSSimon Schubert }
108