gdb, testsuite: Fix return value in gdb.base/foll-fork.exp
[binutils-gdb.git] / gdb / std-regs.c
blob3539d8a629a6ac2aafc6f78c811af0ed7e3d4444
1 /* Builtin frame register, for GDB, the GNU debugger.
3 Copyright (C) 2002-2024 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 3 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, see <http://www.gnu.org/licenses/>. */
22 #include "user-regs.h"
23 #include "frame.h"
24 #include "gdbtypes.h"
25 #include "value.h"
26 #include "gdbarch.h"
28 static struct value *
29 value_of_builtin_frame_fp_reg (const frame_info_ptr &frame, const void *baton)
31 struct gdbarch *gdbarch = get_frame_arch (frame);
33 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0)
34 /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
35 register name table overrides this built-in $fp register, there
36 is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
37 An architecture wanting to implement "$fp" as alias for a raw
38 register can do so by adding "fp" to register name table (mind
39 you, doing this is probably a dangerous thing). */
40 return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch),
41 get_next_frame_sentinel_okay (frame));
42 else
44 struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
45 struct value *val = value::allocate (data_ptr_type);
46 gdb_byte *buf = val->contents_raw ().data ();
48 gdbarch_address_to_pointer (gdbarch, data_ptr_type,
49 buf, get_frame_base_address (frame));
50 return val;
54 static struct value *
55 value_of_builtin_frame_pc_reg (const frame_info_ptr &frame, const void *baton)
57 struct gdbarch *gdbarch = get_frame_arch (frame);
59 if (gdbarch_pc_regnum (gdbarch) >= 0)
60 return value_of_register (gdbarch_pc_regnum (gdbarch),
61 get_next_frame_sentinel_okay (frame));
62 else
64 struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
65 struct value *val = value::allocate (func_ptr_type);
66 gdb_byte *buf = val->contents_raw ().data ();
68 gdbarch_address_to_pointer (gdbarch, func_ptr_type,
69 buf, get_frame_pc (frame));
70 return val;
74 static struct value *
75 value_of_builtin_frame_sp_reg (const frame_info_ptr &frame, const void *baton)
77 struct gdbarch *gdbarch = get_frame_arch (frame);
79 if (gdbarch_sp_regnum (gdbarch) >= 0)
80 return value_of_register (gdbarch_sp_regnum (gdbarch),
81 get_next_frame_sentinel_okay (frame));
82 error (_("Standard register ``$sp'' is not available for this target"));
85 static struct value *
86 value_of_builtin_frame_ps_reg (const frame_info_ptr &frame, const void *baton)
88 struct gdbarch *gdbarch = get_frame_arch (frame);
90 if (gdbarch_ps_regnum (gdbarch) >= 0)
91 return value_of_register (gdbarch_ps_regnum (gdbarch),
92 get_next_frame_sentinel_okay (frame));
93 error (_("Standard register ``$ps'' is not available for this target"));
96 void _initialize_frame_reg ();
97 void
98 _initialize_frame_reg ()
100 /* Frame based $fp, $pc, $sp and $ps. These only come into play
101 when the target does not define its own version of these
102 registers. */
103 user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
104 user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
105 user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
106 user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);