GDB (API)
/home/stan/gdb/src/gdb/frame-base.c
Go to the documentation of this file.
00001 /* Definitions for frame address handler, for GDB, the GNU debugger.
00002 
00003    Copyright (C) 2003-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "frame-base.h"
00022 #include "frame.h"
00023 #include "gdb_obstack.h"
00024 
00025 /* A default frame base implementations.  If it wasn't for the old
00026    DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS,
00027    these could be combined into a single function.  All architectures
00028    really need to override this.  */
00029 
00030 static CORE_ADDR
00031 default_frame_base_address (struct frame_info *this_frame, void **this_cache)
00032 {
00033   return get_frame_base (this_frame); /* sigh! */
00034 }
00035 
00036 static CORE_ADDR
00037 default_frame_locals_address (struct frame_info *this_frame, void **this_cache)
00038 {
00039   return default_frame_base_address (this_frame, this_cache);
00040 }
00041 
00042 static CORE_ADDR
00043 default_frame_args_address (struct frame_info *this_frame, void **this_cache)
00044 {
00045   return default_frame_base_address (this_frame, this_cache);
00046 }
00047 
00048 const struct frame_base default_frame_base = {
00049   NULL, /* No parent.  */
00050   default_frame_base_address,
00051   default_frame_locals_address,
00052   default_frame_args_address
00053 };
00054 
00055 static struct gdbarch_data *frame_base_data;
00056 
00057 struct frame_base_table_entry
00058 {
00059   frame_base_sniffer_ftype *sniffer;
00060   struct frame_base_table_entry *next;
00061 };
00062 
00063 struct frame_base_table
00064 {
00065   struct frame_base_table_entry *head;
00066   struct frame_base_table_entry **tail;
00067   const struct frame_base *default_base;
00068 };
00069 
00070 static void *
00071 frame_base_init (struct obstack *obstack)
00072 {
00073   struct frame_base_table *table
00074     = OBSTACK_ZALLOC (obstack, struct frame_base_table);
00075 
00076   table->tail = &table->head;
00077   table->default_base = &default_frame_base;
00078   return table;
00079 }
00080 
00081 void
00082 frame_base_append_sniffer (struct gdbarch *gdbarch,
00083                            frame_base_sniffer_ftype *sniffer)
00084 {
00085   struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);
00086 
00087   (*table->tail)
00088     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_base_table_entry);
00089   (*table->tail)->sniffer = sniffer;
00090   table->tail = &(*table->tail)->next;
00091 }
00092 
00093 void
00094 frame_base_set_default (struct gdbarch *gdbarch,
00095                         const struct frame_base *default_base)
00096 {
00097   struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);
00098 
00099   table->default_base = default_base;
00100 }
00101 
00102 const struct frame_base *
00103 frame_base_find_by_frame (struct frame_info *this_frame)
00104 {
00105   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00106   struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);
00107   struct frame_base_table_entry *entry;
00108 
00109   for (entry = table->head; entry != NULL; entry = entry->next)
00110     {
00111       const struct frame_base *desc = NULL;
00112 
00113       desc = entry->sniffer (this_frame);
00114       if (desc != NULL)
00115         return desc;
00116     }
00117   return table->default_base;
00118 }
00119 
00120 extern initialize_file_ftype _initialize_frame_base; /* -Wmissing-prototypes */
00121 
00122 void
00123 _initialize_frame_base (void)
00124 {
00125   frame_base_data = gdbarch_data_register_pre_init (frame_base_init);
00126 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines