Commit | Line | Data |
---|---|---|
da62e633 AC |
1 | /* Definitions for frame address handler, for GDB, the GNU debugger. |
2 | ||
0cad6aec | 3 | Copyright 2003, 2004 Free Software Foundation, Inc. |
da62e633 AC |
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" | |
0cad6aec | 25 | #include "gdb_obstack.h" |
da62e633 AC |
26 | |
27 | /* A default frame base implementations. If it wasn't for the old | |
42efa47a AC |
28 | DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS, |
29 | these could be combined into a single function. All architectures | |
30 | really need to override this. */ | |
da62e633 AC |
31 | |
32 | static CORE_ADDR | |
33 | default_frame_base_address (struct frame_info *next_frame, void **this_cache) | |
34 | { | |
35 | struct frame_info *this_frame = get_prev_frame (next_frame); | |
36 | return get_frame_base (this_frame); /* sigh! */ | |
37 | } | |
38 | ||
39 | static CORE_ADDR | |
40 | default_frame_locals_address (struct frame_info *next_frame, void **this_cache) | |
41 | { | |
42efa47a AC |
42 | if (DEPRECATED_FRAME_LOCALS_ADDRESS_P ()) |
43 | { | |
44 | /* This is bad. The computation of per-frame locals address | |
45 | should use a per-frame frame-base. */ | |
46 | struct frame_info *this_frame = get_prev_frame (next_frame); | |
47 | return DEPRECATED_FRAME_LOCALS_ADDRESS (this_frame); | |
48 | } | |
49 | return default_frame_base_address (next_frame, this_cache); | |
da62e633 AC |
50 | } |
51 | ||
52 | static CORE_ADDR | |
53 | default_frame_args_address (struct frame_info *next_frame, void **this_cache) | |
54 | { | |
42efa47a AC |
55 | if (DEPRECATED_FRAME_ARGS_ADDRESS_P ()) |
56 | { | |
57 | struct frame_info *this_frame = get_prev_frame (next_frame); | |
58 | return DEPRECATED_FRAME_ARGS_ADDRESS (this_frame); | |
59 | } | |
60 | return default_frame_base_address (next_frame, this_cache); | |
da62e633 AC |
61 | } |
62 | ||
63 | const struct frame_base default_frame_base = { | |
64 | NULL, /* No parent. */ | |
65 | default_frame_base_address, | |
66 | default_frame_locals_address, | |
67 | default_frame_args_address | |
68 | }; | |
69 | ||
70 | static struct gdbarch_data *frame_base_data; | |
71 | ||
0cad6aec AC |
72 | struct frame_base_table_entry |
73 | { | |
74 | frame_base_sniffer_ftype *sniffer; | |
75 | struct frame_base_table_entry *next; | |
76 | }; | |
77 | ||
da62e633 AC |
78 | struct frame_base_table |
79 | { | |
0cad6aec AC |
80 | struct frame_base_table_entry *head; |
81 | struct frame_base_table_entry **tail; | |
da62e633 | 82 | const struct frame_base *default_base; |
da62e633 AC |
83 | }; |
84 | ||
85 | static void * | |
0cad6aec | 86 | frame_base_init (struct obstack *obstack) |
da62e633 | 87 | { |
0cad6aec AC |
88 | struct frame_base_table *table |
89 | = OBSTACK_ZALLOC (obstack, struct frame_base_table); | |
90 | table->tail = &table->head; | |
da62e633 AC |
91 | table->default_base = &default_frame_base; |
92 | return table; | |
93 | } | |
94 | ||
e8a89fe2 AC |
95 | void |
96 | frame_base_append_sniffer (struct gdbarch *gdbarch, | |
97 | frame_base_sniffer_ftype *sniffer) | |
98 | { | |
0cad6aec AC |
99 | struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); |
100 | (*table->tail) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_base_table_entry); | |
101 | (*table->tail)->sniffer = sniffer; | |
102 | table->tail = &(*table->tail)->next; | |
da62e633 AC |
103 | } |
104 | ||
105 | void | |
106 | frame_base_set_default (struct gdbarch *gdbarch, | |
107 | const struct frame_base *default_base) | |
108 | { | |
0cad6aec | 109 | struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); |
da62e633 AC |
110 | table->default_base = default_base; |
111 | } | |
112 | ||
113 | const struct frame_base * | |
e8a89fe2 | 114 | frame_base_find_by_frame (struct frame_info *next_frame) |
da62e633 | 115 | { |
e8a89fe2 | 116 | struct gdbarch *gdbarch = get_frame_arch (next_frame); |
0cad6aec AC |
117 | struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data); |
118 | struct frame_base_table_entry *entry; | |
119 | ||
120 | for (entry = table->head; entry != NULL; entry = entry->next) | |
da62e633 | 121 | { |
e8a89fe2 | 122 | const struct frame_base *desc = NULL; |
0cad6aec | 123 | desc = entry->sniffer (next_frame); |
da62e633 AC |
124 | if (desc != NULL) |
125 | return desc; | |
126 | } | |
127 | return table->default_base; | |
128 | } | |
129 | ||
a78f21af | 130 | extern initialize_file_ftype _initialize_frame_base; /* -Wmissing-prototypes */ |
b9362cc7 | 131 | |
da62e633 AC |
132 | void |
133 | _initialize_frame_base (void) | |
134 | { | |
0cad6aec | 135 | frame_base_data = gdbarch_data_register_pre_init (frame_base_init); |
da62e633 | 136 | } |