Comment tidy
[deliverable/binutils-gdb.git] / gdb / std-regs.c
CommitLineData
0406ec40
AC
1/* Builtin frame register, for GDB, the GNU debugger.
2
61baf725 3 Copyright (C) 2002-2017 Free Software Foundation, Inc.
0406ec40
AC
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
0406ec40
AC
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0406ec40
AC
21
22#include "defs.h"
eb8bc282 23#include "user-regs.h"
0406ec40
AC
24#include "frame.h"
25#include "gdbtypes.h"
26#include "value.h"
0406ec40 27static struct value *
123dc839 28value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
0406ec40 29{
e9a4730f 30 struct gdbarch *gdbarch = get_frame_arch (frame);
433759f7 31
e9a4730f 32 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0)
0ba6dca9
AC
33 /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
34 register name table overrides this built-in $fp register, there
064f5156 35 is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
0ba6dca9
AC
36 An architecture wanting to implement "$fp" as alias for a raw
37 register can do so by adding "fp" to register name table (mind
38 you, doing this is probably a dangerous thing). */
e9a4730f 39 return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch),
064f5156 40 frame);
0ba6dca9
AC
41 else
42 {
0dfff4cb
UW
43 struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
44 struct value *val = allocate_value (data_ptr_type);
10c42a71 45 gdb_byte *buf = value_contents_raw (val);
433759f7 46
23ce9890
MS
47 gdbarch_address_to_pointer (gdbarch, data_ptr_type,
48 buf, get_frame_base_address (frame));
0ba6dca9
AC
49 return val;
50 }
0406ec40
AC
51}
52
53static struct value *
123dc839 54value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton)
0406ec40 55{
e9a4730f 56 struct gdbarch *gdbarch = get_frame_arch (frame);
433759f7 57
e9a4730f
UW
58 if (gdbarch_pc_regnum (gdbarch) >= 0)
59 return value_of_register (gdbarch_pc_regnum (gdbarch), frame);
82de1e5b
AC
60 else
61 {
0dfff4cb
UW
62 struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
63 struct value *val = allocate_value (func_ptr_type);
10c42a71 64 gdb_byte *buf = value_contents_raw (val);
433759f7 65
18ea20ac
MS
66 gdbarch_address_to_pointer (gdbarch, func_ptr_type,
67 buf, get_frame_pc (frame));
82de1e5b
AC
68 return val;
69 }
0406ec40
AC
70}
71
72static struct value *
123dc839 73value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
0406ec40 74{
e9a4730f 75 struct gdbarch *gdbarch = get_frame_arch (frame);
433759f7 76
e9a4730f
UW
77 if (gdbarch_sp_regnum (gdbarch) >= 0)
78 return value_of_register (gdbarch_sp_regnum (gdbarch), frame);
8a3fe4f8 79 error (_("Standard register ``$sp'' is not available for this target"));
0406ec40
AC
80}
81
82static struct value *
123dc839 83value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
0406ec40 84{
e9a4730f 85 struct gdbarch *gdbarch = get_frame_arch (frame);
433759f7 86
e9a4730f
UW
87 if (gdbarch_ps_regnum (gdbarch) >= 0)
88 return value_of_register (gdbarch_ps_regnum (gdbarch), frame);
8a3fe4f8 89 error (_("Standard register ``$ps'' is not available for this target"));
0406ec40
AC
90}
91
92void
93_initialize_frame_reg (void)
94{
0406ec40
AC
95 /* Frame based $fp, $pc, $sp and $ps. These only come into play
96 when the target does not define its own version of these
97 registers. */
123dc839
DJ
98 user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
99 user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
100 user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
101 user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);
0406ec40 102}
This page took 1.629562 seconds and 4 git commands to generate.