xref: /openbsd-src/gnu/usr.bin/binutils/gdb/frame-unwind.c (revision 11efff7f3ac2b3cfeff0c0cddc14294d9b3aca4f)
1b725ae77Skettenis /* Definitions for frame unwinder, for GDB, the GNU debugger.
2b725ae77Skettenis 
3*11efff7fSkettenis    Copyright 2003, 2004 Free Software Foundation, Inc.
4b725ae77Skettenis 
5b725ae77Skettenis    This file is part of GDB.
6b725ae77Skettenis 
7b725ae77Skettenis    This program is free software; you can redistribute it and/or modify
8b725ae77Skettenis    it under the terms of the GNU General Public License as published by
9b725ae77Skettenis    the Free Software Foundation; either version 2 of the License, or
10b725ae77Skettenis    (at your option) any later version.
11b725ae77Skettenis 
12b725ae77Skettenis    This program is distributed in the hope that it will be useful,
13b725ae77Skettenis    but WITHOUT ANY WARRANTY; without even the implied warranty of
14b725ae77Skettenis    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15b725ae77Skettenis    GNU General Public License for more details.
16b725ae77Skettenis 
17b725ae77Skettenis    You should have received a copy of the GNU General Public License
18b725ae77Skettenis    along with this program; if not, write to the Free Software
19b725ae77Skettenis    Foundation, Inc., 59 Temple Place - Suite 330,
20b725ae77Skettenis    Boston, MA 02111-1307, USA.  */
21b725ae77Skettenis 
22b725ae77Skettenis #include "defs.h"
23b725ae77Skettenis #include "frame.h"
24b725ae77Skettenis #include "frame-unwind.h"
25b725ae77Skettenis #include "gdb_assert.h"
26b725ae77Skettenis #include "dummy-frame.h"
27*11efff7fSkettenis #include "gdb_obstack.h"
28b725ae77Skettenis 
29b725ae77Skettenis static struct gdbarch_data *frame_unwind_data;
30b725ae77Skettenis 
31*11efff7fSkettenis struct frame_unwind_table_entry
32b725ae77Skettenis {
33*11efff7fSkettenis   frame_unwind_sniffer_ftype *sniffer;
34*11efff7fSkettenis   const struct frame_unwind *unwinder;
35*11efff7fSkettenis   struct frame_unwind_table_entry *next;
36b725ae77Skettenis };
37b725ae77Skettenis 
38*11efff7fSkettenis struct frame_unwind_table
39b725ae77Skettenis {
40*11efff7fSkettenis   struct frame_unwind_table_entry *list;
41*11efff7fSkettenis   /* The head of the OSABI part of the search list.  */
42*11efff7fSkettenis   struct frame_unwind_table_entry **osabi_head;
43*11efff7fSkettenis };
44b725ae77Skettenis 
45b725ae77Skettenis static void *
frame_unwind_init(struct obstack * obstack)46*11efff7fSkettenis frame_unwind_init (struct obstack *obstack)
47b725ae77Skettenis {
48*11efff7fSkettenis   struct frame_unwind_table *table
49*11efff7fSkettenis     = OBSTACK_ZALLOC (obstack, struct frame_unwind_table);
50*11efff7fSkettenis   /* Start the table out with a few default sniffers.  OSABI code
51*11efff7fSkettenis      can't override this.  */
52*11efff7fSkettenis   table->list = OBSTACK_ZALLOC (obstack, struct frame_unwind_table_entry);
53*11efff7fSkettenis   table->list->unwinder = dummy_frame_unwind;
54*11efff7fSkettenis   /* The insertion point for OSABI sniffers.  */
55*11efff7fSkettenis   table->osabi_head = &table->list->next;
56b725ae77Skettenis   return table;
57b725ae77Skettenis }
58b725ae77Skettenis 
59b725ae77Skettenis void
frame_unwind_append_sniffer(struct gdbarch * gdbarch,frame_unwind_sniffer_ftype * sniffer)60b725ae77Skettenis frame_unwind_append_sniffer (struct gdbarch *gdbarch,
61b725ae77Skettenis 			     frame_unwind_sniffer_ftype *sniffer)
62b725ae77Skettenis {
63*11efff7fSkettenis   struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
64*11efff7fSkettenis   struct frame_unwind_table_entry **ip;
65*11efff7fSkettenis 
66*11efff7fSkettenis   /* Find the end of the list and insert the new entry there.  */
67*11efff7fSkettenis   for (ip = table->osabi_head; (*ip) != NULL; ip = &(*ip)->next);
68*11efff7fSkettenis   (*ip) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
69*11efff7fSkettenis   (*ip)->sniffer = sniffer;
70b725ae77Skettenis }
71*11efff7fSkettenis 
72*11efff7fSkettenis void
frame_unwind_prepend_unwinder(struct gdbarch * gdbarch,const struct frame_unwind * unwinder)73*11efff7fSkettenis frame_unwind_prepend_unwinder (struct gdbarch *gdbarch,
74*11efff7fSkettenis 				const struct frame_unwind *unwinder)
75*11efff7fSkettenis {
76*11efff7fSkettenis   struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
77*11efff7fSkettenis   struct frame_unwind_table_entry *entry;
78*11efff7fSkettenis 
79*11efff7fSkettenis   /* Insert the new entry at the start of the list.  */
80*11efff7fSkettenis   entry = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
81*11efff7fSkettenis   entry->unwinder = unwinder;
82*11efff7fSkettenis   entry->next = (*table->osabi_head);
83*11efff7fSkettenis   (*table->osabi_head) = entry;
84b725ae77Skettenis }
85b725ae77Skettenis 
86b725ae77Skettenis const struct frame_unwind *
frame_unwind_find_by_frame(struct frame_info * next_frame,void ** this_cache)87*11efff7fSkettenis frame_unwind_find_by_frame (struct frame_info *next_frame, void **this_cache)
88b725ae77Skettenis {
89b725ae77Skettenis   int i;
90b725ae77Skettenis   struct gdbarch *gdbarch = get_frame_arch (next_frame);
91b725ae77Skettenis   struct frame_unwind_table *table = gdbarch_data (gdbarch, frame_unwind_data);
92*11efff7fSkettenis   struct frame_unwind_table_entry *entry;
93*11efff7fSkettenis   for (entry = table->list; entry != NULL; entry = entry->next)
94b725ae77Skettenis     {
95*11efff7fSkettenis       if (entry->sniffer != NULL)
96*11efff7fSkettenis 	{
97*11efff7fSkettenis 	  const struct frame_unwind *desc = NULL;
98*11efff7fSkettenis 	  desc = entry->sniffer (next_frame);
99b725ae77Skettenis 	  if (desc != NULL)
100b725ae77Skettenis 	    return desc;
101b725ae77Skettenis 	}
102*11efff7fSkettenis       if (entry->unwinder != NULL)
103*11efff7fSkettenis 	{
104*11efff7fSkettenis 	  if (entry->unwinder->sniffer (entry->unwinder, next_frame,
105*11efff7fSkettenis 					this_cache))
106*11efff7fSkettenis 	    return entry->unwinder;
107*11efff7fSkettenis 	}
108*11efff7fSkettenis     }
109*11efff7fSkettenis   internal_error (__FILE__, __LINE__, "frame_unwind_find_by_frame failed");
110b725ae77Skettenis }
111b725ae77Skettenis 
112b725ae77Skettenis extern initialize_file_ftype _initialize_frame_unwind; /* -Wmissing-prototypes */
113b725ae77Skettenis 
114b725ae77Skettenis void
_initialize_frame_unwind(void)115b725ae77Skettenis _initialize_frame_unwind (void)
116b725ae77Skettenis {
117*11efff7fSkettenis   frame_unwind_data = gdbarch_data_register_pre_init (frame_unwind_init);
118b725ae77Skettenis }
119