2003-01-18 Andrew Cagney <ac131313@redhat.com>
[deliverable/binutils-gdb.git] / gdb / frame-unwind.c
CommitLineData
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
28static struct gdbarch_data *frame_unwind_data;
29
30struct frame_unwind_table
31{
32 frame_unwind_p_ftype **p;
33 int middle;
34 int nr;
35};
36
37/* Append a predicate to the end of the table. */
38static void
39append_predicate (struct frame_unwind_table *table, frame_unwind_p_ftype *p)
40{
41 table->p = xrealloc (table->p, ((table->nr + 1)
42 * sizeof (frame_unwind_p_ftype *)));
43 table->p[table->nr] = p;
44 table->nr++;
45}
46
47static void *
48frame_unwind_init (struct gdbarch *gdbarch)
49{
50 struct frame_unwind_table *table = XCALLOC (1, struct frame_unwind_table);
51 append_predicate (table, dummy_frame_p);
52 return table;
53}
54
55static void
56frame_unwind_free (struct gdbarch *gdbarch, void *data)
57{
58 struct frame_unwind_table *table =
59 gdbarch_data (gdbarch, frame_unwind_data);
60 xfree (table->p);
61 xfree (table);
62}
63
64void
65frame_unwind_append_predicate (struct gdbarch *gdbarch,
66 frame_unwind_p_ftype *p)
67{
68 struct frame_unwind_table *table =
69 gdbarch_data (gdbarch, frame_unwind_data);
70 if (table == NULL)
71 {
72 /* ULGH, called during architecture initialization. Patch
73 things up. */
74 table = frame_unwind_init (gdbarch);
75 set_gdbarch_data (gdbarch, frame_unwind_data, table);
76 }
77 append_predicate (table, p);
78}
79
80const struct frame_unwind *
81frame_unwind_find_by_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
82{
83 int i;
84 struct frame_unwind_table *table =
85 gdbarch_data (gdbarch, frame_unwind_data);
86 /* Seriously old code. Don't even try to use this new mechanism. */
87 if (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES)
88 return trad_frame_unwind;
89 for (i = 0; i < table->nr; i++)
90 {
91 const struct frame_unwind *desc = table->p[i] (pc);
92 if (desc != NULL)
93 return desc;
94 }
95 return trad_frame_unwind;
96}
97
98void
99_initialize_frame_unwind (void)
100{
101 frame_unwind_data = register_gdbarch_data (frame_unwind_init,
102 frame_unwind_free);
103}
This page took 0.031386 seconds and 4 git commands to generate.