1 /* Definitions for frame address handler, for GDB, the GNU debugger.
3 Copyright 2003 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "frame-base.h"
26 /* A default frame base implementations. If it wasn't for the old
27 DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS,
28 these could be combined into a single function. All architectures
29 really need to override this. */
32 default_frame_base_address (struct frame_info *next_frame, void **this_cache)
34 struct frame_info *this_frame = get_prev_frame (next_frame);
35 return get_frame_base (this_frame); /* sigh! */
39 default_frame_locals_address (struct frame_info *next_frame, void **this_cache)
41 if (DEPRECATED_FRAME_LOCALS_ADDRESS_P ())
43 /* This is bad. The computation of per-frame locals address
44 should use a per-frame frame-base. */
45 struct frame_info *this_frame = get_prev_frame (next_frame);
46 return DEPRECATED_FRAME_LOCALS_ADDRESS (this_frame);
48 return default_frame_base_address (next_frame, this_cache);
52 default_frame_args_address (struct frame_info *next_frame, void **this_cache)
54 if (DEPRECATED_FRAME_ARGS_ADDRESS_P ())
56 struct frame_info *this_frame = get_prev_frame (next_frame);
57 return DEPRECATED_FRAME_ARGS_ADDRESS (this_frame);
59 return default_frame_base_address (next_frame, this_cache);
62 const struct frame_base default_frame_base = {
63 NULL, /* No parent. */
64 default_frame_base_address,
65 default_frame_locals_address,
66 default_frame_args_address
69 static struct gdbarch_data *frame_base_data;
71 struct frame_base_table
73 frame_base_sniffer_ftype **sniffer;
74 const struct frame_base *default_base;
79 frame_base_init (struct gdbarch *gdbarch)
81 struct frame_base_table *table = XCALLOC (1, struct frame_base_table);
82 table->default_base = &default_frame_base;
86 static struct frame_base_table *
87 frame_base_table (struct gdbarch *gdbarch)
89 struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);
92 /* ULGH, called during architecture initialization. Patch
94 table = frame_base_init (gdbarch);
95 deprecated_set_gdbarch_data (gdbarch, frame_base_data, table);
100 /* Append a predicate to the end of the table. */
102 append_predicate (struct frame_base_table *table,
103 frame_base_sniffer_ftype *sniffer)
105 table->sniffer = xrealloc (table->sniffer,
107 * sizeof (frame_base_sniffer_ftype *)));
108 table->sniffer[table->nr] = sniffer;
113 frame_base_append_sniffer (struct gdbarch *gdbarch,
114 frame_base_sniffer_ftype *sniffer)
116 struct frame_base_table *table = frame_base_table (gdbarch);
117 append_predicate (table, sniffer);
121 frame_base_set_default (struct gdbarch *gdbarch,
122 const struct frame_base *default_base)
124 struct frame_base_table *table = frame_base_table (gdbarch);
125 table->default_base = default_base;
128 const struct frame_base *
129 frame_base_find_by_frame (struct frame_info *next_frame)
131 struct gdbarch *gdbarch = get_frame_arch (next_frame);
132 struct frame_base_table *table = frame_base_table (gdbarch);
134 for (i = 0; i < table->nr; i++)
136 const struct frame_base *desc = NULL;
137 desc = table->sniffer[i] (next_frame);
141 return table->default_base;
144 extern initialize_file_ftype _initialize_frame_base; /* -Wmissing-prototypes */
147 _initialize_frame_base (void)
149 frame_base_data = gdbarch_data_register_post_init (frame_base_init);