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