1*5796c8dcSSimon Schubert /* Definitions for frame address handler, for GDB, the GNU debugger. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. 4*5796c8dcSSimon Schubert 5*5796c8dcSSimon Schubert This file is part of GDB. 6*5796c8dcSSimon Schubert 7*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 8*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 9*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 10*5796c8dcSSimon Schubert (at your option) any later version. 11*5796c8dcSSimon Schubert 12*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 13*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 14*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*5796c8dcSSimon Schubert GNU General Public License for more details. 16*5796c8dcSSimon Schubert 17*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 18*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*5796c8dcSSimon Schubert 20*5796c8dcSSimon Schubert #include "defs.h" 21*5796c8dcSSimon Schubert #include "frame-base.h" 22*5796c8dcSSimon Schubert #include "frame.h" 23*5796c8dcSSimon Schubert #include "gdb_obstack.h" 24*5796c8dcSSimon Schubert 25*5796c8dcSSimon Schubert /* A default frame base implementations. If it wasn't for the old 26*5796c8dcSSimon Schubert DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS, 27*5796c8dcSSimon Schubert these could be combined into a single function. All architectures 28*5796c8dcSSimon Schubert really need to override this. */ 29*5796c8dcSSimon Schubert 30*5796c8dcSSimon Schubert static CORE_ADDR 31*5796c8dcSSimon Schubert default_frame_base_address (struct frame_info *this_frame, void **this_cache) 32*5796c8dcSSimon Schubert { 33*5796c8dcSSimon Schubert return get_frame_base (this_frame); /* sigh! */ 34*5796c8dcSSimon Schubert } 35*5796c8dcSSimon Schubert 36*5796c8dcSSimon Schubert static CORE_ADDR 37*5796c8dcSSimon Schubert default_frame_locals_address (struct frame_info *this_frame, void **this_cache) 38*5796c8dcSSimon Schubert { 39*5796c8dcSSimon Schubert return default_frame_base_address (this_frame, this_cache); 40*5796c8dcSSimon Schubert } 41*5796c8dcSSimon Schubert 42*5796c8dcSSimon Schubert static CORE_ADDR 43*5796c8dcSSimon Schubert default_frame_args_address (struct frame_info *this_frame, void **this_cache) 44*5796c8dcSSimon Schubert { 45*5796c8dcSSimon Schubert return default_frame_base_address (this_frame, this_cache); 46*5796c8dcSSimon Schubert } 47*5796c8dcSSimon Schubert 48*5796c8dcSSimon Schubert const struct frame_base default_frame_base = { 49*5796c8dcSSimon Schubert NULL, /* No parent. */ 50*5796c8dcSSimon Schubert default_frame_base_address, 51*5796c8dcSSimon Schubert default_frame_locals_address, 52*5796c8dcSSimon Schubert default_frame_args_address 53*5796c8dcSSimon Schubert }; 54*5796c8dcSSimon Schubert 55*5796c8dcSSimon Schubert static struct gdbarch_data *frame_base_data; 56*5796c8dcSSimon Schubert 57*5796c8dcSSimon Schubert struct frame_base_table_entry 58*5796c8dcSSimon Schubert { 59*5796c8dcSSimon Schubert frame_base_sniffer_ftype *sniffer; 60*5796c8dcSSimon Schubert struct frame_base_table_entry *next; 61*5796c8dcSSimon Schubert }; 62*5796c8dcSSimon Schubert 63*5796c8dcSSimon Schubert struct frame_base_table 64*5796c8dcSSimon Schubert { 65*5796c8dcSSimon Schubert struct frame_base_table_entry *head; 66*5796c8dcSSimon Schubert struct frame_base_table_entry **tail; 67*5796c8dcSSimon Schubert const struct frame_base *default_base; 68*5796c8dcSSimon Schubert }; 69*5796c8dcSSimon Schubert 70*5796c8dcSSimon Schubert static void * 71*5796c8dcSSimon Schubert frame_base_init (struct obstack *obstack) 72*5796c8dcSSimon Schubert { 73*5796c8dcSSimon Schubert struct frame_base_table *table 74*5796c8dcSSimon Schubert = OBSTACK_ZALLOC (obstack, struct frame_base_table); 75*5796c8dcSSimon Schubert table->tail = &table->head; 76*5796c8dcSSimon Schubert table->default_base = &default_frame_base; 77*5796c8dcSSimon Schubert return table; 78*5796c8dcSSimon Schubert } 79*5796c8dcSSimon Schubert 80*5796c8dcSSimon Schubert void 81*5796c8dcSSimon Schubert frame_base_append_sniffer (struct gdbarch *gdbarch, 82*5796c8dcSSimon Schubert frame_base_sniffer_ftype *sniffer) 83*5796c8dcSSimon Schubert { 84*5796c8dcSSimon Schubert struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); 85*5796c8dcSSimon Schubert (*table->tail) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_base_table_entry); 86*5796c8dcSSimon Schubert (*table->tail)->sniffer = sniffer; 87*5796c8dcSSimon Schubert table->tail = &(*table->tail)->next; 88*5796c8dcSSimon Schubert } 89*5796c8dcSSimon Schubert 90*5796c8dcSSimon Schubert void 91*5796c8dcSSimon Schubert frame_base_set_default (struct gdbarch *gdbarch, 92*5796c8dcSSimon Schubert const struct frame_base *default_base) 93*5796c8dcSSimon Schubert { 94*5796c8dcSSimon Schubert struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); 95*5796c8dcSSimon Schubert table->default_base = default_base; 96*5796c8dcSSimon Schubert } 97*5796c8dcSSimon Schubert 98*5796c8dcSSimon Schubert const struct frame_base * 99*5796c8dcSSimon Schubert frame_base_find_by_frame (struct frame_info *this_frame) 100*5796c8dcSSimon Schubert { 101*5796c8dcSSimon Schubert struct gdbarch *gdbarch = get_frame_arch (this_frame); 102*5796c8dcSSimon Schubert struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); 103*5796c8dcSSimon Schubert struct frame_base_table_entry *entry; 104*5796c8dcSSimon Schubert 105*5796c8dcSSimon Schubert for (entry = table->head; entry != NULL; entry = entry->next) 106*5796c8dcSSimon Schubert { 107*5796c8dcSSimon Schubert const struct frame_base *desc = NULL; 108*5796c8dcSSimon Schubert desc = entry->sniffer (this_frame); 109*5796c8dcSSimon Schubert if (desc != NULL) 110*5796c8dcSSimon Schubert return desc; 111*5796c8dcSSimon Schubert } 112*5796c8dcSSimon Schubert return table->default_base; 113*5796c8dcSSimon Schubert } 114*5796c8dcSSimon Schubert 115*5796c8dcSSimon Schubert extern initialize_file_ftype _initialize_frame_base; /* -Wmissing-prototypes */ 116*5796c8dcSSimon Schubert 117*5796c8dcSSimon Schubert void 118*5796c8dcSSimon Schubert _initialize_frame_base (void) 119*5796c8dcSSimon Schubert { 120*5796c8dcSSimon Schubert frame_base_data = gdbarch_data_register_pre_init (frame_base_init); 121*5796c8dcSSimon Schubert } 122