]>
Commit | Line | Data |
---|---|---|
da62e633 AC |
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 | /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except | |
50 | that if it is unsure about the answer, it returns 0 instead of | |
51 | guessing (this happens on the VAX and i960, for example). | |
52 | ||
53 | On most machines, we never have to guess about the args address, | |
54 | so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */ | |
55 | #ifdef FRAME_ARGS_ADDRESS_CORRECT | |
56 | return FRAME_ARGS_ADDRESS_CORRECT (this_frame); | |
57 | #else | |
58 | return FRAME_ARGS_ADDRESS (this_frame); | |
59 | #endif | |
60 | } | |
61 | ||
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 | |
67 | }; | |
68 | ||
69 | static struct gdbarch_data *frame_base_data; | |
70 | ||
71 | struct frame_base_table | |
72 | { | |
73 | frame_base_p_ftype **p; | |
74 | const struct frame_base *default_base; | |
75 | int nr; | |
76 | }; | |
77 | ||
78 | static void * | |
79 | frame_base_init (struct gdbarch *gdbarch) | |
80 | { | |
81 | struct frame_base_table *table = XCALLOC (1, struct frame_base_table); | |
82 | table->default_base = &default_frame_base; | |
83 | return table; | |
84 | } | |
85 | ||
86 | static void | |
87 | frame_base_free (struct gdbarch *gdbarch, void *data) | |
88 | { | |
89 | struct frame_base_table *table = | |
90 | gdbarch_data (gdbarch, frame_base_data); | |
91 | xfree (table->p); | |
92 | xfree (table); | |
93 | } | |
94 | ||
95 | static struct frame_base_table * | |
96 | frame_base_table (struct gdbarch *gdbarch) | |
97 | { | |
98 | struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); | |
99 | if (table == NULL) | |
100 | { | |
101 | /* ULGH, called during architecture initialization. Patch | |
102 | things up. */ | |
103 | table = frame_base_init (gdbarch); | |
104 | set_gdbarch_data (gdbarch, frame_base_data, table); | |
105 | } | |
106 | return table; | |
107 | } | |
108 | ||
109 | /* Append a predicate to the end of the table. */ | |
110 | static void | |
111 | append_predicate (struct frame_base_table *table, frame_base_p_ftype *p) | |
112 | { | |
113 | table->p = xrealloc (table->p, ((table->nr + 1) | |
114 | * sizeof (frame_base_p_ftype *))); | |
115 | table->p[table->nr] = p; | |
116 | table->nr++; | |
117 | } | |
118 | ||
119 | void | |
120 | frame_base_append_predicate (struct gdbarch *gdbarch, | |
121 | frame_base_p_ftype *p) | |
122 | { | |
123 | struct frame_base_table *table = frame_base_table (gdbarch); | |
124 | append_predicate (table, p); | |
125 | } | |
126 | ||
127 | void | |
128 | frame_base_set_default (struct gdbarch *gdbarch, | |
129 | const struct frame_base *default_base) | |
130 | { | |
131 | struct frame_base_table *table = frame_base_table (gdbarch); | |
132 | table->default_base = default_base; | |
133 | } | |
134 | ||
135 | const struct frame_base * | |
136 | frame_base_find_by_pc (struct gdbarch *gdbarch, CORE_ADDR pc) | |
137 | { | |
138 | int i; | |
139 | struct frame_base_table *table = frame_base_table (gdbarch); | |
140 | for (i = 0; i < table->nr; i++) | |
141 | { | |
142 | const struct frame_base *desc = table->p[i] (pc); | |
143 | if (desc != NULL) | |
144 | return desc; | |
145 | } | |
146 | return table->default_base; | |
147 | } | |
148 | ||
149 | void | |
150 | _initialize_frame_base (void) | |
151 | { | |
152 | frame_base_data = register_gdbarch_data (frame_base_init, | |
153 | frame_base_free); | |
154 | } |