* gas/mips/elf-rel19.d: Pass -march=mips1 to gas as the test
[deliverable/binutils-gdb.git] / gdb / frame.c
CommitLineData
4f460812 1/* Cache and manage frames for GDB, the GNU debugger.
96cb11df
AC
2
3 Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
5bf00f29 4 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
d65fe839
AC
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23#include "defs.h"
24#include "frame.h"
25#include "target.h"
26#include "value.h"
39f77062 27#include "inferior.h" /* for inferior_ptid */
4e052eda 28#include "regcache.h"
4f460812 29#include "gdb_assert.h"
e36180d7 30#include "gdb_string.h"
eb8bc282 31#include "user-regs.h"
4c1e7e9d
AC
32#include "gdb_obstack.h"
33#include "dummy-frame.h"
a94dd1fd 34#include "sentinel-frame.h"
4c1e7e9d
AC
35#include "gdbcore.h"
36#include "annotate.h"
6e7f8b9c 37#include "language.h"
494cca16 38#include "frame-unwind.h"
da62e633 39#include "frame-base.h"
eb4f72c5
AC
40#include "command.h"
41#include "gdbcmd.h"
f4c5303c 42#include "observer.h"
eb4f72c5 43
5613d8d3
AC
44static struct frame_info *get_prev_frame_1 (struct frame_info *this_frame);
45
bd013d54
AC
46/* We keep a cache of stack frames, each of which is a "struct
47 frame_info". The innermost one gets allocated (in
48 wait_for_inferior) each time the inferior stops; current_frame
49 points to it. Additional frames get allocated (in get_prev_frame)
50 as needed, and are chained through the next and prev fields. Any
51 time that the frame cache becomes invalid (most notably when we
52 execute something, but also if we change how we interpret the
53 frames (e.g. "set heuristic-fence-post" in mips-tdep.c, or anything
54 which reads new symbols)), we should call reinit_frame_cache. */
55
56struct frame_info
57{
58 /* Level of this frame. The inner-most (youngest) frame is at level
59 0. As you move towards the outer-most (oldest) frame, the level
60 increases. This is a cached value. It could just as easily be
61 computed by counting back from the selected frame to the inner
62 most frame. */
bbde78fa 63 /* NOTE: cagney/2002-04-05: Perhaps a level of ``-1'' should be
bd013d54
AC
64 reserved to indicate a bogus frame - one that has been created
65 just to keep GDB happy (GDB always needs a frame). For the
66 moment leave this as speculation. */
67 int level;
68
69 /* The frame's type. */
55699d59
AC
70 /* FIXME: cagney/2004-05-01: Should instead just use ->unwind->type.
71 Unfortunately, legacy_get_prev_frame is still explicitly setting
72 the type. Eliminate that method and this field can be
73 eliminated. */
bd013d54
AC
74 enum frame_type type;
75
76 /* For each register, address of where it was saved on entry to the
77 frame, or zero if it was not saved on entry to this frame. This
78 includes special registers such as pc and fp saved in special
79 ways in the stack frame. The SP_REGNUM is even more special, the
80 address here is the sp for the previous frame, not the address
81 where the sp was saved. */
82 /* Allocated by frame_saved_regs_zalloc () which is called /
83 initialized by DEPRECATED_FRAME_INIT_SAVED_REGS(). */
84 CORE_ADDR *saved_regs; /*NUM_REGS + NUM_PSEUDO_REGS*/
85
86 /* Anything extra for this structure that may have been defined in
87 the machine dependent files. */
88 /* Allocated by frame_extra_info_zalloc () which is called /
89 initialized by DEPRECATED_INIT_EXTRA_FRAME_INFO */
90 struct frame_extra_info *extra_info;
91
bd013d54
AC
92 /* The frame's low-level unwinder and corresponding cache. The
93 low-level unwinder is responsible for unwinding register values
94 for the previous frame. The low-level unwind methods are
bbde78fa 95 selected based on the presence, or otherwise, of register unwind
bd013d54
AC
96 information such as CFI. */
97 void *prologue_cache;
98 const struct frame_unwind *unwind;
99
100 /* Cached copy of the previous frame's resume address. */
101 struct {
102 int p;
103 CORE_ADDR value;
104 } prev_pc;
105
106 /* Cached copy of the previous frame's function address. */
107 struct
108 {
109 CORE_ADDR addr;
110 int p;
111 } prev_func;
112
113 /* This frame's ID. */
114 struct
115 {
116 int p;
117 struct frame_id value;
118 } this_id;
119
120 /* The frame's high-level base methods, and corresponding cache.
121 The high level base methods are selected based on the frame's
122 debug info. */
123 const struct frame_base *base;
124 void *base_cache;
125
126 /* Pointers to the next (down, inner, younger) and previous (up,
127 outer, older) frame_info's in the frame cache. */
128 struct frame_info *next; /* down, inner, younger */
129 int prev_p;
130 struct frame_info *prev; /* up, outer, older */
131};
132
ac2bd0a9
AC
133/* Flag to control debugging. */
134
135static int frame_debug;
136
25d29d70
AC
137/* Flag to indicate whether backtraces should stop at main et.al. */
138
139static int backtrace_past_main;
140static unsigned int backtrace_limit = UINT_MAX;
eb4f72c5 141
ca73dd9d
AC
142static void
143fprint_field (struct ui_file *file, const char *name, int p, CORE_ADDR addr)
144{
145 if (p)
146 fprintf_unfiltered (file, "%s=0x%s", name, paddr_nz (addr));
147 else
148 fprintf_unfiltered (file, "!%s", name);
149}
d65fe839 150
00905d52 151void
7f78e237
AC
152fprint_frame_id (struct ui_file *file, struct frame_id id)
153{
ca73dd9d
AC
154 fprintf_unfiltered (file, "{");
155 fprint_field (file, "stack", id.stack_addr_p, id.stack_addr);
156 fprintf_unfiltered (file, ",");
157 fprint_field (file, "code", id.code_addr_p, id.code_addr);
158 fprintf_unfiltered (file, ",");
159 fprint_field (file, "special", id.special_addr_p, id.special_addr);
160 fprintf_unfiltered (file, "}");
7f78e237
AC
161}
162
163static void
164fprint_frame_type (struct ui_file *file, enum frame_type type)
165{
166 switch (type)
167 {
168 case UNKNOWN_FRAME:
169 fprintf_unfiltered (file, "UNKNOWN_FRAME");
170 return;
171 case NORMAL_FRAME:
172 fprintf_unfiltered (file, "NORMAL_FRAME");
173 return;
174 case DUMMY_FRAME:
175 fprintf_unfiltered (file, "DUMMY_FRAME");
176 return;
177 case SIGTRAMP_FRAME:
178 fprintf_unfiltered (file, "SIGTRAMP_FRAME");
179 return;
180 default:
181 fprintf_unfiltered (file, "<unknown type>");
182 return;
183 };
184}
185
186static void
187fprint_frame (struct ui_file *file, struct frame_info *fi)
188{
189 if (fi == NULL)
190 {
191 fprintf_unfiltered (file, "<NULL frame>");
192 return;
193 }
194 fprintf_unfiltered (file, "{");
195 fprintf_unfiltered (file, "level=%d", fi->level);
196 fprintf_unfiltered (file, ",");
197 fprintf_unfiltered (file, "type=");
198 fprint_frame_type (file, fi->type);
199 fprintf_unfiltered (file, ",");
200 fprintf_unfiltered (file, "unwind=");
201 if (fi->unwind != NULL)
202 gdb_print_host_address (fi->unwind, file);
203 else
204 fprintf_unfiltered (file, "<unknown>");
205 fprintf_unfiltered (file, ",");
206 fprintf_unfiltered (file, "pc=");
207 if (fi->next != NULL && fi->next->prev_pc.p)
208 fprintf_unfiltered (file, "0x%s", paddr_nz (fi->next->prev_pc.value));
209 else
210 fprintf_unfiltered (file, "<unknown>");
211 fprintf_unfiltered (file, ",");
212 fprintf_unfiltered (file, "id=");
213 if (fi->this_id.p)
214 fprint_frame_id (file, fi->this_id.value);
215 else
216 fprintf_unfiltered (file, "<unknown>");
217 fprintf_unfiltered (file, ",");
218 fprintf_unfiltered (file, "func=");
219 if (fi->next != NULL && fi->next->prev_func.p)
220 fprintf_unfiltered (file, "0x%s", paddr_nz (fi->next->prev_func.addr));
221 else
222 fprintf_unfiltered (file, "<unknown>");
223 fprintf_unfiltered (file, "}");
224}
225
7a424e99 226/* Return a frame uniq ID that can be used to, later, re-find the
101dcfbe
AC
227 frame. */
228
7a424e99
AC
229struct frame_id
230get_frame_id (struct frame_info *fi)
101dcfbe
AC
231{
232 if (fi == NULL)
233 {
7a424e99 234 return null_frame_id;
101dcfbe 235 }
d0a55772 236 if (!fi->this_id.p)
101dcfbe 237 {
06c77151 238 gdb_assert (!legacy_frame_p (current_gdbarch));
7f78e237
AC
239 if (frame_debug)
240 fprintf_unfiltered (gdb_stdlog, "{ get_frame_id (fi=%d) ",
241 fi->level);
c50901fd
AC
242 /* Find the unwinder. */
243 if (fi->unwind == NULL)
244 {
82417da5
AC
245 fi->unwind = frame_unwind_find_by_frame (fi->next,
246 &fi->prologue_cache);
55699d59
AC
247 /* FIXME: cagney/2004-05-01: Should instead just use
248 ->unwind->type. Unfortunately, legacy_get_prev_frame is
249 still explicitly setting the type. Eliminate that method
250 and this field can be eliminated. */
c50901fd
AC
251 fi->type = fi->unwind->type;
252 }
06c77151 253 /* Find THIS frame's ID. */
d0a55772
AC
254 fi->unwind->this_id (fi->next, &fi->prologue_cache, &fi->this_id.value);
255 fi->this_id.p = 1;
7f78e237
AC
256 if (frame_debug)
257 {
258 fprintf_unfiltered (gdb_stdlog, "-> ");
259 fprint_frame_id (gdb_stdlog, fi->this_id.value);
260 fprintf_unfiltered (gdb_stdlog, " }\n");
261 }
101dcfbe 262 }
18adea3f 263 return fi->this_id.value;
101dcfbe
AC
264}
265
5613d8d3
AC
266struct frame_id
267frame_unwind_id (struct frame_info *next_frame)
268{
269 /* Use prev_frame, and not get_prev_frame. The latter will truncate
270 the frame chain, leading to this function unintentionally
271 returning a null_frame_id (e.g., when a caller requests the frame
272 ID of "main()"s caller. */
273 return get_frame_id (get_prev_frame_1 (next_frame));
274}
275
7a424e99
AC
276const struct frame_id null_frame_id; /* All zeros. */
277
278struct frame_id
48c66725
JJ
279frame_id_build_special (CORE_ADDR stack_addr, CORE_ADDR code_addr,
280 CORE_ADDR special_addr)
7a424e99 281{
12b0b6de 282 struct frame_id id = null_frame_id;
d0a55772 283 id.stack_addr = stack_addr;
12b0b6de 284 id.stack_addr_p = 1;
d0a55772 285 id.code_addr = code_addr;
12b0b6de 286 id.code_addr_p = 1;
48c66725 287 id.special_addr = special_addr;
12b0b6de 288 id.special_addr_p = 1;
7a424e99
AC
289 return id;
290}
291
48c66725
JJ
292struct frame_id
293frame_id_build (CORE_ADDR stack_addr, CORE_ADDR code_addr)
294{
12b0b6de
UW
295 struct frame_id id = null_frame_id;
296 id.stack_addr = stack_addr;
297 id.stack_addr_p = 1;
298 id.code_addr = code_addr;
299 id.code_addr_p = 1;
300 return id;
301}
302
303struct frame_id
304frame_id_build_wild (CORE_ADDR stack_addr)
305{
306 struct frame_id id = null_frame_id;
307 id.stack_addr = stack_addr;
308 id.stack_addr_p = 1;
309 return id;
48c66725
JJ
310}
311
7a424e99
AC
312int
313frame_id_p (struct frame_id l)
314{
d0a55772 315 int p;
12b0b6de
UW
316 /* The frame is valid iff it has a valid stack address. */
317 p = l.stack_addr_p;
7f78e237
AC
318 if (frame_debug)
319 {
320 fprintf_unfiltered (gdb_stdlog, "{ frame_id_p (l=");
321 fprint_frame_id (gdb_stdlog, l);
322 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", p);
323 }
d0a55772 324 return p;
7a424e99
AC
325}
326
327int
328frame_id_eq (struct frame_id l, struct frame_id r)
329{
d0a55772 330 int eq;
12b0b6de
UW
331 if (!l.stack_addr_p || !r.stack_addr_p)
332 /* Like a NaN, if either ID is invalid, the result is false.
333 Note that a frame ID is invalid iff it is the null frame ID. */
d0a55772
AC
334 eq = 0;
335 else if (l.stack_addr != r.stack_addr)
336 /* If .stack addresses are different, the frames are different. */
337 eq = 0;
12b0b6de
UW
338 else if (!l.code_addr_p || !r.code_addr_p)
339 /* An invalid code addr is a wild card, always succeed. */
d0a55772 340 eq = 1;
48c66725
JJ
341 else if (l.code_addr != r.code_addr)
342 /* If .code addresses are different, the frames are different. */
343 eq = 0;
12b0b6de
UW
344 else if (!l.special_addr_p || !r.special_addr_p)
345 /* An invalid special addr is a wild card (or unused), always succeed. */
48c66725
JJ
346 eq = 1;
347 else if (l.special_addr == r.special_addr)
348 /* Frames are equal. */
d0a55772
AC
349 eq = 1;
350 else
4aa79dcc
AC
351 /* No luck. */
352 eq = 0;
7f78e237
AC
353 if (frame_debug)
354 {
355 fprintf_unfiltered (gdb_stdlog, "{ frame_id_eq (l=");
356 fprint_frame_id (gdb_stdlog, l);
357 fprintf_unfiltered (gdb_stdlog, ",r=");
358 fprint_frame_id (gdb_stdlog, r);
359 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", eq);
360 }
d0a55772 361 return eq;
7a424e99
AC
362}
363
364int
365frame_id_inner (struct frame_id l, struct frame_id r)
366{
d0a55772 367 int inner;
12b0b6de 368 if (!l.stack_addr_p || !r.stack_addr_p)
d0a55772
AC
369 /* Like NaN, any operation involving an invalid ID always fails. */
370 inner = 0;
371 else
372 /* Only return non-zero when strictly inner than. Note that, per
373 comment in "frame.h", there is some fuzz here. Frameless
374 functions are not strictly inner than (same .stack but
48c66725 375 different .code and/or .special address). */
d0a55772 376 inner = INNER_THAN (l.stack_addr, r.stack_addr);
7f78e237
AC
377 if (frame_debug)
378 {
379 fprintf_unfiltered (gdb_stdlog, "{ frame_id_inner (l=");
380 fprint_frame_id (gdb_stdlog, l);
381 fprintf_unfiltered (gdb_stdlog, ",r=");
382 fprint_frame_id (gdb_stdlog, r);
383 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", inner);
384 }
d0a55772 385 return inner;
7a424e99
AC
386}
387
101dcfbe
AC
388struct frame_info *
389frame_find_by_id (struct frame_id id)
390{
391 struct frame_info *frame;
392
393 /* ZERO denotes the null frame, let the caller decide what to do
394 about it. Should it instead return get_current_frame()? */
7a424e99 395 if (!frame_id_p (id))
101dcfbe
AC
396 return NULL;
397
398 for (frame = get_current_frame ();
399 frame != NULL;
400 frame = get_prev_frame (frame))
401 {
7a424e99
AC
402 struct frame_id this = get_frame_id (frame);
403 if (frame_id_eq (id, this))
404 /* An exact match. */
405 return frame;
406 if (frame_id_inner (id, this))
407 /* Gone to far. */
101dcfbe 408 return NULL;
bbde78fa
JM
409 /* Either we're not yet gone far enough out along the frame
410 chain (inner(this,id)), or we're comparing frameless functions
7a424e99
AC
411 (same .base, different .func, no test available). Struggle
412 on until we've definitly gone to far. */
101dcfbe
AC
413 }
414 return NULL;
415}
416
f18c5a73 417CORE_ADDR
12cc2063 418frame_pc_unwind (struct frame_info *this_frame)
f18c5a73 419{
d1340264 420 if (!this_frame->prev_pc.p)
f18c5a73 421 {
12cc2063
AC
422 CORE_ADDR pc;
423 if (gdbarch_unwind_pc_p (current_gdbarch))
424 {
425 /* The right way. The `pure' way. The one true way. This
426 method depends solely on the register-unwind code to
427 determine the value of registers in THIS frame, and hence
428 the value of this frame's PC (resume address). A typical
429 implementation is no more than:
430
431 frame_unwind_register (this_frame, ISA_PC_REGNUM, buf);
af1342ab 432 return extract_unsigned_integer (buf, size of ISA_PC_REGNUM);
12cc2063
AC
433
434 Note: this method is very heavily dependent on a correct
435 register-unwind implementation, it pays to fix that
436 method first; this method is frame type agnostic, since
437 it only deals with register values, it works with any
438 frame. This is all in stark contrast to the old
439 FRAME_SAVED_PC which would try to directly handle all the
440 different ways that a PC could be unwound. */
441 pc = gdbarch_unwind_pc (current_gdbarch, this_frame);
442 }
443 else if (this_frame->level < 0)
444 {
bbde78fa 445 /* FIXME: cagney/2003-03-06: Old code and a sentinel
12cc2063 446 frame. Do like was always done. Fetch the PC's value
bbde78fa 447 directly from the global registers array (via read_pc).
12cc2063
AC
448 This assumes that this frame belongs to the current
449 global register cache. The assumption is dangerous. */
450 pc = read_pc ();
451 }
8bedc050 452 else if (DEPRECATED_FRAME_SAVED_PC_P ())
12cc2063
AC
453 {
454 /* FIXME: cagney/2003-03-06: Old code, but not a sentinel
455 frame. Do like was always done. Note that this method,
456 unlike unwind_pc(), tries to handle all the different
457 frame cases directly. It fails. */
8bedc050 458 pc = DEPRECATED_FRAME_SAVED_PC (this_frame);
12cc2063
AC
459 }
460 else
461 internal_error (__FILE__, __LINE__, "No gdbarch_unwind_pc method");
d1340264
AC
462 this_frame->prev_pc.value = pc;
463 this_frame->prev_pc.p = 1;
7f78e237
AC
464 if (frame_debug)
465 fprintf_unfiltered (gdb_stdlog,
466 "{ frame_pc_unwind (this_frame=%d) -> 0x%s }\n",
467 this_frame->level,
468 paddr_nz (this_frame->prev_pc.value));
f18c5a73 469 }
d1340264 470 return this_frame->prev_pc.value;
f18c5a73
AC
471}
472
be41e9f4
AC
473CORE_ADDR
474frame_func_unwind (struct frame_info *fi)
475{
476 if (!fi->prev_func.p)
477 {
57bfe177
AC
478 /* Make certain that this, and not the adjacent, function is
479 found. */
480 CORE_ADDR addr_in_block = frame_unwind_address_in_block (fi);
be41e9f4 481 fi->prev_func.p = 1;
57bfe177 482 fi->prev_func.addr = get_pc_function_start (addr_in_block);
7f78e237
AC
483 if (frame_debug)
484 fprintf_unfiltered (gdb_stdlog,
485 "{ frame_func_unwind (fi=%d) -> 0x%s }\n",
486 fi->level, paddr_nz (fi->prev_func.addr));
be41e9f4
AC
487 }
488 return fi->prev_func.addr;
489}
490
491CORE_ADDR
492get_frame_func (struct frame_info *fi)
493{
494 return frame_func_unwind (fi->next);
495}
496
7a25a7c1
AC
497static int
498do_frame_unwind_register (void *src, int regnum, void *buf)
499{
500 frame_unwind_register (src, regnum, buf);
501 return 1;
502}
503
dbe9fe58 504void
7a25a7c1
AC
505frame_pop (struct frame_info *this_frame)
506{
507 struct regcache *scratch_regcache;
508 struct cleanup *cleanups;
509
749b82f6 510 if (DEPRECATED_POP_FRAME_P ())
7a25a7c1
AC
511 {
512 /* A legacy architecture that has implemented a custom pop
513 function. All new architectures should instead be using the
514 generic code below. */
749b82f6 515 DEPRECATED_POP_FRAME;
7a25a7c1
AC
516 }
517 else
518 {
519 /* Make a copy of all the register values unwound from this
520 frame. Save them in a scratch buffer so that there isn't a
bbde78fa
JM
521 race between trying to extract the old values from the
522 current_regcache while at the same time writing new values
7a25a7c1
AC
523 into that same cache. */
524 struct regcache *scratch = regcache_xmalloc (current_gdbarch);
525 struct cleanup *cleanups = make_cleanup_regcache_xfree (scratch);
526 regcache_save (scratch, do_frame_unwind_register, this_frame);
efd710d6
AC
527 /* FIXME: cagney/2003-03-16: It should be possible to tell the
528 target's register cache that it is about to be hit with a
529 burst register transfer and that the sequence of register
530 writes should be batched. The pair target_prepare_to_store()
531 and target_store_registers() kind of suggest this
ce2826aa 532 functionality. Unfortunately, they don't implement it. Their
efd710d6
AC
533 lack of a formal definition can lead to targets writing back
534 bogus values (arguably a bug in the target code mind). */
7a25a7c1
AC
535 /* Now copy those saved registers into the current regcache.
536 Here, regcache_cpy() calls regcache_restore(). */
537 regcache_cpy (current_regcache, scratch);
538 do_cleanups (cleanups);
539 }
540 /* We've made right mess of GDB's local state, just discard
541 everything. */
dbe9fe58
AC
542 flush_cached_frames ();
543}
c689142b 544
4f460812
AC
545void
546frame_register_unwind (struct frame_info *frame, int regnum,
547 int *optimizedp, enum lval_type *lvalp,
548 CORE_ADDR *addrp, int *realnump, void *bufferp)
549{
550 struct frame_unwind_cache *cache;
551
7f78e237
AC
552 if (frame_debug)
553 {
6764ddad
AC
554 fprintf_unfiltered (gdb_stdlog, "\
555{ frame_register_unwind (frame=%d,regnum=%d(%s),...) ",
556 frame->level, regnum,
557 frame_map_regnum_to_name (frame, regnum));
7f78e237
AC
558 }
559
4f460812
AC
560 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
561 that the value proper does not need to be fetched. */
562 gdb_assert (optimizedp != NULL);
563 gdb_assert (lvalp != NULL);
564 gdb_assert (addrp != NULL);
565 gdb_assert (realnump != NULL);
566 /* gdb_assert (bufferp != NULL); */
567
a94dd1fd
AC
568 /* NOTE: cagney/2002-11-27: A program trying to unwind a NULL frame
569 is broken. There is always a frame. If there, for some reason,
bbde78fa 570 isn't a frame, there is some pretty busted code as it should have
a94dd1fd
AC
571 detected the problem before calling here. */
572 gdb_assert (frame != NULL);
4f460812 573
c50901fd
AC
574 /* Find the unwinder. */
575 if (frame->unwind == NULL)
576 {
82417da5
AC
577 frame->unwind = frame_unwind_find_by_frame (frame->next,
578 &frame->prologue_cache);
55699d59
AC
579 /* FIXME: cagney/2004-05-01: Should instead just use ->unwind->type.
580 Unfortunately, legacy_get_prev_frame is still explicitly setting
581 the type. Eliminate that method and this field can be
582 eliminated. */
c50901fd
AC
583 frame->type = frame->unwind->type;
584 }
585
6dc42492 586 /* Ask this frame to unwind its register. See comment in
bbde78fa 587 "frame-unwind.h" for why NEXT frame and this unwind cache are
6dc42492
AC
588 passed in. */
589 frame->unwind->prev_register (frame->next, &frame->prologue_cache, regnum,
590 optimizedp, lvalp, addrp, realnump, bufferp);
591
7f78e237
AC
592 if (frame_debug)
593 {
594 fprintf_unfiltered (gdb_stdlog, "->");
595 fprintf_unfiltered (gdb_stdlog, " *optimizedp=%d", (*optimizedp));
596 fprintf_unfiltered (gdb_stdlog, " *lvalp=%d", (int) (*lvalp));
597 fprintf_unfiltered (gdb_stdlog, " *addrp=0x%s", paddr_nz ((*addrp)));
598 fprintf_unfiltered (gdb_stdlog, " *bufferp=");
599 if (bufferp == NULL)
600 fprintf_unfiltered (gdb_stdlog, "<NULL>");
601 else
602 {
603 int i;
d2cf594a 604 const unsigned char *buf = bufferp;
7f78e237
AC
605 fprintf_unfiltered (gdb_stdlog, "[");
606 for (i = 0; i < register_size (current_gdbarch, regnum); i++)
607 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
608 fprintf_unfiltered (gdb_stdlog, "]");
609 }
610 fprintf_unfiltered (gdb_stdlog, " }\n");
611 }
4f460812
AC
612}
613
a216a322
AC
614void
615frame_register (struct frame_info *frame, int regnum,
616 int *optimizedp, enum lval_type *lvalp,
617 CORE_ADDR *addrp, int *realnump, void *bufferp)
618{
619 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
620 that the value proper does not need to be fetched. */
621 gdb_assert (optimizedp != NULL);
622 gdb_assert (lvalp != NULL);
623 gdb_assert (addrp != NULL);
624 gdb_assert (realnump != NULL);
625 /* gdb_assert (bufferp != NULL); */
626
627 /* Ulgh! Old code that, for lval_register, sets ADDRP to the offset
628 of the register in the register cache. It should instead return
629 the REGNUM corresponding to that register. Translate the . */
129c1cd6 630 if (DEPRECATED_GET_SAVED_REGISTER_P ())
a216a322 631 {
129c1cd6
AC
632 DEPRECATED_GET_SAVED_REGISTER (bufferp, optimizedp, addrp, frame,
633 regnum, lvalp);
a216a322
AC
634 /* Compute the REALNUM if the caller wants it. */
635 if (*lvalp == lval_register)
636 {
637 int regnum;
638 for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
639 {
640 if (*addrp == register_offset_hack (current_gdbarch, regnum))
641 {
642 *realnump = regnum;
643 return;
644 }
645 }
646 internal_error (__FILE__, __LINE__,
647 "Failed to compute the register number corresponding"
648 " to 0x%s", paddr_d (*addrp));
649 }
650 *realnump = -1;
651 return;
652 }
653
a94dd1fd
AC
654 /* Obtain the register value by unwinding the register from the next
655 (more inner frame). */
656 gdb_assert (frame != NULL && frame->next != NULL);
657 frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
658 realnump, bufferp);
a216a322
AC
659}
660
135c175f 661void
5b181d62 662frame_unwind_register (struct frame_info *frame, int regnum, void *buf)
135c175f
AC
663{
664 int optimized;
665 CORE_ADDR addr;
666 int realnum;
667 enum lval_type lval;
135c175f
AC
668 frame_register_unwind (frame, regnum, &optimized, &lval, &addr,
669 &realnum, buf);
5b181d62
AC
670}
671
f0e7d0e8
AC
672void
673get_frame_register (struct frame_info *frame,
674 int regnum, void *buf)
675{
676 frame_unwind_register (frame->next, regnum, buf);
677}
678
679LONGEST
680frame_unwind_register_signed (struct frame_info *frame, int regnum)
681{
682 char buf[MAX_REGISTER_SIZE];
683 frame_unwind_register (frame, regnum, buf);
f30992d4 684 return extract_signed_integer (buf, DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum));
f0e7d0e8
AC
685}
686
687LONGEST
688get_frame_register_signed (struct frame_info *frame, int regnum)
689{
690 return frame_unwind_register_signed (frame->next, regnum);
691}
692
693ULONGEST
694frame_unwind_register_unsigned (struct frame_info *frame, int regnum)
695{
696 char buf[MAX_REGISTER_SIZE];
697 frame_unwind_register (frame, regnum, buf);
f30992d4 698 return extract_unsigned_integer (buf, DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum));
f0e7d0e8
AC
699}
700
701ULONGEST
702get_frame_register_unsigned (struct frame_info *frame, int regnum)
703{
704 return frame_unwind_register_unsigned (frame->next, regnum);
705}
706
135c175f
AC
707void
708frame_unwind_unsigned_register (struct frame_info *frame, int regnum,
709 ULONGEST *val)
710{
d9d9c31f 711 char buf[MAX_REGISTER_SIZE];
5b181d62 712 frame_unwind_register (frame, regnum, buf);
f30992d4 713 (*val) = extract_unsigned_integer (buf, DEPRECATED_REGISTER_VIRTUAL_SIZE (regnum));
135c175f 714}
4f460812 715
ff2e87ac
AC
716void
717put_frame_register (struct frame_info *frame, int regnum, const void *buf)
718{
719 struct gdbarch *gdbarch = get_frame_arch (frame);
720 int realnum;
721 int optim;
722 enum lval_type lval;
723 CORE_ADDR addr;
724 frame_register (frame, regnum, &optim, &lval, &addr, &realnum, NULL);
725 if (optim)
726 error ("Attempt to assign to a value that was optimized out.");
727 switch (lval)
728 {
729 case lval_memory:
730 {
731 /* FIXME: write_memory doesn't yet take constant buffers.
732 Arrrg! */
733 char tmp[MAX_REGISTER_SIZE];
734 memcpy (tmp, buf, register_size (gdbarch, regnum));
735 write_memory (addr, tmp, register_size (gdbarch, regnum));
736 break;
737 }
738 case lval_register:
739 regcache_cooked_write (current_regcache, realnum, buf);
740 break;
741 default:
742 error ("Attempt to assign to an unmodifiable value.");
743 }
744}
745
cda5a58a 746/* frame_register_read ()
d65fe839 747
cda5a58a 748 Find and return the value of REGNUM for the specified stack frame.
12c266ea
AC
749 The number of bytes copied is DEPRECATED_REGISTER_RAW_SIZE
750 (REGNUM).
d65fe839 751
cda5a58a 752 Returns 0 if the register value could not be found. */
d65fe839 753
cda5a58a
AC
754int
755frame_register_read (struct frame_info *frame, int regnum, void *myaddr)
d65fe839 756{
a216a322
AC
757 int optimized;
758 enum lval_type lval;
759 CORE_ADDR addr;
760 int realnum;
761 frame_register (frame, regnum, &optimized, &lval, &addr, &realnum, myaddr);
d65fe839 762
bbde78fa 763 /* FIXME: cagney/2002-05-15: This test is just bogus.
c97dcfc7
AC
764
765 It indicates that the target failed to supply a value for a
766 register because it was "not available" at this time. Problem
767 is, the target still has the register and so get saved_register()
768 may be returning a value saved on the stack. */
769
d65fe839 770 if (register_cached (regnum) < 0)
cda5a58a 771 return 0; /* register value not available */
d65fe839 772
a216a322 773 return !optimized;
d65fe839 774}
e36180d7
AC
775
776
777/* Map between a frame register number and its name. A frame register
778 space is a superset of the cooked register space --- it also
779 includes builtin registers. */
780
781int
eb8bc282 782frame_map_name_to_regnum (struct frame_info *frame, const char *name, int len)
e36180d7 783{
eb8bc282 784 return user_reg_map_name_to_regnum (get_frame_arch (frame), name, len);
e36180d7
AC
785}
786
787const char *
eb8bc282 788frame_map_regnum_to_name (struct frame_info *frame, int regnum)
e36180d7 789{
eb8bc282 790 return user_reg_map_regnum_to_name (get_frame_arch (frame), regnum);
e36180d7 791}
4c1e7e9d 792
a94dd1fd
AC
793/* Create a sentinel frame. */
794
b9362cc7 795static struct frame_info *
a94dd1fd
AC
796create_sentinel_frame (struct regcache *regcache)
797{
798 struct frame_info *frame = FRAME_OBSTACK_ZALLOC (struct frame_info);
0e100dab 799 frame->type = SENTINEL_FRAME;
a94dd1fd
AC
800 frame->level = -1;
801 /* Explicitly initialize the sentinel frame's cache. Provide it
802 with the underlying regcache. In the future additional
803 information, such as the frame's thread will be added. */
6dc42492 804 frame->prologue_cache = sentinel_frame_cache (regcache);
a94dd1fd
AC
805 /* For the moment there is only one sentinel frame implementation. */
806 frame->unwind = sentinel_frame_unwind;
807 /* Link this frame back to itself. The frame is self referential
808 (the unwound PC is the same as the pc), so make it so. */
809 frame->next = frame;
50bbdbd9
AC
810 /* Make the sentinel frame's ID valid, but invalid. That way all
811 comparisons with it should fail. */
d0a55772
AC
812 frame->this_id.p = 1;
813 frame->this_id.value = null_frame_id;
7f78e237
AC
814 if (frame_debug)
815 {
816 fprintf_unfiltered (gdb_stdlog, "{ create_sentinel_frame (...) -> ");
817 fprint_frame (gdb_stdlog, frame);
818 fprintf_unfiltered (gdb_stdlog, " }\n");
819 }
a94dd1fd
AC
820 return frame;
821}
822
4c1e7e9d
AC
823/* Info about the innermost stack frame (contents of FP register) */
824
825static struct frame_info *current_frame;
826
827/* Cache for frame addresses already read by gdb. Valid only while
828 inferior is stopped. Control variables for the frame cache should
829 be local to this module. */
830
831static struct obstack frame_cache_obstack;
832
833void *
479ab5a0 834frame_obstack_zalloc (unsigned long size)
4c1e7e9d 835{
479ab5a0
AC
836 void *data = obstack_alloc (&frame_cache_obstack, size);
837 memset (data, 0, size);
838 return data;
4c1e7e9d
AC
839}
840
6baff1d2 841CORE_ADDR *
4c1e7e9d
AC
842frame_saved_regs_zalloc (struct frame_info *fi)
843{
844 fi->saved_regs = (CORE_ADDR *)
479ab5a0 845 frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS);
6baff1d2 846 return fi->saved_regs;
4c1e7e9d
AC
847}
848
6baff1d2 849CORE_ADDR *
1b1d3794 850deprecated_get_frame_saved_regs (struct frame_info *fi)
6baff1d2
AC
851{
852 return fi->saved_regs;
853}
4c1e7e9d 854
a94dd1fd
AC
855/* Return the innermost (currently executing) stack frame. This is
856 split into two functions. The function unwind_to_current_frame()
857 is wrapped in catch exceptions so that, even when the unwind of the
858 sentinel frame fails, the function still returns a stack frame. */
859
860static int
861unwind_to_current_frame (struct ui_out *ui_out, void *args)
862{
863 struct frame_info *frame = get_prev_frame (args);
bbde78fa 864 /* A sentinel frame can fail to unwind, e.g., because its PC value
a94dd1fd
AC
865 lands in somewhere like start. */
866 if (frame == NULL)
867 return 1;
868 current_frame = frame;
869 return 0;
870}
4c1e7e9d
AC
871
872struct frame_info *
873get_current_frame (void)
874{
0a1e1ca1
AC
875 /* First check, and report, the lack of registers. Having GDB
876 report "No stack!" or "No memory" when the target doesn't even
877 have registers is very confusing. Besides, "printcmd.exp"
878 explicitly checks that ``print $pc'' with no registers prints "No
879 registers". */
a94dd1fd
AC
880 if (!target_has_registers)
881 error ("No registers.");
0a1e1ca1
AC
882 if (!target_has_stack)
883 error ("No stack.");
a94dd1fd
AC
884 if (!target_has_memory)
885 error ("No memory.");
4c1e7e9d
AC
886 if (current_frame == NULL)
887 {
a94dd1fd
AC
888 struct frame_info *sentinel_frame =
889 create_sentinel_frame (current_regcache);
890 if (catch_exceptions (uiout, unwind_to_current_frame, sentinel_frame,
891 NULL, RETURN_MASK_ERROR) != 0)
892 {
893 /* Oops! Fake a current frame? Is this useful? It has a PC
894 of zero, for instance. */
895 current_frame = sentinel_frame;
896 }
4c1e7e9d
AC
897 }
898 return current_frame;
899}
900
6e7f8b9c
AC
901/* The "selected" stack frame is used by default for local and arg
902 access. May be zero, for no selected frame. */
903
904struct frame_info *deprecated_selected_frame;
905
bbde78fa 906/* Return the selected frame. Always non-NULL (unless there isn't an
6e7f8b9c
AC
907 inferior sufficient for creating a frame) in which case an error is
908 thrown. */
909
910struct frame_info *
911get_selected_frame (void)
912{
913 if (deprecated_selected_frame == NULL)
914 /* Hey! Don't trust this. It should really be re-finding the
915 last selected frame of the currently selected thread. This,
916 though, is better than nothing. */
917 select_frame (get_current_frame ());
918 /* There is always a frame. */
919 gdb_assert (deprecated_selected_frame != NULL);
920 return deprecated_selected_frame;
921}
922
bbde78fa 923/* This is a variant of get_selected_frame() which can be called when
7dd88986 924 the inferior does not have a frame; in that case it will return
bbde78fa 925 NULL instead of calling error(). */
7dd88986
DJ
926
927struct frame_info *
928deprecated_safe_get_selected_frame (void)
929{
930 if (!target_has_registers || !target_has_stack || !target_has_memory)
931 return NULL;
932 return get_selected_frame ();
933}
934
6e7f8b9c
AC
935/* Select frame FI (or NULL - to invalidate the current frame). */
936
937void
938select_frame (struct frame_info *fi)
939{
52f0bd74 940 struct symtab *s;
6e7f8b9c
AC
941
942 deprecated_selected_frame = fi;
bbde78fa 943 /* NOTE: cagney/2002-05-04: FI can be NULL. This occurs when the
6e7f8b9c 944 frame is being invalidated. */
9a4105ab
AC
945 if (deprecated_selected_frame_level_changed_hook)
946 deprecated_selected_frame_level_changed_hook (frame_relative_level (fi));
6e7f8b9c
AC
947
948 /* FIXME: kseitz/2002-08-28: It would be nice to call
bbde78fa 949 selected_frame_level_changed_event() right here, but due to limitations
6e7f8b9c 950 in the current interfaces, we would end up flooding UIs with events
bbde78fa 951 because select_frame() is used extensively internally.
6e7f8b9c
AC
952
953 Once we have frame-parameterized frame (and frame-related) commands,
954 the event notification can be moved here, since this function will only
bbde78fa 955 be called when the user's selected frame is being changed. */
6e7f8b9c
AC
956
957 /* Ensure that symbols for this frame are read in. Also, determine the
958 source language of this frame, and switch to it if desired. */
959 if (fi)
960 {
7ae4c3a5 961 /* We retrieve the frame's symtab by using the frame PC. However
bbde78fa 962 we cannot use the frame PC as-is, because it usually points to
7ae4c3a5
JB
963 the instruction following the "call", which is sometimes the
964 first instruction of another function. So we rely on
965 get_frame_address_in_block() which provides us with a PC which
966 is guaranteed to be inside the frame's code block. */
967 s = find_pc_symtab (get_frame_address_in_block (fi));
6e7f8b9c
AC
968 if (s
969 && s->language != current_language->la_language
970 && s->language != language_unknown
971 && language_mode == language_mode_auto)
972 {
973 set_language (s->language);
974 }
975 }
976}
977
4c1e7e9d
AC
978/* Return the register saved in the simplistic ``saved_regs'' cache.
979 If the value isn't here AND a value is needed, try the next inner
980 most frame. */
981
982static void
6dc42492
AC
983legacy_saved_regs_prev_register (struct frame_info *next_frame,
984 void **this_prologue_cache,
985 int regnum, int *optimizedp,
986 enum lval_type *lvalp, CORE_ADDR *addrp,
987 int *realnump, void *bufferp)
4c1e7e9d 988{
6dc42492 989 /* HACK: New code is passed the next frame and this cache.
ce2826aa 990 Unfortunately, old code expects this frame. Since this is a
6dc42492
AC
991 backward compatibility hack, cheat by walking one level along the
992 prologue chain to the frame the old code expects.
993
994 Do not try this at home. Professional driver, closed course. */
995 struct frame_info *frame = next_frame->prev;
4c1e7e9d 996 gdb_assert (frame != NULL);
4c1e7e9d 997
1b1d3794 998 if (deprecated_get_frame_saved_regs (frame) == NULL)
870b3035 999 {
bbde78fa 1000 /* If nothing has initialized the saved regs, do it now. */
870b3035
AC
1001 gdb_assert (DEPRECATED_FRAME_INIT_SAVED_REGS_P ());
1002 DEPRECATED_FRAME_INIT_SAVED_REGS (frame);
1b1d3794 1003 gdb_assert (deprecated_get_frame_saved_regs (frame) != NULL);
870b3035 1004 }
4c1e7e9d 1005
1b1d3794
AC
1006 if (deprecated_get_frame_saved_regs (frame) != NULL
1007 && deprecated_get_frame_saved_regs (frame)[regnum] != 0)
4c1e7e9d
AC
1008 {
1009 if (regnum == SP_REGNUM)
1010 {
1011 /* SP register treated specially. */
1012 *optimizedp = 0;
1013 *lvalp = not_lval;
1014 *addrp = 0;
1015 *realnump = -1;
1016 if (bufferp != NULL)
bbde78fa
JM
1017 /* NOTE: cagney/2003-05-09: In-lined store_address() with
1018 it's body - store_unsigned_integer(). */
12c266ea 1019 store_unsigned_integer (bufferp, DEPRECATED_REGISTER_RAW_SIZE (regnum),
1b1d3794 1020 deprecated_get_frame_saved_regs (frame)[regnum]);
4c1e7e9d
AC
1021 }
1022 else
1023 {
1024 /* Any other register is saved in memory, fetch it but cache
1025 a local copy of its value. */
1026 *optimizedp = 0;
1027 *lvalp = lval_memory;
1b1d3794 1028 *addrp = deprecated_get_frame_saved_regs (frame)[regnum];
4c1e7e9d
AC
1029 *realnump = -1;
1030 if (bufferp != NULL)
1031 {
1032#if 1
1033 /* Save each register value, as it is read in, in a
1034 frame based cache. */
6dc42492 1035 void **regs = (*this_prologue_cache);
4c1e7e9d
AC
1036 if (regs == NULL)
1037 {
1038 int sizeof_cache = ((NUM_REGS + NUM_PSEUDO_REGS)
1039 * sizeof (void *));
479ab5a0 1040 regs = frame_obstack_zalloc (sizeof_cache);
6dc42492 1041 (*this_prologue_cache) = regs;
4c1e7e9d
AC
1042 }
1043 if (regs[regnum] == NULL)
1044 {
1045 regs[regnum]
12c266ea 1046 = frame_obstack_zalloc (DEPRECATED_REGISTER_RAW_SIZE (regnum));
1b1d3794 1047 read_memory (deprecated_get_frame_saved_regs (frame)[regnum], regs[regnum],
12c266ea 1048 DEPRECATED_REGISTER_RAW_SIZE (regnum));
4c1e7e9d 1049 }
12c266ea 1050 memcpy (bufferp, regs[regnum], DEPRECATED_REGISTER_RAW_SIZE (regnum));
4c1e7e9d
AC
1051#else
1052 /* Read the value in from memory. */
1b1d3794 1053 read_memory (deprecated_get_frame_saved_regs (frame)[regnum], bufferp,
12c266ea 1054 DEPRECATED_REGISTER_RAW_SIZE (regnum));
4c1e7e9d
AC
1055#endif
1056 }
1057 }
1058 return;
1059 }
1060
6dc42492
AC
1061 /* No luck. Assume this and the next frame have the same register
1062 value. Pass the unwind request down the frame chain to the next
1063 frame. Hopefully that frame will find the register's location. */
1064 frame_register_unwind (next_frame, regnum, optimizedp, lvalp, addrp,
1065 realnump, bufferp);
4c1e7e9d
AC
1066}
1067
c170fb60 1068static void
6dc42492
AC
1069legacy_saved_regs_this_id (struct frame_info *next_frame,
1070 void **this_prologue_cache,
1071 struct frame_id *id)
c689142b 1072{
1152e35e
AC
1073 /* A developer is trying to bring up a new architecture, help them
1074 by providing a default unwinder that refuses to unwind anything
1075 (the ID is always NULL). In the case of legacy code,
1076 legacy_get_prev_frame() will have previously set ->this_id.p, so
1077 this code won't be called. */
1078 (*id) = null_frame_id;
c689142b
AC
1079}
1080
6dc42492 1081const struct frame_unwind legacy_saved_regs_unwinder = {
bbde78fa 1082 /* Not really. It gets overridden by legacy_get_prev_frame(). */
7df05f2b 1083 UNKNOWN_FRAME,
6dc42492
AC
1084 legacy_saved_regs_this_id,
1085 legacy_saved_regs_prev_register
494cca16 1086};
6dc42492 1087const struct frame_unwind *legacy_saved_regs_unwind = &legacy_saved_regs_unwinder;
494cca16 1088
eb4f72c5
AC
1089/* Determine the frame's type based on its PC. */
1090
1091static enum frame_type
1092frame_type_from_pc (CORE_ADDR pc)
1093{
7a882905
AC
1094 /* NOTE: cagney/2004-05-08: Eliminating this function depends on all
1095 architectures being forced to use the frame-unwind code. */
30a4a8e0 1096 if (deprecated_pc_in_call_dummy (pc))
eb4f72c5
AC
1097 return DUMMY_FRAME;
1098 else
ce12bbf9 1099 return NORMAL_FRAME;
eb4f72c5
AC
1100}
1101
4c1e7e9d
AC
1102/* Create an arbitrary (i.e. address specified by user) or innermost frame.
1103 Always returns a non-NULL value. */
1104
1105struct frame_info *
1106create_new_frame (CORE_ADDR addr, CORE_ADDR pc)
1107{
1108 struct frame_info *fi;
4c1e7e9d 1109
7f78e237
AC
1110 if (frame_debug)
1111 {
1112 fprintf_unfiltered (gdb_stdlog,
1113 "{ create_new_frame (addr=0x%s, pc=0x%s) ",
1114 paddr_nz (addr), paddr_nz (pc));
1115 }
1116
479ab5a0 1117 fi = frame_obstack_zalloc (sizeof (struct frame_info));
4c1e7e9d 1118
a94dd1fd 1119 fi->next = create_sentinel_frame (current_regcache);
7df05f2b
AC
1120
1121 /* Select/initialize both the unwind function and the frame's type
1122 based on the PC. */
82417da5 1123 fi->unwind = frame_unwind_find_by_frame (fi->next, &fi->prologue_cache);
7df05f2b
AC
1124 if (fi->unwind->type != UNKNOWN_FRAME)
1125 fi->type = fi->unwind->type;
1126 else
1127 fi->type = frame_type_from_pc (pc);
1128
18adea3f 1129 fi->this_id.p = 1;
11889732
AC
1130 deprecated_update_frame_base_hack (fi, addr);
1131 deprecated_update_frame_pc_hack (fi, pc);
4c1e7e9d 1132
e9582e71
AC
1133 if (DEPRECATED_INIT_EXTRA_FRAME_INFO_P ())
1134 DEPRECATED_INIT_EXTRA_FRAME_INFO (0, fi);
4c1e7e9d 1135
7f78e237
AC
1136 if (frame_debug)
1137 {
1138 fprintf_unfiltered (gdb_stdlog, "-> ");
1139 fprint_frame (gdb_stdlog, fi);
1140 fprintf_unfiltered (gdb_stdlog, " }\n");
1141 }
1142
4c1e7e9d
AC
1143 return fi;
1144}
1145
03febf99
AC
1146/* Return the frame that THIS_FRAME calls (NULL if THIS_FRAME is the
1147 innermost frame). Be careful to not fall off the bottom of the
1148 frame chain and onto the sentinel frame. */
4c1e7e9d
AC
1149
1150struct frame_info *
03febf99 1151get_next_frame (struct frame_info *this_frame)
4c1e7e9d 1152{
03febf99
AC
1153 if (this_frame->level > 0)
1154 return this_frame->next;
a94dd1fd
AC
1155 else
1156 return NULL;
4c1e7e9d
AC
1157}
1158
f4c5303c
OF
1159/* Observer for the target_changed event. */
1160
1161void
1162frame_observer_target_changed (struct target_ops *target)
1163{
1164 flush_cached_frames ();
1165}
1166
4c1e7e9d
AC
1167/* Flush the entire frame cache. */
1168
1169void
1170flush_cached_frames (void)
1171{
1172 /* Since we can't really be sure what the first object allocated was */
1173 obstack_free (&frame_cache_obstack, 0);
1174 obstack_init (&frame_cache_obstack);
1175
1176 current_frame = NULL; /* Invalidate cache */
1177 select_frame (NULL);
1178 annotate_frames_invalid ();
7f78e237
AC
1179 if (frame_debug)
1180 fprintf_unfiltered (gdb_stdlog, "{ flush_cached_frames () }\n");
4c1e7e9d
AC
1181}
1182
1183/* Flush the frame cache, and start a new one if necessary. */
1184
1185void
1186reinit_frame_cache (void)
1187{
1188 flush_cached_frames ();
1189
1190 /* FIXME: The inferior_ptid test is wrong if there is a corefile. */
1191 if (PIDGET (inferior_ptid) != 0)
1192 {
1193 select_frame (get_current_frame ());
1194 }
1195}
1196
eb4f72c5 1197/* Create the previous frame using the deprecated methods
08be3abd 1198 INIT_EXTRA_INFO, and INIT_FRAME_PC. */
4c1e7e9d 1199
eb4f72c5 1200static struct frame_info *
03febf99 1201legacy_get_prev_frame (struct frame_info *this_frame)
4c1e7e9d
AC
1202{
1203 CORE_ADDR address = 0;
1204 struct frame_info *prev;
95adb866 1205 int fromleaf;
4c1e7e9d 1206
7f78e237
AC
1207 /* Don't frame_debug print legacy_get_prev_frame() here, just
1208 confuses the output. */
1209
a01dd7cc 1210 /* Allocate the new frame.
055bb976
AC
1211
1212 There is no reason to worry about memory leaks, should the
1213 remainder of the function fail. The allocated memory will be
1214 quickly reclaimed when the frame cache is flushed, and the `we've
bbde78fa 1215 been here before' check, in get_prev_frame() will stop repeated
055bb976
AC
1216 memory allocation calls. */
1217 prev = FRAME_OBSTACK_ZALLOC (struct frame_info);
1218 prev->level = this_frame->level + 1;
1219
9564ee9f 1220 /* Do not completely wire it in to the frame chain. Some (bad) code
a01dd7cc
AC
1221 in INIT_FRAME_EXTRA_INFO tries to look along frame->prev to pull
1222 some fancy tricks (of course such code is, by definition,
1223 recursive).
1224
1225 On the other hand, methods, such as get_frame_pc() and
1226 get_frame_base() rely on being able to walk along the frame
1227 chain. Make certain that at least they work by providing that
1228 link. Of course things manipulating prev can't go back. */
1229 prev->next = this_frame;
1230
055bb976
AC
1231 /* NOTE: cagney/2002-11-18: Should have been correctly setting the
1232 frame's type here, before anything else, and not last, at the
1233 bottom of this function. The various
08be3abd 1234 DEPRECATED_INIT_EXTRA_FRAME_INFO, DEPRECATED_INIT_FRAME_PC, and
055bb976
AC
1235 DEPRECATED_FRAME_INIT_SAVED_REGS methods are full of work-arounds
1236 that handle the frame not being correctly set from the start.
ce2826aa 1237 Unfortunately those same work-arounds rely on the type defaulting
055bb976
AC
1238 to NORMAL_FRAME. Ulgh! The new frame code does not have this
1239 problem. */
7df05f2b 1240 prev->type = UNKNOWN_FRAME;
055bb976 1241
06c77151 1242 /* A legacy frame's ID is always computed here. Mark it as valid. */
d0a55772 1243 prev->this_id.p = 1;
06c77151 1244
055bb976
AC
1245 /* Handle sentinel frame unwind as a special case. */
1246 if (this_frame->level < 0)
1247 {
1248 /* Try to unwind the PC. If that doesn't work, assume we've reached
1249 the oldest frame and simply return. Is there a better sentinal
1250 value? The unwound PC value is then used to initialize the new
1251 previous frame's type.
1252
1253 Note that the pc-unwind is intentionally performed before the
1254 frame chain. This is ok since, for old targets, both
bbde78fa 1255 frame_pc_unwind() (nee, DEPRECATED_FRAME_SAVED_PC) and
618ce49f
AC
1256 DEPRECATED_FRAME_CHAIN()) assume THIS_FRAME's data structures
1257 have already been initialized (using
055bb976
AC
1258 DEPRECATED_INIT_EXTRA_FRAME_INFO) and hence the call order
1259 doesn't matter.
1260
1261 By unwinding the PC first, it becomes possible to, in the case of
1262 a dummy frame, avoid also unwinding the frame ID. This is
1263 because (well ignoring the PPC) a dummy frame can be located
1264 using THIS_FRAME's frame ID. */
1265
11889732
AC
1266 deprecated_update_frame_pc_hack (prev, frame_pc_unwind (this_frame));
1267 if (get_frame_pc (prev) == 0)
055bb976
AC
1268 {
1269 /* The allocated PREV_FRAME will be reclaimed when the frame
1270 obstack is next purged. */
1271 if (frame_debug)
7f78e237
AC
1272 {
1273 fprintf_unfiltered (gdb_stdlog, "-> ");
1274 fprint_frame (gdb_stdlog, NULL);
1275 fprintf_unfiltered (gdb_stdlog,
1276 " // unwound legacy PC zero }\n");
1277 }
055bb976
AC
1278 return NULL;
1279 }
055bb976 1280
7df05f2b
AC
1281 /* Set the unwind functions based on that identified PC. Ditto
1282 for the "type" but strongly prefer the unwinder's frame type. */
82417da5
AC
1283 prev->unwind = frame_unwind_find_by_frame (prev->next,
1284 &prev->prologue_cache);
7df05f2b 1285 if (prev->unwind->type == UNKNOWN_FRAME)
d1340264 1286 prev->type = frame_type_from_pc (get_frame_pc (prev));
7df05f2b
AC
1287 else
1288 prev->type = prev->unwind->type;
055bb976
AC
1289
1290 /* Find the prev's frame's ID. */
1291 if (prev->type == DUMMY_FRAME
1292 && gdbarch_unwind_dummy_id_p (current_gdbarch))
1293 {
1294 /* When unwinding a normal frame, the stack structure is
1295 determined by analyzing the frame's function's code (be
1296 it using brute force prologue analysis, or the dwarf2
1297 CFI). In the case of a dummy frame, that simply isn't
1298 possible. The The PC is either the program entry point,
1299 or some random address on the stack. Trying to use that
1300 PC to apply standard frame ID unwind techniques is just
1301 asking for trouble. */
055bb976
AC
1302 /* Use an architecture specific method to extract the prev's
1303 dummy ID from the next frame. Note that this method uses
1304 frame_register_unwind to obtain the register values
1305 needed to determine the dummy frame's ID. */
d0a55772
AC
1306 prev->this_id.value = gdbarch_unwind_dummy_id (current_gdbarch,
1307 this_frame);
055bb976
AC
1308 }
1309 else
1310 {
1311 /* We're unwinding a sentinel frame, the PC of which is
1312 pointing at a stack dummy. Fake up the dummy frame's ID
1313 using the same sequence as is found a traditional
1314 unwinder. Once all architectures supply the
1315 unwind_dummy_id method, this code can go away. */
0ba6dca9
AC
1316 prev->this_id.value = frame_id_build (deprecated_read_fp (),
1317 read_pc ());
055bb976
AC
1318 }
1319
1320 /* Check that the unwound ID is valid. */
d0a55772 1321 if (!frame_id_p (prev->this_id.value))
055bb976
AC
1322 {
1323 if (frame_debug)
7f78e237
AC
1324 {
1325 fprintf_unfiltered (gdb_stdlog, "-> ");
1326 fprint_frame (gdb_stdlog, NULL);
1327 fprintf_unfiltered (gdb_stdlog,
1328 " // unwound legacy ID invalid }\n");
1329 }
055bb976
AC
1330 return NULL;
1331 }
1332
1333 /* Check that the new frame isn't inner to (younger, below,
1334 next) the old frame. If that happens the frame unwind is
1335 going backwards. */
1336 /* FIXME: cagney/2003-02-25: Ignore the sentinel frame since
1337 that doesn't have a valid frame ID. Should instead set the
1338 sentinel frame's frame ID to a `sentinel'. Leave it until
1339 after the switch to storing the frame ID, instead of the
1340 frame base, in the frame object. */
1341
055bb976
AC
1342 /* Link it in. */
1343 this_frame->prev = prev;
055bb976
AC
1344
1345 /* FIXME: cagney/2002-01-19: This call will go away. Instead of
1346 initializing extra info, all frames will use the frame_cache
1347 (passed to the unwind functions) to store additional frame
ce2826aa 1348 info. Unfortunately legacy targets can't use
055bb976
AC
1349 legacy_get_prev_frame() to unwind the sentinel frame and,
1350 consequently, are forced to take this code path and rely on
1351 the below call to DEPRECATED_INIT_EXTRA_FRAME_INFO to
1352 initialize the inner-most frame. */
1353 if (DEPRECATED_INIT_EXTRA_FRAME_INFO_P ())
1354 {
1355 DEPRECATED_INIT_EXTRA_FRAME_INFO (0, prev);
1356 }
18adea3f
AC
1357
1358 if (prev->type == NORMAL_FRAME)
1359 prev->this_id.value.code_addr
1360 = get_pc_function_start (prev->this_id.value.code_addr);
1361
7f78e237
AC
1362 if (frame_debug)
1363 {
1364 fprintf_unfiltered (gdb_stdlog, "-> ");
1365 fprint_frame (gdb_stdlog, prev);
1366 fprintf_unfiltered (gdb_stdlog, " } // legacy innermost frame\n");
1367 }
055bb976
AC
1368 return prev;
1369 }
1370
eb4f72c5
AC
1371 /* This code only works on normal frames. A sentinel frame, where
1372 the level is -1, should never reach this code. */
03febf99 1373 gdb_assert (this_frame->level >= 0);
4c1e7e9d
AC
1374
1375 /* On some machines it is possible to call a function without
1376 setting up a stack frame for it. On these machines, we
1377 define this macro to take two args; a frameinfo pointer
1378 identifying a frame and a variable to set or clear if it is
1379 or isn't leafless. */
1380
1381 /* Still don't want to worry about this except on the innermost
03febf99 1382 frame. This macro will set FROMLEAF if THIS_FRAME is a frameless
95adb866 1383 function invocation. */
03febf99 1384 if (this_frame->level == 0)
bbde78fa 1385 /* FIXME: 2002-11-09: Frameless functions can occur anywhere in
95adb866
AC
1386 the frame chain, not just the inner most frame! The generic,
1387 per-architecture, frame code should handle this and the below
1388 should simply be removed. */
19772a2c
AC
1389 fromleaf = (DEPRECATED_FRAMELESS_FUNCTION_INVOCATION_P ()
1390 && DEPRECATED_FRAMELESS_FUNCTION_INVOCATION (this_frame));
95adb866
AC
1391 else
1392 fromleaf = 0;
1393
1394 if (fromleaf)
1395 /* A frameless inner-most frame. The `FP' (which isn't an
1396 architecture frame-pointer register!) of the caller is the same
1397 as the callee. */
1398 /* FIXME: 2002-11-09: There isn't any reason to special case this
bbde78fa 1399 edge condition. Instead the per-architecture code should handle
95adb866 1400 it locally. */
870b3035
AC
1401 /* FIXME: cagney/2003-06-16: This returns the inner most stack
1402 address for the previous frame, that, however, is wrong. It
1403 should be the inner most stack address for the previous to
1404 previous frame. This is because it is the previous to previous
1405 frame's innermost stack address that is constant through out
1406 the lifetime of the previous frame (trust me :-). */
03febf99 1407 address = get_frame_base (this_frame);
95adb866 1408 else
4c1e7e9d
AC
1409 {
1410 /* Two macros defined in tm.h specify the machine-dependent
1411 actions to be performed here.
95adb866 1412
4c1e7e9d 1413 First, get the frame's chain-pointer.
95adb866 1414
4c1e7e9d
AC
1415 If that is zero, the frame is the outermost frame or a leaf
1416 called by the outermost frame. This means that if start
1417 calls main without a frame, we'll return 0 (which is fine
1418 anyway).
1419
1420 Nope; there's a problem. This also returns when the current
1421 routine is a leaf of main. This is unacceptable. We move
1422 this to after the ffi test; I'd rather have backtraces from
1423 start go curfluy than have an abort called from main not show
1424 main. */
870b3035
AC
1425 if (DEPRECATED_FRAME_CHAIN_P ())
1426 address = DEPRECATED_FRAME_CHAIN (this_frame);
1427 else
1428 {
1429 /* Someone is part way through coverting an old architecture
1430 to the new frame code. Implement FRAME_CHAIN the way the
1431 new frame will. */
1432 /* Find PREV frame's unwinder. */
82417da5
AC
1433 prev->unwind = frame_unwind_find_by_frame (this_frame,
1434 &prev->prologue_cache);
55699d59
AC
1435 /* FIXME: cagney/2004-05-01: Should instead just use
1436 ->unwind->type. Unfortunately, legacy_get_prev_frame is
1437 still explicitly setting the type. Eliminate that method
1438 and this field can be eliminated. */
870b3035
AC
1439 prev->type = prev->unwind->type;
1440 /* Find PREV frame's ID. */
1441 prev->unwind->this_id (this_frame,
1442 &prev->prologue_cache,
1443 &prev->this_id.value);
1444 prev->this_id.p = 1;
1445 address = prev->this_id.value.stack_addr;
1446 }
4c1e7e9d 1447
e6ba3bc9 1448 if (!legacy_frame_chain_valid (address, this_frame))
7f78e237
AC
1449 {
1450 if (frame_debug)
1451 {
1452 fprintf_unfiltered (gdb_stdlog, "-> ");
1453 fprint_frame (gdb_stdlog, NULL);
1454 fprintf_unfiltered (gdb_stdlog,
1455 " // legacy frame chain invalid }\n");
1456 }
1457 return NULL;
1458 }
4c1e7e9d
AC
1459 }
1460 if (address == 0)
7f78e237
AC
1461 {
1462 if (frame_debug)
1463 {
1464 fprintf_unfiltered (gdb_stdlog, "-> ");
1465 fprint_frame (gdb_stdlog, NULL);
1466 fprintf_unfiltered (gdb_stdlog,
1467 " // legacy frame chain NULL }\n");
1468 }
1469 return NULL;
1470 }
4c1e7e9d 1471
055bb976 1472 /* Link in the already allocated prev frame. */
03febf99 1473 this_frame->prev = prev;
11889732 1474 deprecated_update_frame_base_hack (prev, address);
4c1e7e9d 1475
95adb866 1476 /* This change should not be needed, FIXME! We should determine
a5afb99f 1477 whether any targets *need* DEPRECATED_INIT_FRAME_PC to happen
e9582e71
AC
1478 after DEPRECATED_INIT_EXTRA_FRAME_INFO and come up with a simple
1479 way to express what goes on here.
95adb866 1480
e9582e71
AC
1481 DEPRECATED_INIT_EXTRA_FRAME_INFO is called from two places:
1482 create_new_frame (where the PC is already set up) and here (where
1483 it isn't). DEPRECATED_INIT_FRAME_PC is only called from here,
1484 always after DEPRECATED_INIT_EXTRA_FRAME_INFO.
95adb866 1485
e9582e71
AC
1486 The catch is the MIPS, where DEPRECATED_INIT_EXTRA_FRAME_INFO
1487 requires the PC value (which hasn't been set yet). Some other
1488 machines appear to require DEPRECATED_INIT_EXTRA_FRAME_INFO
1489 before they can do DEPRECATED_INIT_FRAME_PC. Phoo.
95adb866 1490
a5afb99f 1491 Assuming that some machines need DEPRECATED_INIT_FRAME_PC after
e9582e71 1492 DEPRECATED_INIT_EXTRA_FRAME_INFO, one possible scheme:
95adb866
AC
1493
1494 SETUP_INNERMOST_FRAME(): Default version is just create_new_frame
0ba6dca9
AC
1495 (deprecated_read_fp ()), read_pc ()). Machines with extra frame
1496 info would do that (or the local equivalent) and then set the
1497 extra fields.
95adb866
AC
1498
1499 SETUP_ARBITRARY_FRAME(argc, argv): Only change here is that
1500 create_new_frame would no longer init extra frame info;
1501 SETUP_ARBITRARY_FRAME would have to do that.
1502
e9582e71
AC
1503 INIT_PREV_FRAME(fromleaf, prev) Replace
1504 DEPRECATED_INIT_EXTRA_FRAME_INFO and DEPRECATED_INIT_FRAME_PC.
1505 This should also return a flag saying whether to keep the new
1506 frame, or whether to discard it, because on some machines (e.g.
618ce49f
AC
1507 mips) it is really awkward to have DEPRECATED_FRAME_CHAIN_VALID
1508 called BEFORE DEPRECATED_INIT_EXTRA_FRAME_INFO (there is no good
1509 way to get information deduced in DEPRECATED_FRAME_CHAIN_VALID
1510 into the extra fields of the new frame). std_frame_pc(fromleaf,
1511 prev)
95adb866
AC
1512
1513 This is the default setting for INIT_PREV_FRAME. It just does
a5afb99f
AC
1514 what the default DEPRECATED_INIT_FRAME_PC does. Some machines
1515 will call it from INIT_PREV_FRAME (either at the beginning, the
1516 end, or in the middle). Some machines won't use it.
95adb866
AC
1517
1518 kingdon@cygnus.com, 13Apr93, 31Jan94, 14Dec94. */
1519
1520 /* NOTE: cagney/2002-11-09: Just ignore the above! There is no
1521 reason for things to be this complicated.
1522
1523 The trick is to assume that there is always a frame. Instead of
bbde78fa 1524 special casing the inner-most frame, create a fake frame
95adb866
AC
1525 (containing the hardware registers) that is inner to the
1526 user-visible inner-most frame (...) and then unwind from that.
bbde78fa 1527 That way architecture code can use the standard
95adb866
AC
1528 frame_XX_unwind() functions and not differentiate between the
1529 inner most and any other case.
1530
1531 Since there is always a frame to unwind from, there is always
03febf99 1532 somewhere (THIS_FRAME) to store all the info needed to construct
95adb866
AC
1533 a new (previous) frame without having to first create it. This
1534 means that the convolution below - needing to carefully order a
1535 frame's initialization - isn't needed.
1536
618ce49f
AC
1537 The irony here though, is that DEPRECATED_FRAME_CHAIN(), at least
1538 for a more up-to-date architecture, always calls
1539 FRAME_SAVED_PC(), and FRAME_SAVED_PC() computes the PC but
1540 without first needing the frame! Instead of the convolution
1541 below, we could have simply called FRAME_SAVED_PC() and been done
bbde78fa 1542 with it! Note that FRAME_SAVED_PC() is being superseded by
618ce49f
AC
1543 frame_pc_unwind() and that function does have somewhere to cache
1544 that PC value. */
4c1e7e9d 1545
e9582e71
AC
1546 if (DEPRECATED_INIT_EXTRA_FRAME_INFO_P ())
1547 DEPRECATED_INIT_EXTRA_FRAME_INFO (fromleaf, prev);
4c1e7e9d
AC
1548
1549 /* This entry is in the frame queue now, which is good since
95adb866 1550 FRAME_SAVED_PC may use that queue to figure out its value (see
bbde78fa 1551 tm-sparc.h). We want the PC saved in the inferior frame. */
a5afb99f 1552 if (DEPRECATED_INIT_FRAME_PC_P ())
11889732
AC
1553 deprecated_update_frame_pc_hack (prev,
1554 DEPRECATED_INIT_FRAME_PC (fromleaf,
1555 prev));
4c1e7e9d 1556
95adb866
AC
1557 /* If ->frame and ->pc are unchanged, we are in the process of
1558 getting ourselves into an infinite backtrace. Some architectures
618ce49f
AC
1559 check this in DEPRECATED_FRAME_CHAIN or thereabouts, but it seems
1560 like there is no reason this can't be an architecture-independent
1561 check. */
11889732
AC
1562 if (get_frame_base (prev) == get_frame_base (this_frame)
1563 && get_frame_pc (prev) == get_frame_pc (this_frame))
4c1e7e9d 1564 {
03febf99 1565 this_frame->prev = NULL;
95adb866 1566 obstack_free (&frame_cache_obstack, prev);
7f78e237
AC
1567 if (frame_debug)
1568 {
1569 fprintf_unfiltered (gdb_stdlog, "-> ");
1570 fprint_frame (gdb_stdlog, NULL);
1571 fprintf_unfiltered (gdb_stdlog,
1572 " // legacy this.id == prev.id }\n");
1573 }
95adb866 1574 return NULL;
4c1e7e9d
AC
1575 }
1576
1577 /* Initialize the code used to unwind the frame PREV based on the PC
1578 (and probably other architectural information). The PC lets you
1579 check things like the debug info at that point (dwarf2cfi?) and
870b3035
AC
1580 use that to decide how the frame should be unwound.
1581
1582 If there isn't a FRAME_CHAIN, the code above will have already
1583 done this. */
1584 if (prev->unwind == NULL)
82417da5
AC
1585 prev->unwind = frame_unwind_find_by_frame (prev->next,
1586 &prev->prologue_cache);
4c1e7e9d 1587
bbde78fa 1588 /* If the unwinder provides a frame type, use it. Otherwise
7df05f2b
AC
1589 continue on to that heuristic mess. */
1590 if (prev->unwind->type != UNKNOWN_FRAME)
1591 {
1592 prev->type = prev->unwind->type;
18adea3f 1593 if (prev->type == NORMAL_FRAME)
870b3035 1594 /* FIXME: cagney/2003-06-16: would get_frame_pc() be better? */
18adea3f
AC
1595 prev->this_id.value.code_addr
1596 = get_pc_function_start (prev->this_id.value.code_addr);
7f78e237
AC
1597 if (frame_debug)
1598 {
1599 fprintf_unfiltered (gdb_stdlog, "-> ");
1600 fprint_frame (gdb_stdlog, prev);
1601 fprintf_unfiltered (gdb_stdlog, " } // legacy with unwound type\n");
1602 }
7df05f2b
AC
1603 return prev;
1604 }
1605
5a203e44 1606 /* NOTE: cagney/2002-11-18: The code segments, found in
bbde78fa
JM
1607 create_new_frame() and get_prev_frame(), that initialize the
1608 frame's type is subtly different. The latter only updates ->type
5a203e44
AC
1609 when it encounters a SIGTRAMP_FRAME or DUMMY_FRAME. This stops
1610 get_prev_frame() overriding the frame's type when the INIT code
1611 has previously set it. This is really somewhat bogus. The
1612 initialization, as seen in create_new_frame(), should occur
1613 before the INIT function has been called. */
30a4a8e0 1614 if (deprecated_pc_in_call_dummy (get_frame_pc (prev)))
5a203e44 1615 prev->type = DUMMY_FRAME;
4c1e7e9d 1616
18adea3f
AC
1617 if (prev->type == NORMAL_FRAME)
1618 prev->this_id.value.code_addr
1619 = get_pc_function_start (prev->this_id.value.code_addr);
1620
7f78e237
AC
1621 if (frame_debug)
1622 {
1623 fprintf_unfiltered (gdb_stdlog, "-> ");
1624 fprint_frame (gdb_stdlog, prev);
1625 fprintf_unfiltered (gdb_stdlog, " } // legacy with confused type\n");
1626 }
1627
4c1e7e9d
AC
1628 return prev;
1629}
1630
5613d8d3
AC
1631/* Return a "struct frame_info" corresponding to the frame that called
1632 THIS_FRAME. Returns NULL if there is no such frame.
5bf00f29 1633
5613d8d3
AC
1634 Unlike get_prev_frame, this function always tries to unwind the
1635 frame. */
eb4f72c5 1636
5613d8d3
AC
1637static struct frame_info *
1638get_prev_frame_1 (struct frame_info *this_frame)
eb4f72c5
AC
1639{
1640 struct frame_info *prev_frame;
756e95f1 1641 struct frame_id this_id;
eb4f72c5 1642
5613d8d3
AC
1643 gdb_assert (this_frame != NULL);
1644
7f78e237
AC
1645 if (frame_debug)
1646 {
5613d8d3 1647 fprintf_unfiltered (gdb_stdlog, "{ get_prev_frame_1 (this_frame=");
7f78e237
AC
1648 if (this_frame != NULL)
1649 fprintf_unfiltered (gdb_stdlog, "%d", this_frame->level);
1650 else
1651 fprintf_unfiltered (gdb_stdlog, "<NULL>");
1652 fprintf_unfiltered (gdb_stdlog, ") ");
1653 }
1654
5613d8d3
AC
1655 /* Only try to do the unwind once. */
1656 if (this_frame->prev_p)
1657 {
1658 if (frame_debug)
1659 {
1660 fprintf_unfiltered (gdb_stdlog, "-> ");
1661 fprint_frame (gdb_stdlog, this_frame->prev);
1662 fprintf_unfiltered (gdb_stdlog, " // cached \n");
1663 }
1664 return this_frame->prev;
1665 }
1666 this_frame->prev_p = 1;
1667
1668 /* If any of the old frame initialization methods are around, use
bbde78fa 1669 the legacy get_prev_frame() method. */
5613d8d3
AC
1670 if (legacy_frame_p (current_gdbarch))
1671 {
1672 prev_frame = legacy_get_prev_frame (this_frame);
1673 return prev_frame;
1674 }
1675
1676 /* Check that this frame's ID was valid. If it wasn't, don't try to
1677 unwind to the prev frame. Be careful to not apply this test to
1678 the sentinel frame. */
756e95f1
MK
1679 this_id = get_frame_id (this_frame);
1680 if (this_frame->level >= 0 && !frame_id_p (this_id))
5613d8d3
AC
1681 {
1682 if (frame_debug)
1683 {
1684 fprintf_unfiltered (gdb_stdlog, "-> ");
1685 fprint_frame (gdb_stdlog, NULL);
1686 fprintf_unfiltered (gdb_stdlog, " // this ID is NULL }\n");
1687 }
1688 return NULL;
1689 }
1690
1691 /* Check that this frame's ID isn't inner to (younger, below, next)
1692 the next frame. This happens when a frame unwind goes backwards.
adb54772
AC
1693 Exclude signal trampolines (due to sigaltstack the frame ID can
1694 go backwards) and sentinel frames (the test is meaningless). */
1695 if (this_frame->next->level >= 0
1696 && this_frame->next->type != SIGTRAMP_FRAME
756e95f1 1697 && frame_id_inner (this_id, get_frame_id (this_frame->next)))
5613d8d3
AC
1698 error ("Previous frame inner to this frame (corrupt stack?)");
1699
1700 /* Check that this and the next frame are not identical. If they
1701 are, there is most likely a stack cycle. As with the inner-than
1702 test above, avoid comparing the inner-most and sentinel frames. */
1703 if (this_frame->level > 0
756e95f1 1704 && frame_id_eq (this_id, get_frame_id (this_frame->next)))
5613d8d3
AC
1705 error ("Previous frame identical to this frame (corrupt stack?)");
1706
1707 /* Allocate the new frame but do not wire it in to the frame chain.
1708 Some (bad) code in INIT_FRAME_EXTRA_INFO tries to look along
1709 frame->next to pull some fancy tricks (of course such code is, by
1710 definition, recursive). Try to prevent it.
1711
1712 There is no reason to worry about memory leaks, should the
1713 remainder of the function fail. The allocated memory will be
1714 quickly reclaimed when the frame cache is flushed, and the `we've
1715 been here before' check above will stop repeated memory
1716 allocation calls. */
1717 prev_frame = FRAME_OBSTACK_ZALLOC (struct frame_info);
1718 prev_frame->level = this_frame->level + 1;
1719
1720 /* Don't yet compute ->unwind (and hence ->type). It is computed
1721 on-demand in get_frame_type, frame_register_unwind, and
1722 get_frame_id. */
1723
1724 /* Don't yet compute the frame's ID. It is computed on-demand by
1725 get_frame_id(). */
1726
1727 /* The unwound frame ID is validate at the start of this function,
1728 as part of the logic to decide if that frame should be further
1729 unwound, and not here while the prev frame is being created.
1730 Doing this makes it possible for the user to examine a frame that
1731 has an invalid frame ID.
1732
1733 Some very old VAX code noted: [...] For the sake of argument,
1734 suppose that the stack is somewhat trashed (which is one reason
1735 that "info frame" exists). So, return 0 (indicating we don't
1736 know the address of the arglist) if we don't know what frame this
1737 frame calls. */
1738
1739 /* Link it in. */
1740 this_frame->prev = prev_frame;
1741 prev_frame->next = this_frame;
1742
1743 if (frame_debug)
1744 {
1745 fprintf_unfiltered (gdb_stdlog, "-> ");
1746 fprint_frame (gdb_stdlog, prev_frame);
1747 fprintf_unfiltered (gdb_stdlog, " }\n");
1748 }
1749
1750 return prev_frame;
1751}
1752
1753/* Debug routine to print a NULL frame being returned. */
1754
1755static void
1756frame_debug_got_null_frame (struct ui_file *file,
1757 struct frame_info *this_frame,
1758 const char *reason)
1759{
1760 if (frame_debug)
1761 {
1762 fprintf_unfiltered (gdb_stdlog, "{ get_prev_frame (this_frame=");
1763 if (this_frame != NULL)
1764 fprintf_unfiltered (gdb_stdlog, "%d", this_frame->level);
1765 else
1766 fprintf_unfiltered (gdb_stdlog, "<NULL>");
1767 fprintf_unfiltered (gdb_stdlog, ") -> // %s}\n", reason);
1768 }
1769}
1770
1771/* Return a structure containing various interesting information about
1772 the frame that called THIS_FRAME. Returns NULL if there is entier
1773 no such frame or the frame fails any of a set of target-independent
1774 condition that should terminate the frame chain (e.g., as unwinding
1775 past main()).
1776
1777 This function should not contain target-dependent tests, such as
1778 checking whether the program-counter is zero. */
1779
1780struct frame_info *
1781get_prev_frame (struct frame_info *this_frame)
1782{
1783 struct frame_info *prev_frame;
1784
eb4f72c5
AC
1785 /* Return the inner-most frame, when the caller passes in NULL. */
1786 /* NOTE: cagney/2002-11-09: Not sure how this would happen. The
1787 caller should have previously obtained a valid frame using
1788 get_selected_frame() and then called this code - only possibility
1789 I can think of is code behaving badly.
1790
1791 NOTE: cagney/2003-01-10: Talk about code behaving badly. Check
1792 block_innermost_frame(). It does the sequence: frame = NULL;
1793 while (1) { frame = get_prev_frame (frame); .... }. Ulgh! Why
1794 it couldn't be written better, I don't know.
1795
bbde78fa 1796 NOTE: cagney/2003-01-11: I suspect what is happening in
eb4f72c5 1797 block_innermost_frame() is, when the target has no state
bbde78fa 1798 (registers, memory, ...), it is still calling this function. The
eb4f72c5
AC
1799 assumption being that this function will return NULL indicating
1800 that a frame isn't possible, rather than checking that the target
1801 has state and then calling get_current_frame() and
1802 get_prev_frame(). This is a guess mind. */
03febf99 1803 if (this_frame == NULL)
eb4f72c5
AC
1804 {
1805 /* NOTE: cagney/2002-11-09: There was a code segment here that
1806 would error out when CURRENT_FRAME was NULL. The comment
1807 that went with it made the claim ...
1808
1809 ``This screws value_of_variable, which just wants a nice
1810 clean NULL return from block_innermost_frame if there are no
1811 frames. I don't think I've ever seen this message happen
1812 otherwise. And returning NULL here is a perfectly legitimate
1813 thing to do.''
1814
1815 Per the above, this code shouldn't even be called with a NULL
03febf99 1816 THIS_FRAME. */
5613d8d3 1817 frame_debug_got_null_frame (gdb_stdlog, this_frame, "this_frame NULL");
eb4f72c5
AC
1818 return current_frame;
1819 }
1820
1821 /* There is always a frame. If this assertion fails, suspect that
1822 something should be calling get_selected_frame() or
1823 get_current_frame(). */
03febf99 1824 gdb_assert (this_frame != NULL);
eb4f72c5 1825
3f1d7f16 1826 /* Make sure we pass an address within THIS_FRAME's code block to
bbde78fa 1827 inside_main_func(). Otherwise, we might stop unwinding at a
3f1d7f16
MK
1828 function which has a call instruction as its last instruction if
1829 that function immediately precedes main(). */
03febf99 1830 if (this_frame->level >= 0
25d29d70 1831 && !backtrace_past_main
3f1d7f16 1832 && inside_main_func (get_frame_address_in_block (this_frame)))
bbde78fa 1833 /* Don't unwind past main(), but always unwind the sentinel frame.
eb4f72c5
AC
1834 Note, this is done _before_ the frame has been marked as
1835 previously unwound. That way if the user later decides to
1836 allow unwinds past main(), that just happens. */
ac2bd0a9 1837 {
5613d8d3 1838 frame_debug_got_null_frame (gdb_stdlog, this_frame, "inside main func");
ac2bd0a9
AC
1839 return NULL;
1840 }
eb4f72c5 1841
25d29d70
AC
1842 if (this_frame->level > backtrace_limit)
1843 {
1844 error ("Backtrace limit of %d exceeded", backtrace_limit);
1845 }
1846
0714963c
AC
1847 /* If we're already inside the entry function for the main objfile,
1848 then it isn't valid. Don't apply this test to a dummy frame -
bbde78fa 1849 dummy frame PCs typically land in the entry func. Don't apply
0714963c
AC
1850 this test to the sentinel frame. Sentinel frames should always
1851 be allowed to unwind. */
1852 /* NOTE: cagney/2003-02-25: Don't enable until someone has found
1853 hard evidence that this is needed. */
2f72f850
AC
1854 /* NOTE: cagney/2003-07-07: Fixed a bug in inside_main_func() -
1855 wasn't checking for "main" in the minimal symbols. With that
1856 fixed asm-source tests now stop in "main" instead of halting the
bbde78fa 1857 backtrace in weird and wonderful ways somewhere inside the entry
2f72f850
AC
1858 file. Suspect that tests for inside the entry file/func were
1859 added to work around that (now fixed) case. */
0714963c
AC
1860 /* NOTE: cagney/2003-07-15: danielj (if I'm reading it right)
1861 suggested having the inside_entry_func test use the
bbde78fa
JM
1862 inside_main_func() msymbol trick (along with entry_point_address()
1863 I guess) to determine the address range of the start function.
0714963c
AC
1864 That should provide a far better stopper than the current
1865 heuristics. */
1866 /* NOTE: cagney/2003-07-15: Need to add a "set backtrace
1867 beyond-entry-func" command so that this can be selectively
1868 disabled. */
1869 if (0
1870#if 0
1871 && backtrace_beyond_entry_func
1872#endif
1873 && this_frame->type != DUMMY_FRAME && this_frame->level >= 0
6e4c6c91 1874 && inside_entry_func (this_frame))
0714963c 1875 {
5613d8d3 1876 frame_debug_got_null_frame (gdb_stdlog, this_frame, "inside entry func");
0714963c
AC
1877 return NULL;
1878 }
1879
5613d8d3 1880 return get_prev_frame_1 (this_frame);
eb4f72c5
AC
1881}
1882
4c1e7e9d
AC
1883CORE_ADDR
1884get_frame_pc (struct frame_info *frame)
1885{
d1340264
AC
1886 gdb_assert (frame->next != NULL);
1887 return frame_pc_unwind (frame->next);
4c1e7e9d
AC
1888}
1889
8edd5d01
AC
1890/* Return an address of that falls within the frame's code block. */
1891
1892CORE_ADDR
1893frame_unwind_address_in_block (struct frame_info *next_frame)
1894{
1895 /* A draft address. */
1896 CORE_ADDR pc = frame_pc_unwind (next_frame);
1897
1898 /* If THIS frame is not inner most (i.e., NEXT isn't the sentinel),
1899 and NEXT is `normal' (i.e., not a sigtramp, dummy, ....) THIS
1900 frame's PC ends up pointing at the instruction fallowing the
1901 "call". Adjust that PC value so that it falls on the call
1902 instruction (which, hopefully, falls within THIS frame's code
1903 block. So far it's proved to be a very good approximation. See
bbde78fa 1904 get_frame_type() for why ->type can't be used. */
8edd5d01
AC
1905 if (next_frame->level >= 0
1906 && get_frame_type (next_frame) == NORMAL_FRAME)
1907 --pc;
1908 return pc;
1909}
1910
1911CORE_ADDR
1912get_frame_address_in_block (struct frame_info *this_frame)
1913{
1914 return frame_unwind_address_in_block (this_frame->next);
1915}
1916
1058bca7
AC
1917static int
1918pc_notcurrent (struct frame_info *frame)
1919{
1920 /* If FRAME is not the innermost frame, that normally means that
1921 FRAME->pc points at the return instruction (which is *after* the
1922 call instruction), and we want to get the line containing the
1923 call (because the call is where the user thinks the program is).
1924 However, if the next frame is either a SIGTRAMP_FRAME or a
1925 DUMMY_FRAME, then the next frame will contain a saved interrupt
1926 PC and such a PC indicates the current (rather than next)
1927 instruction/line, consequently, for such cases, want to get the
1928 line containing fi->pc. */
1929 struct frame_info *next = get_next_frame (frame);
1930 int notcurrent = (next != NULL && get_frame_type (next) == NORMAL_FRAME);
1931 return notcurrent;
1932}
1933
1934void
1935find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal)
1936{
11889732 1937 (*sal) = find_pc_line (get_frame_pc (frame), pc_notcurrent (frame));
1058bca7
AC
1938}
1939
c193f6ac
AC
1940/* Per "frame.h", return the ``address'' of the frame. Code should
1941 really be using get_frame_id(). */
1942CORE_ADDR
1943get_frame_base (struct frame_info *fi)
1944{
d0a55772 1945 return get_frame_id (fi).stack_addr;
c193f6ac
AC
1946}
1947
da62e633
AC
1948/* High-level offsets into the frame. Used by the debug info. */
1949
1950CORE_ADDR
1951get_frame_base_address (struct frame_info *fi)
1952{
7df05f2b 1953 if (get_frame_type (fi) != NORMAL_FRAME)
da62e633
AC
1954 return 0;
1955 if (fi->base == NULL)
e8a89fe2 1956 fi->base = frame_base_find_by_frame (fi->next);
da62e633
AC
1957 /* Sneaky: If the low-level unwind and high-level base code share a
1958 common unwinder, let them share the prologue cache. */
1959 if (fi->base->unwind == fi->unwind)
1960 return fi->base->this_base (fi->next, &fi->prologue_cache);
1961 return fi->base->this_base (fi->next, &fi->base_cache);
1962}
1963
1964CORE_ADDR
1965get_frame_locals_address (struct frame_info *fi)
1966{
1967 void **cache;
7df05f2b 1968 if (get_frame_type (fi) != NORMAL_FRAME)
da62e633
AC
1969 return 0;
1970 /* If there isn't a frame address method, find it. */
1971 if (fi->base == NULL)
e8a89fe2 1972 fi->base = frame_base_find_by_frame (fi->next);
da62e633
AC
1973 /* Sneaky: If the low-level unwind and high-level base code share a
1974 common unwinder, let them share the prologue cache. */
1975 if (fi->base->unwind == fi->unwind)
1976 cache = &fi->prologue_cache;
1977 else
1978 cache = &fi->base_cache;
1979 return fi->base->this_locals (fi->next, cache);
1980}
1981
1982CORE_ADDR
1983get_frame_args_address (struct frame_info *fi)
1984{
1985 void **cache;
7df05f2b 1986 if (get_frame_type (fi) != NORMAL_FRAME)
da62e633
AC
1987 return 0;
1988 /* If there isn't a frame address method, find it. */
1989 if (fi->base == NULL)
e8a89fe2 1990 fi->base = frame_base_find_by_frame (fi->next);
da62e633
AC
1991 /* Sneaky: If the low-level unwind and high-level base code share a
1992 common unwinder, let them share the prologue cache. */
1993 if (fi->base->unwind == fi->unwind)
1994 cache = &fi->prologue_cache;
1995 else
1996 cache = &fi->base_cache;
1997 return fi->base->this_args (fi->next, cache);
1998}
1999
85cf597a
AC
2000/* Level of the selected frame: 0 for innermost, 1 for its caller, ...
2001 or -1 for a NULL frame. */
2002
2003int
2004frame_relative_level (struct frame_info *fi)
2005{
2006 if (fi == NULL)
2007 return -1;
2008 else
2009 return fi->level;
2010}
2011
5a203e44
AC
2012enum frame_type
2013get_frame_type (struct frame_info *frame)
2014{
710ee10a
KB
2015 /* Some legacy code, e.g, mips_init_extra_frame_info() wants
2016 to determine the frame's type prior to it being completely
2017 initialized. Don't attempt to lazily initialize ->unwind for
2018 legacy code. It will be initialized in legacy_get_prev_frame(). */
2019 if (frame->unwind == NULL && !legacy_frame_p (current_gdbarch))
c50901fd 2020 {
bbde78fa 2021 /* Initialize the frame's unwinder because that's what
c50901fd 2022 provides the frame's type. */
82417da5
AC
2023 frame->unwind = frame_unwind_find_by_frame (frame->next,
2024 &frame->prologue_cache);
55699d59
AC
2025 /* FIXME: cagney/2004-05-01: Should instead just use
2026 ->unwind->type. Unfortunately, legacy_get_prev_frame is
2027 still explicitly setting the type. Eliminate that method and
2028 this field can be eliminated. */
c50901fd
AC
2029 frame->type = frame->unwind->type;
2030 }
7df05f2b
AC
2031 if (frame->type == UNKNOWN_FRAME)
2032 return NORMAL_FRAME;
2033 else
2034 return frame->type;
5a203e44
AC
2035}
2036
0394eb2a
AC
2037struct frame_extra_info *
2038get_frame_extra_info (struct frame_info *fi)
2039{
2040 return fi->extra_info;
2041}
2042
2c517d0e
AC
2043struct frame_extra_info *
2044frame_extra_info_zalloc (struct frame_info *fi, long size)
2045{
479ab5a0 2046 fi->extra_info = frame_obstack_zalloc (size);
2c517d0e
AC
2047 return fi->extra_info;
2048}
2049
b87efeee 2050void
2f107107 2051deprecated_update_frame_pc_hack (struct frame_info *frame, CORE_ADDR pc)
b87efeee 2052{
7f78e237
AC
2053 if (frame_debug)
2054 fprintf_unfiltered (gdb_stdlog,
2055 "{ deprecated_update_frame_pc_hack (frame=%d,pc=0x%s) }\n",
2056 frame->level, paddr_nz (pc));
e0d2ae16 2057 /* NOTE: cagney/2003-03-11: Some architectures (e.g., Arm) are
bbde78fa 2058 maintaining a locally allocated frame object. Since such frames
e0d2ae16
AC
2059 are not in the frame chain, it isn't possible to assume that the
2060 frame has a next. Sigh. */
2061 if (frame->next != NULL)
2062 {
2063 /* While we're at it, update this frame's cached PC value, found
2064 in the next frame. Oh for the day when "struct frame_info"
2065 is opaque and this hack on hack can just go away. */
d1340264
AC
2066 frame->next->prev_pc.value = pc;
2067 frame->next->prev_pc.p = 1;
e0d2ae16 2068 }
2f107107
AC
2069}
2070
2071void
2072deprecated_update_frame_base_hack (struct frame_info *frame, CORE_ADDR base)
2073{
7f78e237
AC
2074 if (frame_debug)
2075 fprintf_unfiltered (gdb_stdlog,
2076 "{ deprecated_update_frame_base_hack (frame=%d,base=0x%s) }\n",
2077 frame->level, paddr_nz (base));
2f107107 2078 /* See comment in "frame.h". */
d0a55772 2079 frame->this_id.value.stack_addr = base;
b87efeee
AC
2080}
2081
c8b8a898 2082struct frame_info *
213cc0ad
AC
2083deprecated_frame_xmalloc_with_cleanup (long sizeof_saved_regs,
2084 long sizeof_extra_info)
c8b8a898 2085{
bcf7d3ca
AC
2086 struct frame_info *frame = XMALLOC (struct frame_info);
2087 memset (frame, 0, sizeof (*frame));
18adea3f 2088 frame->this_id.p = 1;
f6c609c4
AC
2089 make_cleanup (xfree, frame);
2090 if (sizeof_saved_regs > 0)
2091 {
2092 frame->saved_regs = xcalloc (1, sizeof_saved_regs);
2093 make_cleanup (xfree, frame->saved_regs);
2094 }
2095 if (sizeof_extra_info > 0)
2096 {
2097 frame->extra_info = xcalloc (1, sizeof_extra_info);
2098 make_cleanup (xfree, frame->extra_info);
2099 }
2100 return frame;
2101}
c8b8a898 2102
ae1e7417
AC
2103/* Memory access methods. */
2104
2105void
2106get_frame_memory (struct frame_info *this_frame, CORE_ADDR addr, void *buf,
2107 int len)
2108{
2109 read_memory (addr, buf, len);
2110}
2111
2112LONGEST
2113get_frame_memory_signed (struct frame_info *this_frame, CORE_ADDR addr,
2114 int len)
2115{
2116 return read_memory_integer (addr, len);
2117}
2118
2119ULONGEST
2120get_frame_memory_unsigned (struct frame_info *this_frame, CORE_ADDR addr,
2121 int len)
2122{
2123 return read_memory_unsigned_integer (addr, len);
2124}
2125
304396fb
AC
2126int
2127safe_frame_unwind_memory (struct frame_info *this_frame,
2128 CORE_ADDR addr, void *buf, int len)
2129{
2130 /* NOTE: read_memory_nobpt returns zero on success! */
2131 return !read_memory_nobpt (addr, buf, len);
2132}
2133
ae1e7417
AC
2134/* Architecture method. */
2135
2136struct gdbarch *
2137get_frame_arch (struct frame_info *this_frame)
2138{
2139 return current_gdbarch;
2140}
2141
a9e5fdc2
AC
2142/* Stack pointer methods. */
2143
2144CORE_ADDR
2145get_frame_sp (struct frame_info *this_frame)
2146{
2147 return frame_sp_unwind (this_frame->next);
2148}
2149
2150CORE_ADDR
2151frame_sp_unwind (struct frame_info *next_frame)
2152{
bbde78fa 2153 /* Normality - an architecture that provides a way of obtaining any
a9e5fdc2
AC
2154 frame inner-most address. */
2155 if (gdbarch_unwind_sp_p (current_gdbarch))
2156 return gdbarch_unwind_sp (current_gdbarch, next_frame);
2157 /* Things are looking grim. If it's the inner-most frame and there
bbde78fa 2158 is a TARGET_READ_SP, then that can be used. */
a9e5fdc2
AC
2159 if (next_frame->level < 0 && TARGET_READ_SP_P ())
2160 return TARGET_READ_SP ();
2161 /* Now things are really are grim. Hope that the value returned by
2162 the SP_REGNUM register is meaningful. */
2163 if (SP_REGNUM >= 0)
2164 {
2165 ULONGEST sp;
2166 frame_unwind_unsigned_register (next_frame, SP_REGNUM, &sp);
2167 return sp;
2168 }
2169 internal_error (__FILE__, __LINE__, "Missing unwind SP method");
2170}
2171
2172
1594fa56
AC
2173int
2174legacy_frame_p (struct gdbarch *current_gdbarch)
2175{
31b75dbf 2176 if (DEPRECATED_INIT_FRAME_PC_P ()
31b75dbf
AC
2177 || DEPRECATED_INIT_EXTRA_FRAME_INFO_P ()
2178 || DEPRECATED_FRAME_CHAIN_P ())
2179 /* No question, it's a legacy frame. */
2180 return 1;
2181 if (gdbarch_unwind_dummy_id_p (current_gdbarch))
2182 /* No question, it's not a legacy frame (provided none of the
2183 deprecated methods checked above are present that is). */
2184 return 0;
2185 if (DEPRECATED_TARGET_READ_FP_P ()
2186 || DEPRECATED_FP_REGNUM >= 0)
2187 /* Assume it's legacy. If you're trying to convert a legacy frame
2188 target to the new mechanism, get rid of these. legacy
bbde78fa 2189 get_prev_frame() requires these when unwind_frame_id() isn't
31b75dbf
AC
2190 available. */
2191 return 1;
2192 /* Default to assuming that it's brand new code, and hence not
2193 legacy. Force it down the non-legacy path so that the new code
bbde78fa 2194 uses the new frame mechanism from day one. Dummy frames won't
31b75dbf
AC
2195 work very well but we can live with that. */
2196 return 0;
1594fa56
AC
2197}
2198
b9362cc7
AC
2199extern initialize_file_ftype _initialize_frame; /* -Wmissing-prototypes */
2200
25d29d70
AC
2201static struct cmd_list_element *set_backtrace_cmdlist;
2202static struct cmd_list_element *show_backtrace_cmdlist;
2203
2204static void
2205set_backtrace_cmd (char *args, int from_tty)
2206{
2207 help_list (set_backtrace_cmdlist, "set backtrace ", -1, gdb_stdout);
2208}
2209
2210static void
2211show_backtrace_cmd (char *args, int from_tty)
2212{
2213 cmd_show_list (show_backtrace_cmdlist, from_tty, "");
2214}
2215
4c1e7e9d
AC
2216void
2217_initialize_frame (void)
2218{
2219 obstack_init (&frame_cache_obstack);
eb4f72c5 2220
f4c5303c
OF
2221 observer_attach_target_changed (frame_observer_target_changed);
2222
25d29d70
AC
2223 add_prefix_cmd ("backtrace", class_maintenance, set_backtrace_cmd, "\
2224Set backtrace specific variables.\n\
2225Configure backtrace variables such as the backtrace limit",
2226 &set_backtrace_cmdlist, "set backtrace ",
2227 0/*allow-unknown*/, &setlist);
2228 add_prefix_cmd ("backtrace", class_maintenance, show_backtrace_cmd, "\
2229Show backtrace specific variables\n\
2230Show backtrace variables such as the backtrace limit",
2231 &show_backtrace_cmdlist, "show backtrace ",
2232 0/*allow-unknown*/, &showlist);
2233
2234 add_setshow_boolean_cmd ("past-main", class_obscure,
2235 &backtrace_past_main, "\
eb4f72c5
AC
2236Set whether backtraces should continue past \"main\".\n\
2237Normally the caller of \"main\" is not of interest, so GDB will terminate\n\
2238the backtrace at \"main\". Set this variable if you need to see the rest\n\
2239of the stack trace.", "\
2240Show whether backtraces should continue past \"main\".\n\
2241Normally the caller of \"main\" is not of interest, so GDB will terminate\n\
2242the backtrace at \"main\". Set this variable if you need to see the rest\n\
2243of the stack trace.",
25d29d70
AC
2244 NULL, NULL, &set_backtrace_cmdlist,
2245 &show_backtrace_cmdlist);
2246
2247 add_setshow_uinteger_cmd ("limit", class_obscure,
2248 &backtrace_limit, "\
2249Set an upper bound on the number of backtrace levels.\n\
fec74868 2250No more than the specified number of frames can be displayed or examined.\n\
25d29d70
AC
2251Zero is unlimited.", "\
2252Show the upper bound on the number of backtrace levels.",
2253 NULL, NULL, &set_backtrace_cmdlist,
2254 &show_backtrace_cmdlist);
ac2bd0a9
AC
2255
2256 /* Debug this files internals. */
2257 add_show_from_set (add_set_cmd ("frame", class_maintenance, var_zinteger,
2258 &frame_debug, "Set frame debugging.\n\
2259When non-zero, frame specific internal debugging is enabled.", &setdebuglist),
2260 &showdebuglist);
4c1e7e9d 2261}
This page took 0.405722 seconds and 4 git commands to generate.