]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/frame-base.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / frame-base.c
CommitLineData
da62e633
AC
1/* Definitions for frame address handler, for GDB, the GNU debugger.
2
1d506c26 3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
da62e633
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
da62e633
AC
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
da62e633 19
da62e633
AC
20#include "frame-base.h"
21#include "frame.h"
bf31fd38 22#include "gdbsupport/gdb_obstack.h"
0d12e84c 23#include "gdbarch.h"
da62e633
AC
24
25/* A default frame base implementations. If it wasn't for the old
42efa47a
AC
26 DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS,
27 these could be combined into a single function. All architectures
28 really need to override this. */
da62e633
AC
29
30static CORE_ADDR
8480a37e 31default_frame_base_address (const frame_info_ptr &this_frame, void **this_cache)
da62e633 32{
da62e633
AC
33 return get_frame_base (this_frame); /* sigh! */
34}
35
36static CORE_ADDR
8480a37e 37default_frame_locals_address (const frame_info_ptr &this_frame, void **this_cache)
da62e633 38{
669fac23 39 return default_frame_base_address (this_frame, this_cache);
da62e633
AC
40}
41
42static CORE_ADDR
8480a37e 43default_frame_args_address (const frame_info_ptr &this_frame, void **this_cache)
da62e633 44{
669fac23 45 return default_frame_base_address (this_frame, this_cache);
da62e633
AC
46}
47
48const struct frame_base default_frame_base = {
49 NULL, /* No parent. */
50 default_frame_base_address,
51 default_frame_locals_address,
52 default_frame_args_address
53};
54
0cad6aec
AC
55struct frame_base_table_entry
56{
57 frame_base_sniffer_ftype *sniffer;
58 struct frame_base_table_entry *next;
59};
60
da62e633
AC
61struct frame_base_table
62{
cb275538
TT
63 struct frame_base_table_entry *head = nullptr;
64 struct frame_base_table_entry **tail = &head;
65 const struct frame_base *default_base = &default_frame_base;
da62e633
AC
66};
67
cb275538 68static const registry<gdbarch>::key<struct frame_base_table> frame_base_data;
bb9bcb69 69
cb275538
TT
70static struct frame_base_table *
71get_frame_base_table (struct gdbarch *gdbarch)
72{
73 struct frame_base_table *table = frame_base_data.get (gdbarch);
74 if (table == nullptr)
75 table = frame_base_data.emplace (gdbarch);
da62e633
AC
76 return table;
77}
78
e8a89fe2
AC
79void
80frame_base_append_sniffer (struct gdbarch *gdbarch,
81 frame_base_sniffer_ftype *sniffer)
82{
cb275538 83 struct frame_base_table *table = get_frame_base_table (gdbarch);
bb9bcb69 84
3e43a32a
MS
85 (*table->tail)
86 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_base_table_entry);
0cad6aec
AC
87 (*table->tail)->sniffer = sniffer;
88 table->tail = &(*table->tail)->next;
da62e633
AC
89}
90
91void
92frame_base_set_default (struct gdbarch *gdbarch,
93 const struct frame_base *default_base)
94{
cb275538 95 struct frame_base_table *table = get_frame_base_table (gdbarch);
bb9bcb69 96
da62e633
AC
97 table->default_base = default_base;
98}
99
100const struct frame_base *
8480a37e 101frame_base_find_by_frame (const frame_info_ptr &this_frame)
da62e633 102{
669fac23 103 struct gdbarch *gdbarch = get_frame_arch (this_frame);
cb275538 104 struct frame_base_table *table = get_frame_base_table (gdbarch);
0cad6aec
AC
105 struct frame_base_table_entry *entry;
106
107 for (entry = table->head; entry != NULL; entry = entry->next)
da62e633 108 {
e8a89fe2 109 const struct frame_base *desc = NULL;
bb9bcb69 110
669fac23 111 desc = entry->sniffer (this_frame);
da62e633
AC
112 if (desc != NULL)
113 return desc;
114 }
115 return table->default_base;
116}