]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/frame-unwind.c
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / frame-unwind.c
CommitLineData
494cca16
AC
1/* Definitions for frame unwinder, for GDB, the GNU debugger.
2
6aba47ca 3 Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
494cca16
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
197e01b6
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
494cca16
AC
21
22#include "defs.h"
23#include "frame.h"
24#include "frame-unwind.h"
25#include "gdb_assert.h"
26#include "dummy-frame.h"
41fe5eb3 27#include "gdb_obstack.h"
494cca16
AC
28
29static struct gdbarch_data *frame_unwind_data;
30
41fe5eb3 31struct frame_unwind_table_entry
494cca16 32{
41fe5eb3 33 frame_unwind_sniffer_ftype *sniffer;
82417da5 34 const struct frame_unwind *unwinder;
41fe5eb3 35 struct frame_unwind_table_entry *next;
494cca16
AC
36};
37
41fe5eb3 38struct frame_unwind_table
494cca16 39{
fb2be677
AC
40 struct frame_unwind_table_entry *list;
41 /* The head of the OSABI part of the search list. */
42 struct frame_unwind_table_entry **osabi_head;
41fe5eb3 43};
494cca16
AC
44
45static void *
41fe5eb3 46frame_unwind_init (struct obstack *obstack)
494cca16 47{
41fe5eb3
AC
48 struct frame_unwind_table *table
49 = OBSTACK_ZALLOC (obstack, struct frame_unwind_table);
fb2be677
AC
50 /* Start the table out with a few default sniffers. OSABI code
51 can't override this. */
52 table->list = OBSTACK_ZALLOC (obstack, struct frame_unwind_table_entry);
d67ec5db 53 table->list->unwinder = dummy_frame_unwind;
fb2be677
AC
54 /* The insertion point for OSABI sniffers. */
55 table->osabi_head = &table->list->next;
494cca16
AC
56 return table;
57}
58
e8a89fe2
AC
59void
60frame_unwind_append_sniffer (struct gdbarch *gdbarch,
61 frame_unwind_sniffer_ftype *sniffer)
494cca16 62{
41fe5eb3 63 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
fb2be677
AC
64 struct frame_unwind_table_entry **ip;
65
66 /* Find the end of the list and insert the new entry there. */
67 for (ip = table->osabi_head; (*ip) != NULL; ip = &(*ip)->next);
68 (*ip) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
69 (*ip)->sniffer = sniffer;
e8a89fe2
AC
70}
71
82417da5 72void
fb2be677 73frame_unwind_prepend_unwinder (struct gdbarch *gdbarch,
82417da5
AC
74 const struct frame_unwind *unwinder)
75{
76 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
fb2be677
AC
77 struct frame_unwind_table_entry *entry;
78
79 /* Insert the new entry at the start of the list. */
80 entry = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
81 entry->unwinder = unwinder;
82 entry->next = (*table->osabi_head);
83 (*table->osabi_head) = entry;
82417da5
AC
84}
85
e8a89fe2 86const struct frame_unwind *
82417da5 87frame_unwind_find_by_frame (struct frame_info *next_frame, void **this_cache)
e8a89fe2
AC
88{
89 int i;
90 struct gdbarch *gdbarch = get_frame_arch (next_frame);
91 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
41fe5eb3 92 struct frame_unwind_table_entry *entry;
fb2be677 93 for (entry = table->list; entry != NULL; entry = entry->next)
494cca16 94 {
82417da5
AC
95 if (entry->sniffer != NULL)
96 {
97 const struct frame_unwind *desc = NULL;
98 desc = entry->sniffer (next_frame);
99 if (desc != NULL)
100 return desc;
101 }
102 if (entry->unwinder != NULL)
103 {
104 if (entry->unwinder->sniffer (entry->unwinder, next_frame,
105 this_cache))
106 return entry->unwinder;
107 }
494cca16 108 }
e2e0b3e5 109 internal_error (__FILE__, __LINE__, _("frame_unwind_find_by_frame failed"));
494cca16
AC
110}
111
b9362cc7
AC
112extern initialize_file_ftype _initialize_frame_unwind; /* -Wmissing-prototypes */
113
494cca16
AC
114void
115_initialize_frame_unwind (void)
116{
41fe5eb3 117 frame_unwind_data = gdbarch_data_register_pre_init (frame_unwind_init);
494cca16 118}