2011-03-01 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / std-regs.c
CommitLineData
0406ec40
AC
1/* Builtin frame register, for GDB, the GNU debugger.
2
7b6bb8da 3 Copyright (C) 2002, 2005, 2007, 2008, 2009, 2010, 2011
4c38e0a4 4 Free Software Foundation, Inc.
0406ec40
AC
5
6 Contributed by Red Hat.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
0406ec40
AC
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0406ec40
AC
22
23#include "defs.h"
eb8bc282 24#include "user-regs.h"
0406ec40
AC
25#include "frame.h"
26#include "gdbtypes.h"
27#include "value.h"
b66d6d2e 28#include "gdb_string.h"
0406ec40 29
0406ec40
AC
30
31static struct value *
123dc839 32value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
0406ec40 33{
e9a4730f 34 struct gdbarch *gdbarch = get_frame_arch (frame);
433759f7 35
e9a4730f 36 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0)
0ba6dca9
AC
37 /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
38 register name table overrides this built-in $fp register, there
064f5156 39 is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
0ba6dca9
AC
40 An architecture wanting to implement "$fp" as alias for a raw
41 register can do so by adding "fp" to register name table (mind
42 you, doing this is probably a dangerous thing). */
e9a4730f 43 return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch),
064f5156 44 frame);
0ba6dca9
AC
45 else
46 {
0dfff4cb
UW
47 struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
48 struct value *val = allocate_value (data_ptr_type);
10c42a71 49 gdb_byte *buf = value_contents_raw (val);
433759f7 50
0ba6dca9 51 if (frame == NULL)
170cd118 52 memset (buf, 0, TYPE_LENGTH (value_type (val)));
0ba6dca9 53 else
0dfff4cb 54 gdbarch_address_to_pointer (gdbarch, data_ptr_type,
76e71323 55 buf, get_frame_base_address (frame));
0ba6dca9
AC
56 return val;
57 }
0406ec40
AC
58}
59
60static struct value *
123dc839 61value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton)
0406ec40 62{
e9a4730f 63 struct gdbarch *gdbarch = get_frame_arch (frame);
433759f7 64
e9a4730f
UW
65 if (gdbarch_pc_regnum (gdbarch) >= 0)
66 return value_of_register (gdbarch_pc_regnum (gdbarch), frame);
82de1e5b
AC
67 else
68 {
0dfff4cb
UW
69 struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
70 struct value *val = allocate_value (func_ptr_type);
10c42a71 71 gdb_byte *buf = value_contents_raw (val);
433759f7 72
18ea20ac
MS
73 gdbarch_address_to_pointer (gdbarch, func_ptr_type,
74 buf, get_frame_pc (frame));
82de1e5b
AC
75 return val;
76 }
0406ec40
AC
77}
78
79static struct value *
123dc839 80value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
0406ec40 81{
e9a4730f 82 struct gdbarch *gdbarch = get_frame_arch (frame);
433759f7 83
e9a4730f
UW
84 if (gdbarch_sp_regnum (gdbarch) >= 0)
85 return value_of_register (gdbarch_sp_regnum (gdbarch), frame);
8a3fe4f8 86 error (_("Standard register ``$sp'' is not available for this target"));
0406ec40
AC
87}
88
89static struct value *
123dc839 90value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
0406ec40 91{
e9a4730f 92 struct gdbarch *gdbarch = get_frame_arch (frame);
433759f7 93
e9a4730f
UW
94 if (gdbarch_ps_regnum (gdbarch) >= 0)
95 return value_of_register (gdbarch_ps_regnum (gdbarch), frame);
8a3fe4f8 96 error (_("Standard register ``$ps'' is not available for this target"));
0406ec40
AC
97}
98
b9362cc7
AC
99extern initialize_file_ftype _initialize_frame_reg; /* -Wmissing-prototypes */
100
0406ec40
AC
101void
102_initialize_frame_reg (void)
103{
0406ec40
AC
104 /* Frame based $fp, $pc, $sp and $ps. These only come into play
105 when the target does not define its own version of these
106 registers. */
123dc839
DJ
107 user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
108 user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
109 user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
110 user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);
0406ec40 111}
This page took 1.279101 seconds and 4 git commands to generate.