Update
[gdb.git] / gdb / frame-unwind.c
blob3a2cb7a1f739d6e0f656cbd85c6d18795cb0b4b7
1 /* Definitions for frame unwinder, for GDB, the GNU debugger.
3 Copyright (C) 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
5 This file is part of GDB.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "frame.h"
22 #include "frame-unwind.h"
23 #include "gdb_assert.h"
24 #include "dummy-frame.h"
25 #include "gdb_obstack.h"
27 static struct gdbarch_data *frame_unwind_data;
29 struct frame_unwind_table_entry
31 frame_unwind_sniffer_ftype *sniffer;
32 const struct frame_unwind *unwinder;
33 struct frame_unwind_table_entry *next;
36 struct frame_unwind_table
38 struct frame_unwind_table_entry *list;
39 /* The head of the OSABI part of the search list. */
40 struct frame_unwind_table_entry **osabi_head;
43 static void *
44 frame_unwind_init (struct obstack *obstack)
46 struct frame_unwind_table *table
47 = OBSTACK_ZALLOC (obstack, struct frame_unwind_table);
48 /* Start the table out with a few default sniffers. OSABI code
49 can't override this. */
50 table->list = OBSTACK_ZALLOC (obstack, struct frame_unwind_table_entry);
51 table->list->unwinder = dummy_frame_unwind;
52 /* The insertion point for OSABI sniffers. */
53 table->osabi_head = &table->list->next;
54 return table;
57 void
58 frame_unwind_append_sniffer (struct gdbarch *gdbarch,
59 frame_unwind_sniffer_ftype *sniffer)
61 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
62 struct frame_unwind_table_entry **ip;
64 /* Find the end of the list and insert the new entry there. */
65 for (ip = table->osabi_head; (*ip) != NULL; ip = &(*ip)->next);
66 (*ip) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
67 (*ip)->sniffer = sniffer;
70 void
71 frame_unwind_prepend_unwinder (struct gdbarch *gdbarch,
72 const struct frame_unwind *unwinder)
74 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
75 struct frame_unwind_table_entry *entry;
77 /* Insert the new entry at the start of the list. */
78 entry = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
79 entry->unwinder = unwinder;
80 entry->next = (*table->osabi_head);
81 (*table->osabi_head) = entry;
84 const struct frame_unwind *
85 frame_unwind_find_by_frame (struct frame_info *next_frame, void **this_cache)
87 int i;
88 struct gdbarch *gdbarch = get_frame_arch (next_frame);
89 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
90 struct frame_unwind_table_entry *entry;
91 for (entry = table->list; entry != NULL; entry = entry->next)
93 if (entry->sniffer != NULL)
95 const struct frame_unwind *desc = NULL;
96 desc = entry->sniffer (next_frame);
97 if (desc != NULL)
98 return desc;
100 if (entry->unwinder != NULL)
102 if (entry->unwinder->sniffer (entry->unwinder, next_frame,
103 this_cache))
104 return entry->unwinder;
107 internal_error (__FILE__, __LINE__, _("frame_unwind_find_by_frame failed"));
110 extern initialize_file_ftype _initialize_frame_unwind; /* -Wmissing-prototypes */
112 void
113 _initialize_frame_unwind (void)
115 frame_unwind_data = gdbarch_data_register_pre_init (frame_unwind_init);