15796c8dcSSimon Schubert /* Definitions for frame address handler, for GDB, the GNU debugger. 25796c8dcSSimon Schubert 3*cf7f2e2dSJohn Marino Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010 4*cf7f2e2dSJohn Marino Free Software Foundation, Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert This file is part of GDB. 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 95796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 105796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 115796c8dcSSimon Schubert (at your option) any later version. 125796c8dcSSimon Schubert 135796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 145796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 155796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165796c8dcSSimon Schubert GNU General Public License for more details. 175796c8dcSSimon Schubert 185796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 195796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 205796c8dcSSimon Schubert 215796c8dcSSimon Schubert #include "defs.h" 225796c8dcSSimon Schubert #include "frame-base.h" 235796c8dcSSimon Schubert #include "frame.h" 245796c8dcSSimon Schubert #include "gdb_obstack.h" 255796c8dcSSimon Schubert 265796c8dcSSimon Schubert /* A default frame base implementations. If it wasn't for the old 275796c8dcSSimon Schubert DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS, 285796c8dcSSimon Schubert these could be combined into a single function. All architectures 295796c8dcSSimon Schubert really need to override this. */ 305796c8dcSSimon Schubert 315796c8dcSSimon Schubert static CORE_ADDR 325796c8dcSSimon Schubert default_frame_base_address (struct frame_info *this_frame, void **this_cache) 335796c8dcSSimon Schubert { 345796c8dcSSimon Schubert return get_frame_base (this_frame); /* sigh! */ 355796c8dcSSimon Schubert } 365796c8dcSSimon Schubert 375796c8dcSSimon Schubert static CORE_ADDR 385796c8dcSSimon Schubert default_frame_locals_address (struct frame_info *this_frame, void **this_cache) 395796c8dcSSimon Schubert { 405796c8dcSSimon Schubert return default_frame_base_address (this_frame, this_cache); 415796c8dcSSimon Schubert } 425796c8dcSSimon Schubert 435796c8dcSSimon Schubert static CORE_ADDR 445796c8dcSSimon Schubert default_frame_args_address (struct frame_info *this_frame, void **this_cache) 455796c8dcSSimon Schubert { 465796c8dcSSimon Schubert return default_frame_base_address (this_frame, this_cache); 475796c8dcSSimon Schubert } 485796c8dcSSimon Schubert 495796c8dcSSimon Schubert const struct frame_base default_frame_base = { 505796c8dcSSimon Schubert NULL, /* No parent. */ 515796c8dcSSimon Schubert default_frame_base_address, 525796c8dcSSimon Schubert default_frame_locals_address, 535796c8dcSSimon Schubert default_frame_args_address 545796c8dcSSimon Schubert }; 555796c8dcSSimon Schubert 565796c8dcSSimon Schubert static struct gdbarch_data *frame_base_data; 575796c8dcSSimon Schubert 585796c8dcSSimon Schubert struct frame_base_table_entry 595796c8dcSSimon Schubert { 605796c8dcSSimon Schubert frame_base_sniffer_ftype *sniffer; 615796c8dcSSimon Schubert struct frame_base_table_entry *next; 625796c8dcSSimon Schubert }; 635796c8dcSSimon Schubert 645796c8dcSSimon Schubert struct frame_base_table 655796c8dcSSimon Schubert { 665796c8dcSSimon Schubert struct frame_base_table_entry *head; 675796c8dcSSimon Schubert struct frame_base_table_entry **tail; 685796c8dcSSimon Schubert const struct frame_base *default_base; 695796c8dcSSimon Schubert }; 705796c8dcSSimon Schubert 715796c8dcSSimon Schubert static void * 725796c8dcSSimon Schubert frame_base_init (struct obstack *obstack) 735796c8dcSSimon Schubert { 745796c8dcSSimon Schubert struct frame_base_table *table 755796c8dcSSimon Schubert = OBSTACK_ZALLOC (obstack, struct frame_base_table); 76*cf7f2e2dSJohn Marino 775796c8dcSSimon Schubert table->tail = &table->head; 785796c8dcSSimon Schubert table->default_base = &default_frame_base; 795796c8dcSSimon Schubert return table; 805796c8dcSSimon Schubert } 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert void 835796c8dcSSimon Schubert frame_base_append_sniffer (struct gdbarch *gdbarch, 845796c8dcSSimon Schubert frame_base_sniffer_ftype *sniffer) 855796c8dcSSimon Schubert { 865796c8dcSSimon Schubert struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); 87*cf7f2e2dSJohn Marino 885796c8dcSSimon Schubert (*table->tail) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_base_table_entry); 895796c8dcSSimon Schubert (*table->tail)->sniffer = sniffer; 905796c8dcSSimon Schubert table->tail = &(*table->tail)->next; 915796c8dcSSimon Schubert } 925796c8dcSSimon Schubert 935796c8dcSSimon Schubert void 945796c8dcSSimon Schubert frame_base_set_default (struct gdbarch *gdbarch, 955796c8dcSSimon Schubert const struct frame_base *default_base) 965796c8dcSSimon Schubert { 975796c8dcSSimon Schubert struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); 98*cf7f2e2dSJohn Marino 995796c8dcSSimon Schubert table->default_base = default_base; 1005796c8dcSSimon Schubert } 1015796c8dcSSimon Schubert 1025796c8dcSSimon Schubert const struct frame_base * 1035796c8dcSSimon Schubert frame_base_find_by_frame (struct frame_info *this_frame) 1045796c8dcSSimon Schubert { 1055796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (this_frame); 1065796c8dcSSimon Schubert struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); 1075796c8dcSSimon Schubert struct frame_base_table_entry *entry; 1085796c8dcSSimon Schubert 1095796c8dcSSimon Schubert for (entry = table->head; entry != NULL; entry = entry->next) 1105796c8dcSSimon Schubert { 1115796c8dcSSimon Schubert const struct frame_base *desc = NULL; 112*cf7f2e2dSJohn Marino 1135796c8dcSSimon Schubert desc = entry->sniffer (this_frame); 1145796c8dcSSimon Schubert if (desc != NULL) 1155796c8dcSSimon Schubert return desc; 1165796c8dcSSimon Schubert } 1175796c8dcSSimon Schubert return table->default_base; 1185796c8dcSSimon Schubert } 1195796c8dcSSimon Schubert 1205796c8dcSSimon Schubert extern initialize_file_ftype _initialize_frame_base; /* -Wmissing-prototypes */ 1215796c8dcSSimon Schubert 1225796c8dcSSimon Schubert void 1235796c8dcSSimon Schubert _initialize_frame_base (void) 1245796c8dcSSimon Schubert { 1255796c8dcSSimon Schubert frame_base_data = gdbarch_data_register_pre_init (frame_base_init); 1265796c8dcSSimon Schubert } 127