xref: /dflybsd-src/contrib/gdb-7/gdb/frame-base.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Definitions for frame address handler, for GDB, the GNU debugger.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 2003-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "frame-base.h"
225796c8dcSSimon Schubert #include "frame.h"
235796c8dcSSimon Schubert #include "gdb_obstack.h"
245796c8dcSSimon Schubert 
255796c8dcSSimon Schubert /* A default frame base implementations.  If it wasn't for the old
265796c8dcSSimon Schubert    DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS,
275796c8dcSSimon Schubert    these could be combined into a single function.  All architectures
285796c8dcSSimon Schubert    really need to override this.  */
295796c8dcSSimon Schubert 
305796c8dcSSimon Schubert static CORE_ADDR
default_frame_base_address(struct frame_info * this_frame,void ** this_cache)315796c8dcSSimon Schubert default_frame_base_address (struct frame_info *this_frame, void **this_cache)
325796c8dcSSimon Schubert {
335796c8dcSSimon Schubert   return get_frame_base (this_frame); /* sigh! */
345796c8dcSSimon Schubert }
355796c8dcSSimon Schubert 
365796c8dcSSimon Schubert static CORE_ADDR
default_frame_locals_address(struct frame_info * this_frame,void ** this_cache)375796c8dcSSimon Schubert default_frame_locals_address (struct frame_info *this_frame, void **this_cache)
385796c8dcSSimon Schubert {
395796c8dcSSimon Schubert   return default_frame_base_address (this_frame, this_cache);
405796c8dcSSimon Schubert }
415796c8dcSSimon Schubert 
425796c8dcSSimon Schubert static CORE_ADDR
default_frame_args_address(struct frame_info * this_frame,void ** this_cache)435796c8dcSSimon Schubert default_frame_args_address (struct frame_info *this_frame, void **this_cache)
445796c8dcSSimon Schubert {
455796c8dcSSimon Schubert   return default_frame_base_address (this_frame, this_cache);
465796c8dcSSimon Schubert }
475796c8dcSSimon Schubert 
485796c8dcSSimon Schubert const struct frame_base default_frame_base = {
495796c8dcSSimon Schubert   NULL, /* No parent.  */
505796c8dcSSimon Schubert   default_frame_base_address,
515796c8dcSSimon Schubert   default_frame_locals_address,
525796c8dcSSimon Schubert   default_frame_args_address
535796c8dcSSimon Schubert };
545796c8dcSSimon Schubert 
555796c8dcSSimon Schubert static struct gdbarch_data *frame_base_data;
565796c8dcSSimon Schubert 
575796c8dcSSimon Schubert struct frame_base_table_entry
585796c8dcSSimon Schubert {
595796c8dcSSimon Schubert   frame_base_sniffer_ftype *sniffer;
605796c8dcSSimon Schubert   struct frame_base_table_entry *next;
615796c8dcSSimon Schubert };
625796c8dcSSimon Schubert 
635796c8dcSSimon Schubert struct frame_base_table
645796c8dcSSimon Schubert {
655796c8dcSSimon Schubert   struct frame_base_table_entry *head;
665796c8dcSSimon Schubert   struct frame_base_table_entry **tail;
675796c8dcSSimon Schubert   const struct frame_base *default_base;
685796c8dcSSimon Schubert };
695796c8dcSSimon Schubert 
705796c8dcSSimon Schubert static void *
frame_base_init(struct obstack * obstack)715796c8dcSSimon Schubert frame_base_init (struct obstack *obstack)
725796c8dcSSimon Schubert {
735796c8dcSSimon Schubert   struct frame_base_table *table
745796c8dcSSimon Schubert     = OBSTACK_ZALLOC (obstack, struct frame_base_table);
75cf7f2e2dSJohn Marino 
765796c8dcSSimon Schubert   table->tail = &table->head;
775796c8dcSSimon Schubert   table->default_base = &default_frame_base;
785796c8dcSSimon Schubert   return table;
795796c8dcSSimon Schubert }
805796c8dcSSimon Schubert 
815796c8dcSSimon Schubert void
frame_base_append_sniffer(struct gdbarch * gdbarch,frame_base_sniffer_ftype * sniffer)825796c8dcSSimon Schubert frame_base_append_sniffer (struct gdbarch *gdbarch,
835796c8dcSSimon Schubert 			   frame_base_sniffer_ftype *sniffer)
845796c8dcSSimon Schubert {
855796c8dcSSimon Schubert   struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);
86cf7f2e2dSJohn Marino 
87c50c785cSJohn Marino   (*table->tail)
88c50c785cSJohn Marino     = 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
frame_base_set_default(struct gdbarch * gdbarch,const struct frame_base * default_base)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);
98cf7f2e2dSJohn Marino 
995796c8dcSSimon Schubert   table->default_base = default_base;
1005796c8dcSSimon Schubert }
1015796c8dcSSimon Schubert 
1025796c8dcSSimon Schubert const struct frame_base *
frame_base_find_by_frame(struct frame_info * this_frame)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;
112cf7f2e2dSJohn 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
_initialize_frame_base(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