* findvar.c: Include "builtin-regs.h".
[external/binutils.git] / gdb / std-regs.c
1 /* Builtin frame register, for GDB, the GNU debugger.
2
3    Copyright 2002 Free Software Foundation, Inc.
4
5    Contributed by Red Hat.
6
7    This file is part of GDB.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 59 Temple Place - Suite 330,
22    Boston, MA 02111-1307, USA.  */
23
24 #include "defs.h"
25 #include "builtin-regs.h"
26 #include "frame.h"
27 #include "gdbtypes.h"
28 #include "value.h"
29
30 /* Types that describe the various builtin registers.  */
31
32 static struct type *builtin_type_frame_reg;
33
34 /* Constructors for those types.  */
35
36 static void
37 build_builtin_type_frame_reg (void)
38 {
39   /* $frame.  */
40   if (builtin_type_frame_reg == NULL)
41     {
42 #if 0
43       struct frame
44       {
45         void *base;
46       };
47 #endif
48       builtin_type_frame_reg = init_composite_type ("frame", TYPE_CODE_STRUCT);
49       append_composite_type_field (builtin_type_frame_reg, "base",
50                                    builtin_type_void_data_ptr);
51     }
52 }
53
54 static struct value *
55 value_of_builtin_frame_reg (struct frame_info *frame)
56 {
57   struct value *val;
58   char *buf;
59   build_builtin_type_frame_reg ();
60   val = allocate_value (builtin_type_frame_reg);
61   VALUE_LVAL (val) = not_lval;
62   buf = VALUE_CONTENTS_RAW (val);
63   memset (buf, TYPE_LENGTH (VALUE_TYPE (val)), 0);
64   /* frame.base.  */
65   if (frame != NULL)
66     ADDRESS_TO_POINTER (builtin_type_void_data_ptr, buf, frame->frame);
67   buf += TYPE_LENGTH (builtin_type_void_data_ptr);
68   /* frame.XXX.  */
69   return val;
70 }
71
72 static struct value *
73 value_of_builtin_frame_fp_reg (struct frame_info *frame)
74 {
75 #ifdef FP_REGNUM
76   if (FP_REGNUM >= 0)
77     return value_of_register (FP_REGNUM, frame);
78 #endif
79   {
80     struct value *val = allocate_value (builtin_type_void_data_ptr);
81     char *buf = VALUE_CONTENTS_RAW (val);
82     if (frame == NULL)
83       memset (buf, TYPE_LENGTH (VALUE_TYPE (val)), 0);
84     else
85       ADDRESS_TO_POINTER (builtin_type_void_data_ptr, buf, frame->frame);
86     return val;
87   }
88 }
89
90 static struct value *
91 value_of_builtin_frame_pc_reg (struct frame_info *frame)
92 {
93 #ifdef PC_REGNUM
94   if (PC_REGNUM >= 0)
95     return value_of_register (PC_REGNUM, frame);
96 #endif
97   {
98     struct value *val = allocate_value (builtin_type_void_data_ptr);
99     char *buf = VALUE_CONTENTS_RAW (val);
100     if (frame == NULL)
101       memset (buf, TYPE_LENGTH (VALUE_TYPE (val)), 0);
102     else
103       ADDRESS_TO_POINTER (builtin_type_void_data_ptr, buf, frame->pc);
104     return val;
105   }
106 }
107
108 static struct value *
109 value_of_builtin_frame_sp_reg (struct frame_info *frame)
110 {
111 #ifdef SP_REGNUM
112   if (SP_REGNUM >= 0)
113     return value_of_register (SP_REGNUM, frame);
114 #endif
115   error ("Standard register ``$sp'' is not available for this target");
116 }
117
118 static struct value *
119 value_of_builtin_frame_ps_reg (struct frame_info *frame)
120 {
121 #ifdef PS_REGNUM
122   if (PS_REGNUM >= 0)
123     return value_of_register (PS_REGNUM, frame);
124 #endif
125   error ("Standard register ``$ps'' is not available for this target");
126 }
127
128 void
129 _initialize_frame_reg (void)
130 {
131   /* FIXME: cagney/2002-02-08: At present the local builtin types
132      can't be initialized using _initialize*() or gdbarch.  Due mainly
133      to non-multi-arch targets, GDB initializes things piece meal and,
134      as a consequence can leave these types NULL.  */
135   REGISTER_GDBARCH_SWAP (builtin_type_frame_reg);
136
137   /* Frame based $fp, $pc, $sp and $ps.  These only come into play
138      when the target does not define its own version of these
139      registers.  */
140   add_builtin_reg ("fp", value_of_builtin_frame_fp_reg);
141   add_builtin_reg ("pc", value_of_builtin_frame_pc_reg);
142   add_builtin_reg ("sp", value_of_builtin_frame_sp_reg);
143   add_builtin_reg ("ps", value_of_builtin_frame_ps_reg);
144
145   /* NOTE: cagney/2002-04-05: For moment leave the $frame / $gdbframe
146      / $gdb.frame disabled.  It isn't yet clear which of the many
147      options is the best.  */
148   if (0)
149     add_builtin_reg ("frame", value_of_builtin_frame_reg);
150 }