xref: /dragonfly/contrib/gdb-7/gdb/std-regs.c (revision 28c26f7e)
1 /* Builtin frame register, for GDB, the GNU debugger.
2 
3    Copyright (C) 2002, 2005, 2007, 2008, 2009 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 #include "gdb_string.h"
28 
29 
30 static struct value *
31 value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
32 {
33   struct gdbarch *gdbarch = get_frame_arch (frame);
34   if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0)
35     /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
36        register name table overrides this built-in $fp register, there
37        is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
38        An architecture wanting to implement "$fp" as alias for a raw
39        register can do so by adding "fp" to register name table (mind
40        you, doing this is probably a dangerous thing).  */
41     return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch),
42 			      frame);
43   else
44     {
45       struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
46       struct value *val = allocate_value (data_ptr_type);
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 (gdbarch, data_ptr_type,
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   struct gdbarch *gdbarch = get_frame_arch (frame);
61   if (gdbarch_pc_regnum (gdbarch) >= 0)
62     return value_of_register (gdbarch_pc_regnum (gdbarch), frame);
63   else
64     {
65       struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
66       struct value *val = allocate_value (func_ptr_type);
67       gdb_byte *buf = value_contents_raw (val);
68       if (frame == NULL)
69 	memset (buf, 0, TYPE_LENGTH (value_type (val)));
70       else
71 	gdbarch_address_to_pointer (gdbarch, func_ptr_type,
72 				    buf, get_frame_pc (frame));
73       return val;
74     }
75 }
76 
77 static struct value *
78 value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
79 {
80   struct gdbarch *gdbarch = get_frame_arch (frame);
81   if (gdbarch_sp_regnum (gdbarch) >= 0)
82     return value_of_register (gdbarch_sp_regnum (gdbarch), frame);
83   error (_("Standard register ``$sp'' is not available for this target"));
84 }
85 
86 static struct value *
87 value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
88 {
89   struct gdbarch *gdbarch = get_frame_arch (frame);
90   if (gdbarch_ps_regnum (gdbarch) >= 0)
91     return value_of_register (gdbarch_ps_regnum (gdbarch), frame);
92   error (_("Standard register ``$ps'' is not available for this target"));
93 }
94 
95 extern initialize_file_ftype _initialize_frame_reg; /* -Wmissing-prototypes */
96 
97 void
98 _initialize_frame_reg (void)
99 {
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);
107 }
108