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