GDB (xrefs)

/tmp/gdb-8.1/gdb/std-regs.c
Go to the documentation of this file.
1 /* Builtin frame register, for GDB, the GNU debugger.
2
3 Copyright (C) 2002-2018 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 3 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, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "user-regs.h"
24 #include "frame.h"
25 #include "gdbtypes.h"
26 #include "value.h"
27 static struct value *
28 value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
29 {
30 struct gdbarch *gdbarch = get_frame_arch (frame);
31
32 if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0)
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
35 is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
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). */
39 return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch),
40 frame);
41 else
42 {
43 struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
44 struct value *val = allocate_value (data_ptr_type);
45 gdb_byte *buf = value_contents_raw (val);
46
47 gdbarch_address_to_pointer (gdbarch, data_ptr_type,
48 buf, get_frame_base_address (frame));
49 return val;
50 }
51 }
52
53 static struct value *
54 value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton)
55 {
56 struct gdbarch *gdbarch = get_frame_arch (frame);
57
58 if (gdbarch_pc_regnum (gdbarch) >= 0)
59 return value_of_register (gdbarch_pc_regnum (gdbarch), frame);
60 else
61 {
62 struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
63 struct value *val = allocate_value (func_ptr_type);
64 gdb_byte *buf = value_contents_raw (val);
65
66 gdbarch_address_to_pointer (gdbarch, func_ptr_type,
67 buf, get_frame_pc (frame));
68 return val;
69 }
70 }
71
72 static struct value *
73 value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
74 {
75 struct gdbarch *gdbarch = get_frame_arch (frame);
76
77 if (gdbarch_sp_regnum (gdbarch) >= 0)
78 return value_of_register (gdbarch_sp_regnum (gdbarch), frame);
79 error (_("Standard register ``$sp'' is not available for this target"));
80 }
81
82 static struct value *
83 value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
84 {
85 struct gdbarch *gdbarch = get_frame_arch (frame);
86
87 if (gdbarch_ps_regnum (gdbarch) >= 0)
88 return value_of_register (gdbarch_ps_regnum (gdbarch), frame);
89 error (_("Standard register ``$ps'' is not available for this target"));
90 }
91
92 void
93 _initialize_frame_reg (void)
94 {
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. */
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);
102 }
gdbarch
Definition: gdbarch.c:127
builtin_type::builtin_func_ptr
struct type * builtin_func_ptr
Definition: gdbtypes.h:1565
get_frame_pc
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
gdbarch_deprecated_fp_regnum
int gdbarch_deprecated_fp_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2347
builtin_type
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition: gdbtypes.c:5217
frame_info
Definition: frame.c:85
_
#define _(String)
Definition: gdb_locale.h:35
_initialize_frame_reg
void _initialize_frame_reg(void)
Definition: std-regs.c:93
defs.h
gdbarch_ps_regnum
int gdbarch_ps_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2180
allocate_value
struct value * allocate_value(struct type *type)
Definition: value.c:1036
gdbarch_sp_regnum
int gdbarch_sp_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2146
frame.h
value_of_builtin_frame_sp_reg
static struct value * value_of_builtin_frame_sp_reg(struct frame_info *frame, const void *baton)
Definition: std-regs.c:73
type
Definition: gdbtypes.h:749
user-regs.h
value
Definition: value.c:169
get_frame_base_address
CORE_ADDR get_frame_base_address(struct frame_info *fi)
Definition: frame.c:2552
user_reg_add_builtin
void user_reg_add_builtin(const char *name, user_reg_read_ftype *read, const void *baton)
Definition: user-regs.c:85
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
value_of_register
struct value * value_of_register(int regnum, struct frame_info *frame)
Definition: findvar.c:263
builtin_type::builtin_data_ptr
struct type * builtin_data_ptr
Definition: gdbtypes.h:1554
value.h
value_of_builtin_frame_pc_reg
static struct value * value_of_builtin_frame_pc_reg(struct frame_info *frame, const void *baton)
Definition: std-regs.c:54
gdbtypes.h
gdbarch_pc_regnum
int gdbarch_pc_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2163
value_of_builtin_frame_ps_reg
static struct value * value_of_builtin_frame_ps_reg(struct frame_info *frame, const void *baton)
Definition: std-regs.c:83
value_contents_raw
gdb_byte * value_contents_raw(struct value *value)
Definition: value.c:1158
error
void error(const char *fmt,...)
Definition: errors.c:38
gdbarch_address_to_pointer
void gdbarch_address_to_pointer(struct gdbarch *gdbarch, struct type *type, gdb_byte *buf, CORE_ADDR addr)
Definition: gdbarch.c:2680
get_frame_arch
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
value_of_builtin_frame_fp_reg
static struct value * value_of_builtin_frame_fp_reg(struct frame_info *frame, const void *baton)
Definition: std-regs.c:28