15796c8dcSSimon Schubert /* Builtin frame register, for GDB, the GNU debugger. 25796c8dcSSimon Schubert 3*cf7f2e2dSJohn Marino Copyright (C) 2002, 2005, 2007, 2008, 2009, 2010 4*cf7f2e2dSJohn Marino Free Software Foundation, Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert Contributed by Red Hat. 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This file is part of GDB. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 115796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 125796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 135796c8dcSSimon Schubert (at your option) any later version. 145796c8dcSSimon Schubert 155796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 165796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 175796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 185796c8dcSSimon Schubert GNU General Public License for more details. 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 215796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert #include "defs.h" 245796c8dcSSimon Schubert #include "user-regs.h" 255796c8dcSSimon Schubert #include "frame.h" 265796c8dcSSimon Schubert #include "gdbtypes.h" 275796c8dcSSimon Schubert #include "value.h" 285796c8dcSSimon Schubert #include "gdb_string.h" 295796c8dcSSimon Schubert 305796c8dcSSimon Schubert 315796c8dcSSimon Schubert static struct value * 325796c8dcSSimon Schubert value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton) 335796c8dcSSimon Schubert { 345796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (frame); 35*cf7f2e2dSJohn Marino 365796c8dcSSimon Schubert if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0) 375796c8dcSSimon Schubert /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the 385796c8dcSSimon Schubert register name table overrides this built-in $fp register, there 395796c8dcSSimon Schubert is no real reason for this gdbarch_deprecated_fp_regnum trickery here. 405796c8dcSSimon Schubert An architecture wanting to implement "$fp" as alias for a raw 415796c8dcSSimon Schubert register can do so by adding "fp" to register name table (mind 425796c8dcSSimon Schubert you, doing this is probably a dangerous thing). */ 435796c8dcSSimon Schubert return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch), 445796c8dcSSimon Schubert frame); 455796c8dcSSimon Schubert else 465796c8dcSSimon Schubert { 475796c8dcSSimon Schubert struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr; 485796c8dcSSimon Schubert struct value *val = allocate_value (data_ptr_type); 495796c8dcSSimon Schubert gdb_byte *buf = value_contents_raw (val); 50*cf7f2e2dSJohn Marino 515796c8dcSSimon Schubert if (frame == NULL) 525796c8dcSSimon Schubert memset (buf, 0, TYPE_LENGTH (value_type (val))); 535796c8dcSSimon Schubert else 545796c8dcSSimon Schubert gdbarch_address_to_pointer (gdbarch, data_ptr_type, 555796c8dcSSimon Schubert buf, get_frame_base_address (frame)); 565796c8dcSSimon Schubert return val; 575796c8dcSSimon Schubert } 585796c8dcSSimon Schubert } 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert static struct value * 615796c8dcSSimon Schubert value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton) 625796c8dcSSimon Schubert { 635796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (frame); 64*cf7f2e2dSJohn Marino 655796c8dcSSimon Schubert if (gdbarch_pc_regnum (gdbarch) >= 0) 665796c8dcSSimon Schubert return value_of_register (gdbarch_pc_regnum (gdbarch), frame); 675796c8dcSSimon Schubert else 685796c8dcSSimon Schubert { 695796c8dcSSimon Schubert struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr; 705796c8dcSSimon Schubert struct value *val = allocate_value (func_ptr_type); 715796c8dcSSimon Schubert gdb_byte *buf = value_contents_raw (val); 72*cf7f2e2dSJohn Marino 735796c8dcSSimon Schubert if (frame == NULL) 745796c8dcSSimon Schubert memset (buf, 0, TYPE_LENGTH (value_type (val))); 755796c8dcSSimon Schubert else 765796c8dcSSimon Schubert gdbarch_address_to_pointer (gdbarch, func_ptr_type, 775796c8dcSSimon Schubert buf, get_frame_pc (frame)); 785796c8dcSSimon Schubert return val; 795796c8dcSSimon Schubert } 805796c8dcSSimon Schubert } 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert static struct value * 835796c8dcSSimon Schubert value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton) 845796c8dcSSimon Schubert { 855796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (frame); 86*cf7f2e2dSJohn Marino 875796c8dcSSimon Schubert if (gdbarch_sp_regnum (gdbarch) >= 0) 885796c8dcSSimon Schubert return value_of_register (gdbarch_sp_regnum (gdbarch), frame); 895796c8dcSSimon Schubert error (_("Standard register ``$sp'' is not available for this target")); 905796c8dcSSimon Schubert } 915796c8dcSSimon Schubert 925796c8dcSSimon Schubert static struct value * 935796c8dcSSimon Schubert value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton) 945796c8dcSSimon Schubert { 955796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (frame); 96*cf7f2e2dSJohn Marino 975796c8dcSSimon Schubert if (gdbarch_ps_regnum (gdbarch) >= 0) 985796c8dcSSimon Schubert return value_of_register (gdbarch_ps_regnum (gdbarch), frame); 995796c8dcSSimon Schubert error (_("Standard register ``$ps'' is not available for this target")); 1005796c8dcSSimon Schubert } 1015796c8dcSSimon Schubert 1025796c8dcSSimon Schubert extern initialize_file_ftype _initialize_frame_reg; /* -Wmissing-prototypes */ 1035796c8dcSSimon Schubert 1045796c8dcSSimon Schubert void 1055796c8dcSSimon Schubert _initialize_frame_reg (void) 1065796c8dcSSimon Schubert { 1075796c8dcSSimon Schubert /* Frame based $fp, $pc, $sp and $ps. These only come into play 1085796c8dcSSimon Schubert when the target does not define its own version of these 1095796c8dcSSimon Schubert registers. */ 1105796c8dcSSimon Schubert user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL); 1115796c8dcSSimon Schubert user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL); 1125796c8dcSSimon Schubert user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL); 1135796c8dcSSimon Schubert user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL); 1145796c8dcSSimon Schubert } 115