GDB (xrefs)
/tmp/gdb-8.1/gdb/trad-frame.c
Go to the documentation of this file.
1 /* Traditional frame unwind support, for GDB the GNU Debugger.
2 
3  Copyright (C) 2003-2018 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 3 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, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "frame.h"
22 #include "trad-frame.h"
23 #include "regcache.h"
24 #include "frame-unwind.h"
25 #include "value.h"
26 
28 {
32  struct frame_id this_id;
33 };
34 
35 struct trad_frame_cache *
37 {
38  struct trad_frame_cache *this_trad_cache;
39 
40  this_trad_cache = FRAME_OBSTACK_ZALLOC (struct trad_frame_cache);
42  this_trad_cache->this_frame = this_frame;
43  return this_trad_cache;
44 }
45 
46 struct trad_frame_saved_reg *
48 {
49  int regnum;
51  struct trad_frame_saved_reg *this_saved_regs
52  = FRAME_OBSTACK_CALLOC (numregs, struct trad_frame_saved_reg);
53 
54  for (regnum = 0; regnum < numregs; regnum++)
55  {
56  this_saved_regs[regnum].realreg = regnum;
57  this_saved_regs[regnum].addr = -1;
58  }
59  return this_saved_regs;
60 }
61 
62 /* A traditional frame is unwound by analysing the function prologue
63  and using the information gathered to track registers. For
64  non-optimized frames, the technique is reliable (just need to check
65  for all potential instruction sequences). */
66 
67 struct trad_frame_saved_reg *
69 {
70  struct gdbarch *gdbarch = get_frame_arch (this_frame);
71 
73 }
74 
75 enum { TF_REG_VALUE = -1, TF_REG_UNKNOWN = -2 };
76 
77 int
78 trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
79 {
80  return (this_saved_regs[regnum].realreg == TF_REG_VALUE);
81 }
82 
83 int
84 trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
85 {
86  return (this_saved_regs[regnum].realreg >= 0
87  && this_saved_regs[regnum].addr != -1);
88 }
89 
90 int
91 trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs[],
92  int regnum)
93 {
94  return (this_saved_regs[regnum].realreg >= 0
95  && this_saved_regs[regnum].addr == -1);
96 }
97 
98 void
99 trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
100  int regnum, LONGEST val)
101 {
102  /* Make the REALREG invalid, indicating that the ADDR contains the
103  register's value. */
104  this_saved_regs[regnum].realreg = TF_REG_VALUE;
105  this_saved_regs[regnum].addr = val;
106 }
107 
108 void
110  int regnum, LONGEST val)
111 {
112  /* External interface for users of trad_frame_cache
113  (who cannot access the prev_regs object directly). */
114  trad_frame_set_value (this_trad_cache->prev_regs, regnum, val);
115 }
116 
117 void
119  int regnum, int realreg)
120 {
121  this_trad_cache->prev_regs[regnum].realreg = realreg;
122  this_trad_cache->prev_regs[regnum].addr = -1;
123 }
124 
125 void
126 trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache,
127  int regnum, CORE_ADDR addr)
128 {
129  this_trad_cache->prev_regs[regnum].addr = addr;
130 }
131 
132 void
134  int regnum)
135 {
136  /* Make the REALREG invalid, indicating that the value is not known. */
137  this_saved_regs[regnum].realreg = TF_REG_UNKNOWN;
138  this_saved_regs[regnum].addr = -1;
139 }
140 
141 struct value *
143  struct trad_frame_saved_reg this_saved_regs[],
144  int regnum)
145 {
146  if (trad_frame_addr_p (this_saved_regs, regnum))
147  /* The register was saved in memory. */
148  return frame_unwind_got_memory (this_frame, regnum,
149  this_saved_regs[regnum].addr);
150  else if (trad_frame_realreg_p (this_saved_regs, regnum))
151  return frame_unwind_got_register (this_frame, regnum,
152  this_saved_regs[regnum].realreg);
153  else if (trad_frame_value_p (this_saved_regs, regnum))
154  /* The register's value is available. */
155  return frame_unwind_got_constant (this_frame, regnum,
156  this_saved_regs[regnum].addr);
157  else
158  return frame_unwind_got_optimized (this_frame, regnum);
159 }
160 
161 struct value *
162 trad_frame_get_register (struct trad_frame_cache *this_trad_cache,
163  struct frame_info *this_frame,
164  int regnum)
165 {
166  return trad_frame_get_prev_register (this_frame, this_trad_cache->prev_regs,
167  regnum);
168 }
169 
170 void
171 trad_frame_set_id (struct trad_frame_cache *this_trad_cache,
172  struct frame_id this_id)
173 {
174  this_trad_cache->this_id = this_id;
175 }
176 
177 void
178 trad_frame_get_id (struct trad_frame_cache *this_trad_cache,
179  struct frame_id *this_id)
180 {
181  (*this_id) = this_trad_cache->this_id;
182 }
183 
184 void
186  CORE_ADDR this_base)
187 {
188  this_trad_cache->this_base = this_base;
189 }
190 
191 CORE_ADDR
193 {
194  return this_trad_cache->this_base;
195 }
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition: trad-frame.c:126
struct trad_frame_saved_reg * prev_regs
Definition: trad-frame.c:31
int trad_frame_realreg_p(struct trad_frame_saved_reg this_saved_regs[], int regnum)
Definition: trad-frame.c:91
bfd_vma CORE_ADDR
Definition: common-types.h:41
struct value * trad_frame_get_prev_register(struct frame_info *this_frame, struct trad_frame_saved_reg this_saved_regs[], int regnum)
Definition: trad-frame.c:142
int trad_frame_addr_p(struct trad_frame_saved_reg this_saved_regs[], int regnum)
Definition: trad-frame.c:84
struct value * frame_unwind_got_memory(struct frame_info *frame, int regnum, CORE_ADDR addr)
Definition: frame-unwind.c:233
void trad_frame_set_value(struct trad_frame_saved_reg this_saved_regs[], int regnum, LONGEST val)
Definition: trad-frame.c:99
void trad_frame_set_reg_realreg(struct trad_frame_cache *this_trad_cache, int regnum, int realreg)
Definition: trad-frame.c:118
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition: trad-frame.c:171
int trad_frame_value_p(struct trad_frame_saved_reg this_saved_regs[], int regnum)
Definition: trad-frame.c:78
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition: gdbarch.c:2039
CORE_ADDR this_base
Definition: trad-frame.c:30
#define FRAME_OBSTACK_ZALLOC(TYPE)
Definition: frame.h:678
struct value * frame_unwind_got_constant(struct frame_info *frame, int regnum, ULONGEST val)
Definition: frame-unwind.c:246
int gdbarch_num_pseudo_regs(struct gdbarch *gdbarch)
Definition: gdbarch.c:2057
void trad_frame_get_id(struct trad_frame_cache *this_trad_cache, struct frame_id *this_id)
Definition: trad-frame.c:178
struct trad_frame_cache * trad_frame_cache_zalloc(struct frame_info *this_frame)
Definition: trad-frame.c:36
void trad_frame_set_reg_value(struct trad_frame_cache *this_trad_cache, int regnum, LONGEST val)
Definition: trad-frame.c:109
int regnum
Definition: aarch64-tdep.c:77
struct trad_frame_saved_reg * trad_frame_alloc_saved_regs(struct gdbarch *gdbarch)
Definition: trad-frame.c:47
struct frame_info * this_frame
Definition: trad-frame.c:29
Definition: value.c:169
struct frame_id this_id
Definition: trad-frame.c:32
struct value * frame_unwind_got_optimized(struct frame_info *frame, int regnum)
Definition: frame-unwind.c:201
struct value * frame_unwind_got_register(struct frame_info *frame, int regnum, int new_regnum)
Definition: frame-unwind.c:223
void trad_frame_set_this_base(struct trad_frame_cache *this_trad_cache, CORE_ADDR this_base)
Definition: trad-frame.c:185
void trad_frame_set_unknown(struct trad_frame_saved_reg this_saved_regs[], int regnum)
Definition: trad-frame.c:133
CORE_ADDR trad_frame_get_this_base(struct trad_frame_cache *this_trad_cache)
Definition: trad-frame.c:192
struct value * trad_frame_get_register(struct trad_frame_cache *this_trad_cache, struct frame_info *this_frame, int regnum)
Definition: trad-frame.c:162
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
#define FRAME_OBSTACK_CALLOC(NUMBER, TYPE)
Definition: frame.h:680
long long LONGEST
Definition: common-types.h:52