gdb, testsuite: Fix return value in gdb.base/foll-fork.exp
[binutils-gdb.git] / gdb / trad-frame.h
blobca8792baa17d20e932412b09ba65dcb98dcb0c5e
1 /* Traditional frame unwind support, for GDB the GNU Debugger.
3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef TRAD_FRAME_H
21 #define TRAD_FRAME_H
23 #include "frame.h"
25 class frame_info_ptr;
26 struct regcache_map_entry;
27 struct trad_frame_cache;
29 /* A simple, or traditional frame cache.
31 The entire cache is populated in a single pass and then generic
32 routines are used to extract the various cache values. */
34 struct trad_frame_cache *trad_frame_cache_zalloc (const frame_info_ptr &);
36 /* This frame's ID. */
37 void trad_frame_set_id (struct trad_frame_cache *this_trad_cache,
38 struct frame_id this_id);
39 void trad_frame_get_id (struct trad_frame_cache *this_trad_cache,
40 struct frame_id *this_id);
41 void trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache,
42 CORE_ADDR this_base);
43 CORE_ADDR trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache);
45 void trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache,
46 int regnum, int realreg);
47 void trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache,
48 int regnum, CORE_ADDR addr);
49 void trad_frame_set_reg_regmap (struct trad_frame_cache *this_trad_cache,
50 const struct regcache_map_entry *regmap,
51 CORE_ADDR addr, size_t size);
52 void trad_frame_set_reg_value (struct trad_frame_cache *this_cache,
53 int regnum, LONGEST val);
55 /* Given the cache in THIS_TRAD_CACHE, set the value of REGNUM to the bytes
56 contained in BYTES with size SIZE. */
57 void trad_frame_set_reg_value_bytes (struct trad_frame_cache *this_trad_cache,
58 int regnum,
59 gdb::array_view<const gdb_byte> bytes);
61 struct value *trad_frame_get_register (struct trad_frame_cache *this_trad_cache,
62 const frame_info_ptr &this_frame,
63 int regnum);
65 /* Describes the kind of encoding a stored register has. */
66 enum class trad_frame_saved_reg_kind
68 /* Register value is unknown. */
69 UNKNOWN = 0,
70 /* Register value is a constant. */
71 VALUE,
72 /* Register value is in another register. */
73 REALREG,
74 /* Register value is at an address. */
75 ADDR,
76 /* Register value is a sequence of bytes. */
77 VALUE_BYTES
80 /* A struct that describes a saved register in a frame. */
82 struct trad_frame_saved_reg
84 /* Setters */
86 /* Encode that the saved register's value is constant VAL in the
87 trad-frame. */
88 void set_value (LONGEST val)
90 m_kind = trad_frame_saved_reg_kind::VALUE;
91 m_reg.value = val;
94 /* Encode that the saved register's value is stored in register REALREG. */
95 void set_realreg (int realreg)
97 m_kind = trad_frame_saved_reg_kind::REALREG;
98 m_reg.realreg = realreg;
101 /* Encode that the saved register's value is stored in memory at ADDR. */
102 void set_addr (LONGEST addr)
104 m_kind = trad_frame_saved_reg_kind::ADDR;
105 m_reg.addr = addr;
108 /* Encode that the saved register's value is unknown. */
109 void set_unknown ()
111 m_kind = trad_frame_saved_reg_kind::UNKNOWN;
114 /* Encode that the saved register's value is stored as a sequence of bytes.
115 This is useful when the value is larger than what primitive types
116 can hold. */
117 void set_value_bytes (gdb::array_view<const gdb_byte> bytes)
119 /* Allocate the space and copy the data bytes. */
120 gdb_byte *data = FRAME_OBSTACK_CALLOC (bytes.size (), gdb_byte);
121 memcpy (data, bytes.data (), bytes.size ());
123 m_kind = trad_frame_saved_reg_kind::VALUE_BYTES;
124 m_reg.value_bytes = data;
127 /* Getters */
129 LONGEST value () const
131 gdb_assert (m_kind == trad_frame_saved_reg_kind::VALUE);
132 return m_reg.value;
135 int realreg () const
137 gdb_assert (m_kind == trad_frame_saved_reg_kind::REALREG);
138 return m_reg.realreg;
141 LONGEST addr () const
143 gdb_assert (m_kind == trad_frame_saved_reg_kind::ADDR);
144 return m_reg.addr;
147 const gdb_byte *value_bytes () const
149 gdb_assert (m_kind == trad_frame_saved_reg_kind::VALUE_BYTES);
150 return m_reg.value_bytes;
153 /* Convenience functions, return true if the register has been
154 encoded as specified. Return false otherwise. */
155 bool is_value () const
157 return m_kind == trad_frame_saved_reg_kind::VALUE;
160 bool is_realreg () const
162 return m_kind == trad_frame_saved_reg_kind::REALREG;
165 bool is_addr () const
167 return m_kind == trad_frame_saved_reg_kind::ADDR;
170 bool is_unknown () const
172 return m_kind == trad_frame_saved_reg_kind::UNKNOWN;
175 bool is_value_bytes () const
177 return m_kind == trad_frame_saved_reg_kind::VALUE_BYTES;
180 private:
182 trad_frame_saved_reg_kind m_kind;
184 union {
185 LONGEST value;
186 int realreg;
187 LONGEST addr;
188 const gdb_byte *value_bytes;
189 } m_reg;
192 /* Reset the saved regs cache, setting register values to REALREG. */
193 void trad_frame_reset_saved_regs (struct gdbarch *gdbarch,
194 trad_frame_saved_reg *regs);
196 /* Return a freshly allocated (and initialized) trad_frame array. */
197 trad_frame_saved_reg *trad_frame_alloc_saved_regs (const frame_info_ptr &);
198 trad_frame_saved_reg *trad_frame_alloc_saved_regs (struct gdbarch *);
200 /* Given the trad_frame info, return the location of the specified
201 register. */
202 struct value *trad_frame_get_prev_register (const frame_info_ptr &this_frame,
203 trad_frame_saved_reg this_saved_regs[],
204 int regnum);
206 #endif