ad4689d3b7549ad09a68f5b3d104d0fd65b6de5b
[deliverable/binutils-gdb.git] / gdb / frame-base.c
1 /* Definitions for frame address handler, for GDB, the GNU debugger.
2
3 Copyright 2003 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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. */
21
22 #include "defs.h"
23 #include "frame-base.h"
24 #include "frame.h"
25
26 /* A default frame base implementations. If it wasn't for the old
27 FRAME_LOCALS_ADDRESS and FRAME_ARGS_ADDRESS, these could be
28 combined into a single function. All architectures really need to
29 override this. */
30
31 static CORE_ADDR
32 default_frame_base_address (struct frame_info *next_frame, void **this_cache)
33 {
34 struct frame_info *this_frame = get_prev_frame (next_frame);
35 return get_frame_base (this_frame); /* sigh! */
36 }
37
38 static CORE_ADDR
39 default_frame_locals_address (struct frame_info *next_frame, void **this_cache)
40 {
41 struct frame_info *this_frame = get_prev_frame (next_frame);
42 return FRAME_LOCALS_ADDRESS (this_frame);
43 }
44
45 static CORE_ADDR
46 default_frame_args_address (struct frame_info *next_frame, void **this_cache)
47 {
48 struct frame_info *this_frame = get_prev_frame (next_frame);
49 return FRAME_ARGS_ADDRESS (this_frame);
50 }
51
52 const struct frame_base default_frame_base = {
53 NULL, /* No parent. */
54 default_frame_base_address,
55 default_frame_locals_address,
56 default_frame_args_address
57 };
58
59 static struct gdbarch_data *frame_base_data;
60
61 struct frame_base_table
62 {
63 frame_base_p_ftype **p;
64 const struct frame_base *default_base;
65 int nr;
66 };
67
68 static void *
69 frame_base_init (struct gdbarch *gdbarch)
70 {
71 struct frame_base_table *table = XCALLOC (1, struct frame_base_table);
72 table->default_base = &default_frame_base;
73 return table;
74 }
75
76 static void
77 frame_base_free (struct gdbarch *gdbarch, void *data)
78 {
79 struct frame_base_table *table =
80 gdbarch_data (gdbarch, frame_base_data);
81 xfree (table->p);
82 xfree (table);
83 }
84
85 static struct frame_base_table *
86 frame_base_table (struct gdbarch *gdbarch)
87 {
88 struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);
89 if (table == NULL)
90 {
91 /* ULGH, called during architecture initialization. Patch
92 things up. */
93 table = frame_base_init (gdbarch);
94 set_gdbarch_data (gdbarch, frame_base_data, table);
95 }
96 return table;
97 }
98
99 /* Append a predicate to the end of the table. */
100 static void
101 append_predicate (struct frame_base_table *table, frame_base_p_ftype *p)
102 {
103 table->p = xrealloc (table->p, ((table->nr + 1)
104 * sizeof (frame_base_p_ftype *)));
105 table->p[table->nr] = p;
106 table->nr++;
107 }
108
109 void
110 frame_base_append_predicate (struct gdbarch *gdbarch,
111 frame_base_p_ftype *p)
112 {
113 struct frame_base_table *table = frame_base_table (gdbarch);
114 append_predicate (table, p);
115 }
116
117 void
118 frame_base_set_default (struct gdbarch *gdbarch,
119 const struct frame_base *default_base)
120 {
121 struct frame_base_table *table = frame_base_table (gdbarch);
122 table->default_base = default_base;
123 }
124
125 const struct frame_base *
126 frame_base_find_by_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
127 {
128 int i;
129 struct frame_base_table *table = frame_base_table (gdbarch);
130 for (i = 0; i < table->nr; i++)
131 {
132 const struct frame_base *desc = table->p[i] (pc);
133 if (desc != NULL)
134 return desc;
135 }
136 return table->default_base;
137 }
138
139 extern initialize_file_ftype _initialize_frame_base; /* -Wmissing-protypes */
140
141 void
142 _initialize_frame_base (void)
143 {
144 frame_base_data = register_gdbarch_data (frame_base_init,
145 frame_base_free);
146 }
This page took 0.045437 seconds and 3 git commands to generate.