GDB (API)
/home/stan/gdb/src/gdb/std-regs.c
Go to the documentation of this file.
00001 /* Builtin frame register, for GDB, the GNU debugger.
00002 
00003    Copyright (C) 2002-2013 Free Software Foundation, Inc.
00004 
00005    Contributed by Red Hat.
00006 
00007    This file is part of GDB.
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 3 of the License, or
00012    (at your option) any later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00021 
00022 #include "defs.h"
00023 #include "user-regs.h"
00024 #include "frame.h"
00025 #include "gdbtypes.h"
00026 #include "value.h"
00027 #include "gdb_string.h"
00028 
00029 
00030 static struct value *
00031 value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
00032 {
00033   struct gdbarch *gdbarch = get_frame_arch (frame);
00034 
00035   if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0)
00036     /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
00037        register name table overrides this built-in $fp register, there
00038        is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
00039        An architecture wanting to implement "$fp" as alias for a raw
00040        register can do so by adding "fp" to register name table (mind
00041        you, doing this is probably a dangerous thing).  */
00042     return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch),
00043                               frame);
00044   else
00045     {
00046       struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
00047       struct value *val = allocate_value (data_ptr_type);
00048       gdb_byte *buf = value_contents_raw (val);
00049 
00050       gdbarch_address_to_pointer (gdbarch, data_ptr_type,
00051                                   buf, get_frame_base_address (frame));
00052       return val;
00053     }
00054 }
00055 
00056 static struct value *
00057 value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton)
00058 {
00059   struct gdbarch *gdbarch = get_frame_arch (frame);
00060 
00061   if (gdbarch_pc_regnum (gdbarch) >= 0)
00062     return value_of_register (gdbarch_pc_regnum (gdbarch), frame);
00063   else
00064     {
00065       struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
00066       struct value *val = allocate_value (func_ptr_type);
00067       gdb_byte *buf = value_contents_raw (val);
00068 
00069       gdbarch_address_to_pointer (gdbarch, func_ptr_type,
00070                                   buf, get_frame_pc (frame));
00071       return val;
00072     }
00073 }
00074 
00075 static struct value *
00076 value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
00077 {
00078   struct gdbarch *gdbarch = get_frame_arch (frame);
00079 
00080   if (gdbarch_sp_regnum (gdbarch) >= 0)
00081     return value_of_register (gdbarch_sp_regnum (gdbarch), frame);
00082   error (_("Standard register ``$sp'' is not available for this target"));
00083 }
00084 
00085 static struct value *
00086 value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
00087 {
00088   struct gdbarch *gdbarch = get_frame_arch (frame);
00089 
00090   if (gdbarch_ps_regnum (gdbarch) >= 0)
00091     return value_of_register (gdbarch_ps_regnum (gdbarch), frame);
00092   error (_("Standard register ``$ps'' is not available for this target"));
00093 }
00094 
00095 extern initialize_file_ftype _initialize_frame_reg; /* -Wmissing-prototypes */
00096 
00097 void
00098 _initialize_frame_reg (void)
00099 {
00100   /* Frame based $fp, $pc, $sp and $ps.  These only come into play
00101      when the target does not define its own version of these
00102      registers.  */
00103   user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
00104   user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
00105   user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
00106   user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);
00107 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines