2007-06-18 Markus Deuling <deuling@de.ibm.com>
[deliverable/binutils-gdb.git] / gdb / std-regs.c
1 /* Builtin frame register, for GDB, the GNU debugger.
2
3 Copyright (C) 2002, 2005, 2007 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., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
23
24 #include "defs.h"
25 #include "user-regs.h"
26 #include "frame.h"
27 #include "gdbtypes.h"
28 #include "value.h"
29 #include "gdb_string.h"
30
31
32 static struct value *
33 value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
34 {
35 if (gdbarch_deprecated_fp_regnum (current_gdbarch) >= 0)
36 /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
37 register name table overrides this built-in $fp register, there
38 is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
39 An architecture wanting to implement "$fp" as alias for a raw
40 register can do so by adding "fp" to register name table (mind
41 you, doing this is probably a dangerous thing). */
42 return value_of_register (gdbarch_deprecated_fp_regnum (current_gdbarch),
43 frame);
44 else
45 {
46 struct value *val = allocate_value (builtin_type_void_data_ptr);
47 gdb_byte *buf = value_contents_raw (val);
48 if (frame == NULL)
49 memset (buf, 0, TYPE_LENGTH (value_type (val)));
50 else
51 gdbarch_address_to_pointer (current_gdbarch, builtin_type_void_data_ptr,
52 buf, get_frame_base_address (frame));
53 return val;
54 }
55 }
56
57 static struct value *
58 value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton)
59 {
60 if (gdbarch_pc_regnum (current_gdbarch) >= 0)
61 return value_of_register (gdbarch_pc_regnum (current_gdbarch), frame);
62 else
63 {
64 struct value *val = allocate_value (builtin_type_void_data_ptr);
65 gdb_byte *buf = value_contents_raw (val);
66 if (frame == NULL)
67 memset (buf, 0, TYPE_LENGTH (value_type (val)));
68 else
69 gdbarch_address_to_pointer (current_gdbarch, builtin_type_void_data_ptr,
70 buf, get_frame_pc (frame));
71 return val;
72 }
73 }
74
75 static struct value *
76 value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
77 {
78 if (gdbarch_sp_regnum (current_gdbarch) >= 0)
79 return value_of_register (gdbarch_sp_regnum (current_gdbarch), frame);
80 error (_("Standard register ``$sp'' is not available for this target"));
81 }
82
83 static struct value *
84 value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
85 {
86 if (gdbarch_ps_regnum (current_gdbarch) >= 0)
87 return value_of_register (gdbarch_ps_regnum (current_gdbarch), frame);
88 error (_("Standard register ``$ps'' is not available for this target"));
89 }
90
91 extern initialize_file_ftype _initialize_frame_reg; /* -Wmissing-prototypes */
92
93 void
94 _initialize_frame_reg (void)
95 {
96 /* Frame based $fp, $pc, $sp and $ps. These only come into play
97 when the target does not define its own version of these
98 registers. */
99 user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
100 user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
101 user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
102 user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);
103 }
This page took 0.051169 seconds and 5 git commands to generate.