* dwarf2dbg.c (get_frag_fix): Revert 2001-11-15 change.
[deliverable/binutils-gdb.git] / gdb / frame-unwind.c
1 /* Definitions for frame unwinder, 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.h"
24 #include "frame-unwind.h"
25 #include "gdb_assert.h"
26 #include "dummy-frame.h"
27
28 static struct gdbarch_data *frame_unwind_data;
29
30 struct frame_unwind_table
31 {
32 frame_unwind_p_ftype **p;
33 frame_unwind_sniffer_ftype **sniffer;
34 int nr;
35 };
36
37 /* Append a predicate to the end of the table. */
38 static void
39 append_predicate (struct frame_unwind_table *table, frame_unwind_p_ftype *p,
40 frame_unwind_sniffer_ftype *sniffer)
41 {
42 table->p = xrealloc (table->p, ((table->nr + 1)
43 * sizeof (frame_unwind_p_ftype *)));
44 table->sniffer = xrealloc (table->sniffer, ((table->nr + 1)
45 * sizeof (frame_unwind_sniffer_ftype *)));
46 table->p[table->nr] = p;
47 table->sniffer[table->nr] = sniffer;
48 table->nr++;
49 }
50
51 static void *
52 frame_unwind_init (struct gdbarch *gdbarch)
53 {
54 struct frame_unwind_table *table = XCALLOC (1, struct frame_unwind_table);
55 append_predicate (table, dummy_frame_p, NULL);
56 return table;
57 }
58
59 static void
60 frame_unwind_free (struct gdbarch *gdbarch, void *data)
61 {
62 struct frame_unwind_table *table =
63 gdbarch_data (gdbarch, frame_unwind_data);
64 xfree (table->p);
65 xfree (table->sniffer);
66 xfree (table);
67 }
68
69 void
70 frame_unwind_append_predicate (struct gdbarch *gdbarch,
71 frame_unwind_p_ftype *p)
72 {
73 struct frame_unwind_table *table =
74 gdbarch_data (gdbarch, frame_unwind_data);
75 if (table == NULL)
76 {
77 /* ULGH, called during architecture initialization. Patch
78 things up. */
79 table = frame_unwind_init (gdbarch);
80 set_gdbarch_data (gdbarch, frame_unwind_data, table);
81 }
82 append_predicate (table, p, NULL);
83 }
84
85 void
86 frame_unwind_append_sniffer (struct gdbarch *gdbarch,
87 frame_unwind_sniffer_ftype *sniffer)
88 {
89 struct frame_unwind_table *table =
90 gdbarch_data (gdbarch, frame_unwind_data);
91 if (table == NULL)
92 {
93 /* ULGH, called during architecture initialization. Patch
94 things up. */
95 table = frame_unwind_init (gdbarch);
96 set_gdbarch_data (gdbarch, frame_unwind_data, table);
97 }
98 append_predicate (table, NULL, sniffer);
99 }
100
101 const struct frame_unwind *
102 frame_unwind_find_by_frame (struct frame_info *next_frame)
103 {
104 int i;
105 struct gdbarch *gdbarch = get_frame_arch (next_frame);
106 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
107 if (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES)
108 /* Seriously old code. Don't even try to use this new mechanism.
109 (Note: The variable USE_GENERIC_DUMMY_FRAMES is deprecated, not
110 the dummy frame mechanism. All architectures should be using
111 generic dummy frames). */
112 return legacy_saved_regs_unwind;
113 for (i = 0; i < table->nr; i++)
114 {
115 const struct frame_unwind *desc;
116 if (table->p[i] != NULL)
117 desc = table->p[i] (frame_pc_unwind (next_frame));
118 else if (table->sniffer[i] != NULL)
119 desc = table->sniffer[i] (next_frame);
120 else
121 internal_error (__FILE__, __LINE__, "Missing sniffer?");
122 if (desc != NULL)
123 return desc;
124 }
125 return legacy_saved_regs_unwind;
126 }
127
128 extern initialize_file_ftype _initialize_frame_unwind; /* -Wmissing-prototypes */
129
130 void
131 _initialize_frame_unwind (void)
132 {
133 frame_unwind_data = register_gdbarch_data (frame_unwind_init,
134 frame_unwind_free);
135 }
This page took 0.031938 seconds and 4 git commands to generate.