2004-04-03 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / frame-unwind.c
CommitLineData
494cca16
AC
1/* Definitions for frame unwinder, for GDB, the GNU debugger.
2
41fe5eb3 3 Copyright 2003, 2004 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
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"
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{
41fe5eb3
AC
40 struct frame_unwind_table_entry *head;
41 struct frame_unwind_table_entry **tail;
42};
494cca16
AC
43
44static void *
41fe5eb3 45frame_unwind_init (struct obstack *obstack)
494cca16 46{
41fe5eb3
AC
47 struct frame_unwind_table *table
48 = OBSTACK_ZALLOC (obstack, struct frame_unwind_table);
49 table->head = OBSTACK_ZALLOC (obstack, struct frame_unwind_table_entry);
50 table->head->sniffer = dummy_frame_sniffer;
51 table->tail = &table->head->next;
494cca16
AC
52 return table;
53}
54
e8a89fe2
AC
55void
56frame_unwind_append_sniffer (struct gdbarch *gdbarch,
57 frame_unwind_sniffer_ftype *sniffer)
494cca16 58{
41fe5eb3
AC
59 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
60 (*table->tail) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
61 (*table->tail)->sniffer = sniffer;
62 table->tail = &((*table->tail)->next);
e8a89fe2
AC
63}
64
82417da5
AC
65void
66frame_unwind_register_unwinder (struct gdbarch *gdbarch,
67 const struct frame_unwind *unwinder)
68{
69 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
70 (*table->tail) = GDBARCH_OBSTACK_ZALLOC (gdbarch,
71 struct frame_unwind_table_entry);
72 (*table->tail)->unwinder = unwinder;
73 table->tail = &((*table->tail)->next);
74}
75
e8a89fe2 76const struct frame_unwind *
82417da5 77frame_unwind_find_by_frame (struct frame_info *next_frame, void **this_cache)
e8a89fe2
AC
78{
79 int i;
80 struct gdbarch *gdbarch = get_frame_arch (next_frame);
81 struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
41fe5eb3 82 struct frame_unwind_table_entry *entry;
41fe5eb3 83 for (entry = table->head; entry != NULL; entry = entry->next)
494cca16 84 {
82417da5
AC
85 if (entry->sniffer != NULL)
86 {
87 const struct frame_unwind *desc = NULL;
88 desc = entry->sniffer (next_frame);
89 if (desc != NULL)
90 return desc;
91 }
92 if (entry->unwinder != NULL)
93 {
94 if (entry->unwinder->sniffer (entry->unwinder, next_frame,
95 this_cache))
96 return entry->unwinder;
97 }
494cca16 98 }
6dc42492 99 return legacy_saved_regs_unwind;
494cca16
AC
100}
101
b9362cc7
AC
102extern initialize_file_ftype _initialize_frame_unwind; /* -Wmissing-prototypes */
103
494cca16
AC
104void
105_initialize_frame_unwind (void)
106{
41fe5eb3 107 frame_unwind_data = gdbarch_data_register_pre_init (frame_unwind_init);
494cca16 108}
This page took 0.134847 seconds and 4 git commands to generate.