Commit | Line | Data |
---|---|---|
494cca16 AC |
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 | { | |
e8a89fe2 | 32 | frame_unwind_sniffer_ftype **sniffer; |
494cca16 AC |
33 | int nr; |
34 | }; | |
35 | ||
36 | /* Append a predicate to the end of the table. */ | |
37 | static void | |
336d1bba | 38 | append_predicate (struct frame_unwind_table *table, |
e8a89fe2 | 39 | frame_unwind_sniffer_ftype *sniffer) |
494cca16 | 40 | { |
e8a89fe2 AC |
41 | table->sniffer = xrealloc (table->sniffer, ((table->nr + 1) |
42 | * sizeof (frame_unwind_sniffer_ftype *))); | |
e8a89fe2 | 43 | table->sniffer[table->nr] = sniffer; |
494cca16 AC |
44 | table->nr++; |
45 | } | |
46 | ||
47 | static void * | |
48 | frame_unwind_init (struct gdbarch *gdbarch) | |
49 | { | |
50 | struct frame_unwind_table *table = XCALLOC (1, struct frame_unwind_table); | |
336d1bba | 51 | append_predicate (table, dummy_frame_sniffer); |
494cca16 AC |
52 | return table; |
53 | } | |
54 | ||
e8a89fe2 AC |
55 | void |
56 | frame_unwind_append_sniffer (struct gdbarch *gdbarch, | |
57 | frame_unwind_sniffer_ftype *sniffer) | |
494cca16 | 58 | { |
494cca16 AC |
59 | struct frame_unwind_table *table = |
60 | gdbarch_data (gdbarch, frame_unwind_data); | |
e8a89fe2 AC |
61 | if (table == NULL) |
62 | { | |
63 | /* ULGH, called during architecture initialization. Patch | |
64 | things up. */ | |
65 | table = frame_unwind_init (gdbarch); | |
030f20e1 | 66 | deprecated_set_gdbarch_data (gdbarch, frame_unwind_data, table); |
e8a89fe2 | 67 | } |
336d1bba | 68 | append_predicate (table, sniffer); |
e8a89fe2 AC |
69 | } |
70 | ||
71 | const struct frame_unwind * | |
72 | frame_unwind_find_by_frame (struct frame_info *next_frame) | |
73 | { | |
74 | int i; | |
75 | struct gdbarch *gdbarch = get_frame_arch (next_frame); | |
76 | struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data); | |
e7d7bd65 | 77 | if (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES && legacy_frame_p (gdbarch)) |
6dc42492 AC |
78 | /* Seriously old code. Don't even try to use this new mechanism. |
79 | (Note: The variable USE_GENERIC_DUMMY_FRAMES is deprecated, not | |
80 | the dummy frame mechanism. All architectures should be using | |
81 | generic dummy frames). */ | |
82 | return legacy_saved_regs_unwind; | |
494cca16 AC |
83 | for (i = 0; i < table->nr; i++) |
84 | { | |
e8a89fe2 | 85 | const struct frame_unwind *desc; |
336d1bba | 86 | desc = table->sniffer[i] (next_frame); |
494cca16 AC |
87 | if (desc != NULL) |
88 | return desc; | |
89 | } | |
6dc42492 | 90 | return legacy_saved_regs_unwind; |
494cca16 AC |
91 | } |
92 | ||
b9362cc7 AC |
93 | extern initialize_file_ftype _initialize_frame_unwind; /* -Wmissing-prototypes */ |
94 | ||
494cca16 AC |
95 | void |
96 | _initialize_frame_unwind (void) | |
97 | { | |
030f20e1 | 98 | frame_unwind_data = gdbarch_data_register_post_init (frame_unwind_init); |
494cca16 | 99 | } |