1 /* User visible, per-frame registers, for GDB, the GNU debugger.
3 Copyright 2002 Free Software Foundation, Inc.
5 Contributed by Red Hat.
7 This file is part of GDB.
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.
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.
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. */
25 #include "user-regs.h"
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
31 /* A table of user registers.
33 User registers have regnum's that live above of the range [0
34 .. NUM_REGS + NUM_PSEUDO_REGS) (which is controlled by the target).
35 The target should never see a user register's regnum value.
37 Always append, never delete. By doing this, the relative regnum
38 (offset from NUM_REGS + NUM_PSEUDO_REGS) assigned to each user
39 register never changes. */
44 struct value
*(*read
) (struct frame_info
* frame
);
49 struct user_reg
*user
;
54 append_user_reg (struct user_regs
*regs
,
55 const char *name
, user_reg_read_ftype
*read
)
58 regs
->user
= xrealloc (regs
->user
,
59 regs
->nr
* sizeof (struct user_reg
));
60 regs
->user
[regs
->nr
- 1].name
= name
;
61 regs
->user
[regs
->nr
- 1].read
= read
;
64 /* An array of the builtin user registers. */
66 static struct user_regs builtin_user_regs
;
69 user_reg_add_builtin (const char *name
, user_reg_read_ftype
*read
)
71 append_user_reg (&builtin_user_regs
, name
, read
);
74 /* Per-architecture user registers. Start with the builtin user
75 registers and then, again, append. */
77 static struct gdbarch_data
*user_regs_data
;
80 user_regs_init (struct gdbarch
*gdbarch
)
83 struct user_regs
*regs
= XMALLOC (struct user_regs
);
84 memset (regs
, 0, sizeof (struct user_regs
));
85 for (i
= 0; i
< builtin_user_regs
.nr
; i
++)
86 append_user_reg (regs
, builtin_user_regs
.user
[i
].name
,
87 builtin_user_regs
.user
[i
].read
);
92 user_regs_free (struct gdbarch
*gdbarch
, void *data
)
94 struct user_regs
*regs
= data
;
100 user_reg_add (struct gdbarch
*gdbarch
, const char *name
,
101 user_reg_read_ftype
*read
)
103 struct user_regs
*regs
= gdbarch_data (gdbarch
, user_regs_data
);
106 /* ULGH, called during architecture initialization. Patch
108 regs
= user_regs_init (gdbarch
);
109 set_gdbarch_data (gdbarch
, user_regs_data
, regs
);
111 append_user_reg (regs
, name
, read
);
115 user_reg_map_name_to_regnum (struct gdbarch
*gdbarch
, const char *name
,
118 /* Make life easy, set the len to something reasonable. */
122 /* Search register name space first - always let an architecture
123 specific register override the user registers. */
126 int maxregs
= (gdbarch_num_regs (gdbarch
)
127 + gdbarch_num_pseudo_regs (gdbarch
));
128 for (i
= 0; i
< maxregs
; i
++)
130 const char *regname
= gdbarch_register_name (gdbarch
, i
);
131 if (regname
!= NULL
&& len
== strlen (regname
)
132 && strncmp (regname
, name
, len
) == 0)
139 /* Search the user name space. */
141 struct user_regs
*regs
= gdbarch_data (gdbarch
, user_regs_data
);
143 for (reg
= 0; reg
< regs
->nr
; reg
++)
145 if ((len
< 0 && strcmp (regs
->user
[reg
].name
, name
))
146 || (len
== strlen (regs
->user
[reg
].name
)
147 && strncmp (regs
->user
[reg
].name
, name
, len
) == 0))
148 return NUM_REGS
+ NUM_PSEUDO_REGS
+ reg
;
156 user_reg_map_regnum_to_name (struct gdbarch
*gdbarch
, int regnum
)
158 int maxregs
= (gdbarch_num_regs (gdbarch
)
159 + gdbarch_num_pseudo_regs (gdbarch
));
160 struct user_regs
*regs
= gdbarch_data (gdbarch
, user_regs_data
);
163 if (regnum
< maxregs
)
164 return gdbarch_register_name (gdbarch
, regnum
);
165 if (regnum
< (maxregs
+ regs
->nr
))
166 return regs
->user
[regnum
- maxregs
].name
;
171 value_of_user_reg (int regnum
, struct frame_info
*frame
)
173 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
174 struct user_regs
*regs
= gdbarch_data (gdbarch
, user_regs_data
);
175 int reg
= regnum
- (NUM_REGS
+ NUM_PSEUDO_REGS
);
176 gdb_assert (reg
>= 0 && reg
< regs
->nr
);
177 return regs
->user
[reg
].read (frame
);
180 extern initialize_file_ftype _initialize_user_regs
; /* -Wmissing-prototypes */
183 _initialize_user_regs (void)
185 user_regs_data
= register_gdbarch_data (user_regs_init
, user_regs_free
);