gdb: Show type summary for anonymous structures from c_print_typedef
[deliverable/binutils-gdb.git] / gdb / frame.c
CommitLineData
4f460812 1/* Cache and manage frames for GDB, the GNU debugger.
96cb11df 2
42a4f53d 3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
d65fe839
AC
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
d65fe839
AC
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
d65fe839
AC
19
20#include "defs.h"
d55e5aa6 21#include "frame.h"
4de283e4
TT
22#include "target.h"
23#include "value.h"
24#include "inferior.h" /* for inferior_ptid */
25#include "regcache.h"
26#include "user-regs.h"
d55e5aa6 27#include "gdb_obstack.h"
4de283e4
TT
28#include "dummy-frame.h"
29#include "sentinel-frame.h"
d55e5aa6 30#include "gdbcore.h"
4de283e4 31#include "annotate.h"
d55e5aa6 32#include "language.h"
4de283e4
TT
33#include "frame-unwind.h"
34#include "frame-base.h"
35#include "command.h"
36#include "gdbcmd.h"
d55e5aa6 37#include "observable.h"
4de283e4
TT
38#include "objfiles.h"
39#include "gdbthread.h"
40#include "block.h"
41#include "inline-frame.h"
983dc440 42#include "tracepoint.h"
4de283e4 43#include "hashtab.h"
f6c01fc5 44#include "valprint.h"
d4c16835 45#include "cli/cli-option.h"
eb4f72c5 46
df433d31
KB
47/* The sentinel frame terminates the innermost end of the frame chain.
48 If unwound, it returns the information needed to construct an
49 innermost frame.
50
51 The current frame, which is the innermost frame, can be found at
52 sentinel_frame->prev. */
53
54static struct frame_info *sentinel_frame;
55
d4c16835
PA
56/* The values behind the global "set backtrace ..." settings. */
57set_backtrace_options user_set_backtrace_options;
58
edb3359d 59static struct frame_info *get_prev_frame_raw (struct frame_info *this_frame);
a7300869 60static const char *frame_stop_reason_symbol_string (enum unwind_stop_reason reason);
5613d8d3 61
782d47df
PA
62/* Status of some values cached in the frame_info object. */
63
64enum cached_copy_status
65{
66 /* Value is unknown. */
67 CC_UNKNOWN,
68
69 /* We have a value. */
70 CC_VALUE,
71
72 /* Value was not saved. */
73 CC_NOT_SAVED,
74
75 /* Value is unavailable. */
76 CC_UNAVAILABLE
77};
78
bd013d54
AC
79/* We keep a cache of stack frames, each of which is a "struct
80 frame_info". The innermost one gets allocated (in
df433d31 81 wait_for_inferior) each time the inferior stops; sentinel_frame
bd013d54
AC
82 points to it. Additional frames get allocated (in get_prev_frame)
83 as needed, and are chained through the next and prev fields. Any
84 time that the frame cache becomes invalid (most notably when we
85 execute something, but also if we change how we interpret the
86 frames (e.g. "set heuristic-fence-post" in mips-tdep.c, or anything
87 which reads new symbols)), we should call reinit_frame_cache. */
88
89struct frame_info
90{
91 /* Level of this frame. The inner-most (youngest) frame is at level
92 0. As you move towards the outer-most (oldest) frame, the level
93 increases. This is a cached value. It could just as easily be
94 computed by counting back from the selected frame to the inner
95 most frame. */
bbde78fa 96 /* NOTE: cagney/2002-04-05: Perhaps a level of ``-1'' should be
bd013d54
AC
97 reserved to indicate a bogus frame - one that has been created
98 just to keep GDB happy (GDB always needs a frame). For the
99 moment leave this as speculation. */
100 int level;
101
6c95b8df
PA
102 /* The frame's program space. */
103 struct program_space *pspace;
104
105 /* The frame's address space. */
8b86c959 106 const address_space *aspace;
6c95b8df 107
bd013d54
AC
108 /* The frame's low-level unwinder and corresponding cache. The
109 low-level unwinder is responsible for unwinding register values
110 for the previous frame. The low-level unwind methods are
bbde78fa 111 selected based on the presence, or otherwise, of register unwind
bd013d54
AC
112 information such as CFI. */
113 void *prologue_cache;
114 const struct frame_unwind *unwind;
115
36f15f55
UW
116 /* Cached copy of the previous frame's architecture. */
117 struct
118 {
119 int p;
120 struct gdbarch *arch;
121 } prev_arch;
122
bd013d54
AC
123 /* Cached copy of the previous frame's resume address. */
124 struct {
782d47df 125 enum cached_copy_status status;
bd013d54
AC
126 CORE_ADDR value;
127 } prev_pc;
128
129 /* Cached copy of the previous frame's function address. */
130 struct
131 {
132 CORE_ADDR addr;
133 int p;
134 } prev_func;
135
136 /* This frame's ID. */
137 struct
138 {
139 int p;
140 struct frame_id value;
141 } this_id;
142
143 /* The frame's high-level base methods, and corresponding cache.
144 The high level base methods are selected based on the frame's
145 debug info. */
146 const struct frame_base *base;
147 void *base_cache;
148
149 /* Pointers to the next (down, inner, younger) and previous (up,
150 outer, older) frame_info's in the frame cache. */
151 struct frame_info *next; /* down, inner, younger */
152 int prev_p;
153 struct frame_info *prev; /* up, outer, older */
55feb689
DJ
154
155 /* The reason why we could not set PREV, or UNWIND_NO_REASON if we
156 could. Only valid when PREV_P is set. */
157 enum unwind_stop_reason stop_reason;
53e8a631
AB
158
159 /* A frame specific string describing the STOP_REASON in more detail.
160 Only valid when PREV_P is set, but even then may still be NULL. */
161 const char *stop_string;
bd013d54
AC
162};
163
3de661e6
PM
164/* A frame stash used to speed up frame lookups. Create a hash table
165 to stash frames previously accessed from the frame cache for
166 quicker subsequent retrieval. The hash table is emptied whenever
167 the frame cache is invalidated. */
b83e9eb7 168
3de661e6 169static htab_t frame_stash;
b83e9eb7 170
3de661e6
PM
171/* Internal function to calculate a hash from the frame_id addresses,
172 using as many valid addresses as possible. Frames below level 0
173 are not stored in the hash table. */
174
175static hashval_t
176frame_addr_hash (const void *ap)
177{
9a3c8263 178 const struct frame_info *frame = (const struct frame_info *) ap;
3de661e6
PM
179 const struct frame_id f_id = frame->this_id.value;
180 hashval_t hash = 0;
181
5ce0145d
PA
182 gdb_assert (f_id.stack_status != FID_STACK_INVALID
183 || f_id.code_addr_p
3de661e6
PM
184 || f_id.special_addr_p);
185
5ce0145d 186 if (f_id.stack_status == FID_STACK_VALID)
3de661e6
PM
187 hash = iterative_hash (&f_id.stack_addr,
188 sizeof (f_id.stack_addr), hash);
189 if (f_id.code_addr_p)
190 hash = iterative_hash (&f_id.code_addr,
191 sizeof (f_id.code_addr), hash);
192 if (f_id.special_addr_p)
193 hash = iterative_hash (&f_id.special_addr,
194 sizeof (f_id.special_addr), hash);
195
196 return hash;
197}
198
199/* Internal equality function for the hash table. This function
200 defers equality operations to frame_id_eq. */
201
202static int
203frame_addr_hash_eq (const void *a, const void *b)
204{
9a3c8263
SM
205 const struct frame_info *f_entry = (const struct frame_info *) a;
206 const struct frame_info *f_element = (const struct frame_info *) b;
3de661e6
PM
207
208 return frame_id_eq (f_entry->this_id.value,
209 f_element->this_id.value);
210}
211
212/* Internal function to create the frame_stash hash table. 100 seems
213 to be a good compromise to start the hash table at. */
214
215static void
216frame_stash_create (void)
217{
218 frame_stash = htab_create (100,
219 frame_addr_hash,
220 frame_addr_hash_eq,
221 NULL);
222}
223
194cca41
PA
224/* Internal function to add a frame to the frame_stash hash table.
225 Returns false if a frame with the same ID was already stashed, true
226 otherwise. */
b83e9eb7 227
194cca41 228static int
b83e9eb7
JB
229frame_stash_add (struct frame_info *frame)
230{
194cca41 231 struct frame_info **slot;
f5b0ed3c 232
194cca41
PA
233 /* Do not try to stash the sentinel frame. */
234 gdb_assert (frame->level >= 0);
235
236 slot = (struct frame_info **) htab_find_slot (frame_stash,
237 frame,
238 INSERT);
239
240 /* If we already have a frame in the stack with the same id, we
241 either have a stack cycle (corrupted stack?), or some bug
242 elsewhere in GDB. In any case, ignore the duplicate and return
243 an indication to the caller. */
244 if (*slot != NULL)
245 return 0;
246
247 *slot = frame;
248 return 1;
b83e9eb7
JB
249}
250
3de661e6
PM
251/* Internal function to search the frame stash for an entry with the
252 given frame ID. If found, return that frame. Otherwise return
253 NULL. */
b83e9eb7
JB
254
255static struct frame_info *
256frame_stash_find (struct frame_id id)
257{
3de661e6
PM
258 struct frame_info dummy;
259 struct frame_info *frame;
b83e9eb7 260
3de661e6 261 dummy.this_id.value = id;
9a3c8263 262 frame = (struct frame_info *) htab_find (frame_stash, &dummy);
3de661e6 263 return frame;
b83e9eb7
JB
264}
265
3de661e6
PM
266/* Internal function to invalidate the frame stash by removing all
267 entries in it. This only occurs when the frame cache is
268 invalidated. */
b83e9eb7
JB
269
270static void
271frame_stash_invalidate (void)
272{
3de661e6 273 htab_empty (frame_stash);
b83e9eb7
JB
274}
275
45f25d6c
AB
276/* See frame.h */
277scoped_restore_selected_frame::scoped_restore_selected_frame ()
278{
279 m_fid = get_frame_id (get_selected_frame (NULL));
280}
281
282/* See frame.h */
283scoped_restore_selected_frame::~scoped_restore_selected_frame ()
284{
285 frame_info *frame = frame_find_by_id (m_fid);
286 if (frame == NULL)
287 warning (_("Unable to restore previously selected frame."));
288 else
289 select_frame (frame);
290}
291
ac2bd0a9
AC
292/* Flag to control debugging. */
293
ccce17b0 294unsigned int frame_debug;
920d2a44
AC
295static void
296show_frame_debug (struct ui_file *file, int from_tty,
297 struct cmd_list_element *c, const char *value)
298{
299 fprintf_filtered (file, _("Frame debugging is %s.\n"), value);
300}
ac2bd0a9 301
d4c16835 302/* Implementation of "show backtrace past-main". */
25d29d70 303
920d2a44
AC
304static void
305show_backtrace_past_main (struct ui_file *file, int from_tty,
306 struct cmd_list_element *c, const char *value)
307{
3e43a32a
MS
308 fprintf_filtered (file,
309 _("Whether backtraces should "
310 "continue past \"main\" is %s.\n"),
920d2a44
AC
311 value);
312}
313
d4c16835
PA
314/* Implementation of "show backtrace past-entry". */
315
920d2a44
AC
316static void
317show_backtrace_past_entry (struct ui_file *file, int from_tty,
318 struct cmd_list_element *c, const char *value)
319{
3e43a32a
MS
320 fprintf_filtered (file, _("Whether backtraces should continue past the "
321 "entry point of a program is %s.\n"),
920d2a44
AC
322 value);
323}
324
d4c16835
PA
325/* Implementation of "show backtrace limit". */
326
920d2a44
AC
327static void
328show_backtrace_limit (struct ui_file *file, int from_tty,
329 struct cmd_list_element *c, const char *value)
330{
3e43a32a
MS
331 fprintf_filtered (file,
332 _("An upper bound on the number "
333 "of backtrace levels is %s.\n"),
920d2a44
AC
334 value);
335}
336
eb4f72c5 337
ca73dd9d
AC
338static void
339fprint_field (struct ui_file *file, const char *name, int p, CORE_ADDR addr)
340{
341 if (p)
5af949e3 342 fprintf_unfiltered (file, "%s=%s", name, hex_string (addr));
ca73dd9d
AC
343 else
344 fprintf_unfiltered (file, "!%s", name);
345}
d65fe839 346
00905d52 347void
7f78e237
AC
348fprint_frame_id (struct ui_file *file, struct frame_id id)
349{
ca73dd9d 350 fprintf_unfiltered (file, "{");
5ce0145d
PA
351
352 if (id.stack_status == FID_STACK_INVALID)
353 fprintf_unfiltered (file, "!stack");
354 else if (id.stack_status == FID_STACK_UNAVAILABLE)
355 fprintf_unfiltered (file, "stack=<unavailable>");
df433d31
KB
356 else if (id.stack_status == FID_STACK_SENTINEL)
357 fprintf_unfiltered (file, "stack=<sentinel>");
5ce0145d
PA
358 else
359 fprintf_unfiltered (file, "stack=%s", hex_string (id.stack_addr));
ca73dd9d 360 fprintf_unfiltered (file, ",");
5ce0145d 361
ca73dd9d
AC
362 fprint_field (file, "code", id.code_addr_p, id.code_addr);
363 fprintf_unfiltered (file, ",");
5ce0145d 364
ca73dd9d 365 fprint_field (file, "special", id.special_addr_p, id.special_addr);
5ce0145d 366
193facb3
JK
367 if (id.artificial_depth)
368 fprintf_unfiltered (file, ",artificial=%d", id.artificial_depth);
5ce0145d 369
ca73dd9d 370 fprintf_unfiltered (file, "}");
7f78e237
AC
371}
372
373static void
374fprint_frame_type (struct ui_file *file, enum frame_type type)
375{
376 switch (type)
377 {
7f78e237
AC
378 case NORMAL_FRAME:
379 fprintf_unfiltered (file, "NORMAL_FRAME");
380 return;
381 case DUMMY_FRAME:
382 fprintf_unfiltered (file, "DUMMY_FRAME");
383 return;
edb3359d
DJ
384 case INLINE_FRAME:
385 fprintf_unfiltered (file, "INLINE_FRAME");
386 return;
b5eef7aa
JK
387 case TAILCALL_FRAME:
388 fprintf_unfiltered (file, "TAILCALL_FRAME");
edb3359d 389 return;
7f78e237
AC
390 case SIGTRAMP_FRAME:
391 fprintf_unfiltered (file, "SIGTRAMP_FRAME");
392 return;
36f15f55
UW
393 case ARCH_FRAME:
394 fprintf_unfiltered (file, "ARCH_FRAME");
395 return;
b5eef7aa
JK
396 case SENTINEL_FRAME:
397 fprintf_unfiltered (file, "SENTINEL_FRAME");
398 return;
7f78e237
AC
399 default:
400 fprintf_unfiltered (file, "<unknown type>");
401 return;
402 };
403}
404
405static void
406fprint_frame (struct ui_file *file, struct frame_info *fi)
407{
408 if (fi == NULL)
409 {
410 fprintf_unfiltered (file, "<NULL frame>");
411 return;
412 }
413 fprintf_unfiltered (file, "{");
414 fprintf_unfiltered (file, "level=%d", fi->level);
415 fprintf_unfiltered (file, ",");
416 fprintf_unfiltered (file, "type=");
c1bf6f65
AC
417 if (fi->unwind != NULL)
418 fprint_frame_type (file, fi->unwind->type);
419 else
420 fprintf_unfiltered (file, "<unknown>");
7f78e237
AC
421 fprintf_unfiltered (file, ",");
422 fprintf_unfiltered (file, "unwind=");
423 if (fi->unwind != NULL)
424 gdb_print_host_address (fi->unwind, file);
425 else
426 fprintf_unfiltered (file, "<unknown>");
427 fprintf_unfiltered (file, ",");
428 fprintf_unfiltered (file, "pc=");
782d47df 429 if (fi->next == NULL || fi->next->prev_pc.status == CC_UNKNOWN)
7f78e237 430 fprintf_unfiltered (file, "<unknown>");
782d47df
PA
431 else if (fi->next->prev_pc.status == CC_VALUE)
432 fprintf_unfiltered (file, "%s",
433 hex_string (fi->next->prev_pc.value));
434 else if (fi->next->prev_pc.status == CC_NOT_SAVED)
435 val_print_not_saved (file);
436 else if (fi->next->prev_pc.status == CC_UNAVAILABLE)
437 val_print_unavailable (file);
7f78e237
AC
438 fprintf_unfiltered (file, ",");
439 fprintf_unfiltered (file, "id=");
440 if (fi->this_id.p)
441 fprint_frame_id (file, fi->this_id.value);
442 else
443 fprintf_unfiltered (file, "<unknown>");
444 fprintf_unfiltered (file, ",");
445 fprintf_unfiltered (file, "func=");
446 if (fi->next != NULL && fi->next->prev_func.p)
5af949e3 447 fprintf_unfiltered (file, "%s", hex_string (fi->next->prev_func.addr));
7f78e237
AC
448 else
449 fprintf_unfiltered (file, "<unknown>");
450 fprintf_unfiltered (file, "}");
451}
452
193facb3
JK
453/* Given FRAME, return the enclosing frame as found in real frames read-in from
454 inferior memory. Skip any previous frames which were made up by GDB.
33b4777c
MM
455 Return FRAME if FRAME is a non-artificial frame.
456 Return NULL if FRAME is the start of an artificial-only chain. */
edb3359d
DJ
457
458static struct frame_info *
193facb3 459skip_artificial_frames (struct frame_info *frame)
edb3359d 460{
51d48146
PA
461 /* Note we use get_prev_frame_always, and not get_prev_frame. The
462 latter will truncate the frame chain, leading to this function
463 unintentionally returning a null_frame_id (e.g., when the user
33b4777c
MM
464 sets a backtrace limit).
465
466 Note that for record targets we may get a frame chain that consists
467 of artificial frames only. */
1ab3b62c
JK
468 while (get_frame_type (frame) == INLINE_FRAME
469 || get_frame_type (frame) == TAILCALL_FRAME)
33b4777c
MM
470 {
471 frame = get_prev_frame_always (frame);
472 if (frame == NULL)
473 break;
474 }
edb3359d
DJ
475
476 return frame;
477}
478
7eb89530
YQ
479struct frame_info *
480skip_unwritable_frames (struct frame_info *frame)
481{
482 while (gdbarch_code_of_frame_writable (get_frame_arch (frame), frame) == 0)
483 {
484 frame = get_prev_frame (frame);
485 if (frame == NULL)
486 break;
487 }
488
489 return frame;
490}
491
2f3ef606
MM
492/* See frame.h. */
493
494struct frame_info *
495skip_tailcall_frames (struct frame_info *frame)
496{
497 while (get_frame_type (frame) == TAILCALL_FRAME)
33b4777c
MM
498 {
499 /* Note that for record targets we may get a frame chain that consists of
500 tailcall frames only. */
501 frame = get_prev_frame (frame);
502 if (frame == NULL)
503 break;
504 }
2f3ef606
MM
505
506 return frame;
507}
508
194cca41
PA
509/* Compute the frame's uniq ID that can be used to, later, re-find the
510 frame. */
511
512static void
513compute_frame_id (struct frame_info *fi)
514{
515 gdb_assert (!fi->this_id.p);
516
517 if (frame_debug)
518 fprintf_unfiltered (gdb_stdlog, "{ compute_frame_id (fi=%d) ",
519 fi->level);
520 /* Find the unwinder. */
521 if (fi->unwind == NULL)
522 frame_unwind_find_by_frame (fi, &fi->prologue_cache);
523 /* Find THIS frame's ID. */
524 /* Default to outermost if no ID is found. */
525 fi->this_id.value = outer_frame_id;
526 fi->unwind->this_id (fi, &fi->prologue_cache, &fi->this_id.value);
527 gdb_assert (frame_id_p (fi->this_id.value));
528 fi->this_id.p = 1;
529 if (frame_debug)
530 {
531 fprintf_unfiltered (gdb_stdlog, "-> ");
532 fprint_frame_id (gdb_stdlog, fi->this_id.value);
533 fprintf_unfiltered (gdb_stdlog, " }\n");
534 }
535}
536
7a424e99 537/* Return a frame uniq ID that can be used to, later, re-find the
101dcfbe
AC
538 frame. */
539
7a424e99
AC
540struct frame_id
541get_frame_id (struct frame_info *fi)
101dcfbe
AC
542{
543 if (fi == NULL)
b83e9eb7
JB
544 return null_frame_id;
545
f245535c
PA
546 if (!fi->this_id.p)
547 {
548 int stashed;
549
550 /* If we haven't computed the frame id yet, then it must be that
551 this is the current frame. Compute it now, and stash the
552 result. The IDs of other frames are computed as soon as
553 they're created, in order to detect cycles. See
554 get_prev_frame_if_no_cycle. */
555 gdb_assert (fi->level == 0);
556
557 /* Compute. */
558 compute_frame_id (fi);
559
560 /* Since this is the first frame in the chain, this should
561 always succeed. */
562 stashed = frame_stash_add (fi);
563 gdb_assert (stashed);
564 }
565
18adea3f 566 return fi->this_id.value;
101dcfbe
AC
567}
568
edb3359d
DJ
569struct frame_id
570get_stack_frame_id (struct frame_info *next_frame)
571{
193facb3 572 return get_frame_id (skip_artificial_frames (next_frame));
edb3359d
DJ
573}
574
5613d8d3 575struct frame_id
c7ce8faa 576frame_unwind_caller_id (struct frame_info *next_frame)
5613d8d3 577{
edb3359d
DJ
578 struct frame_info *this_frame;
579
51d48146
PA
580 /* Use get_prev_frame_always, and not get_prev_frame. The latter
581 will truncate the frame chain, leading to this function
582 unintentionally returning a null_frame_id (e.g., when a caller
583 requests the frame ID of "main()"s caller. */
edb3359d 584
193facb3 585 next_frame = skip_artificial_frames (next_frame);
33b4777c
MM
586 if (next_frame == NULL)
587 return null_frame_id;
588
51d48146 589 this_frame = get_prev_frame_always (next_frame);
edb3359d 590 if (this_frame)
193facb3 591 return get_frame_id (skip_artificial_frames (this_frame));
edb3359d
DJ
592 else
593 return null_frame_id;
5613d8d3
AC
594}
595
f8904751 596const struct frame_id null_frame_id = { 0 }; /* All zeros. */
df433d31 597const struct frame_id sentinel_frame_id = { 0, 0, 0, FID_STACK_SENTINEL, 0, 1, 0 };
5ce0145d 598const struct frame_id outer_frame_id = { 0, 0, 0, FID_STACK_INVALID, 0, 1, 0 };
7a424e99
AC
599
600struct frame_id
48c66725
JJ
601frame_id_build_special (CORE_ADDR stack_addr, CORE_ADDR code_addr,
602 CORE_ADDR special_addr)
7a424e99 603{
12b0b6de 604 struct frame_id id = null_frame_id;
1c4d3f96 605
d0a55772 606 id.stack_addr = stack_addr;
5ce0145d 607 id.stack_status = FID_STACK_VALID;
d0a55772 608 id.code_addr = code_addr;
12b0b6de 609 id.code_addr_p = 1;
48c66725 610 id.special_addr = special_addr;
12b0b6de 611 id.special_addr_p = 1;
7a424e99
AC
612 return id;
613}
614
5ce0145d
PA
615/* See frame.h. */
616
617struct frame_id
618frame_id_build_unavailable_stack (CORE_ADDR code_addr)
619{
620 struct frame_id id = null_frame_id;
621
622 id.stack_status = FID_STACK_UNAVAILABLE;
623 id.code_addr = code_addr;
624 id.code_addr_p = 1;
625 return id;
626}
627
8372a7cb
MM
628/* See frame.h. */
629
630struct frame_id
631frame_id_build_unavailable_stack_special (CORE_ADDR code_addr,
632 CORE_ADDR special_addr)
633{
634 struct frame_id id = null_frame_id;
635
636 id.stack_status = FID_STACK_UNAVAILABLE;
637 id.code_addr = code_addr;
638 id.code_addr_p = 1;
639 id.special_addr = special_addr;
640 id.special_addr_p = 1;
641 return id;
642}
643
48c66725
JJ
644struct frame_id
645frame_id_build (CORE_ADDR stack_addr, CORE_ADDR code_addr)
646{
12b0b6de 647 struct frame_id id = null_frame_id;
1c4d3f96 648
12b0b6de 649 id.stack_addr = stack_addr;
5ce0145d 650 id.stack_status = FID_STACK_VALID;
12b0b6de
UW
651 id.code_addr = code_addr;
652 id.code_addr_p = 1;
653 return id;
654}
655
656struct frame_id
657frame_id_build_wild (CORE_ADDR stack_addr)
658{
659 struct frame_id id = null_frame_id;
1c4d3f96 660
12b0b6de 661 id.stack_addr = stack_addr;
5ce0145d 662 id.stack_status = FID_STACK_VALID;
12b0b6de 663 return id;
48c66725
JJ
664}
665
7a424e99
AC
666int
667frame_id_p (struct frame_id l)
668{
d0a55772 669 int p;
1c4d3f96 670
12b0b6de 671 /* The frame is valid iff it has a valid stack address. */
5ce0145d 672 p = l.stack_status != FID_STACK_INVALID;
005ca36a
JB
673 /* outer_frame_id is also valid. */
674 if (!p && memcmp (&l, &outer_frame_id, sizeof (l)) == 0)
675 p = 1;
7f78e237
AC
676 if (frame_debug)
677 {
678 fprintf_unfiltered (gdb_stdlog, "{ frame_id_p (l=");
679 fprint_frame_id (gdb_stdlog, l);
680 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", p);
681 }
d0a55772 682 return p;
7a424e99
AC
683}
684
edb3359d 685int
193facb3 686frame_id_artificial_p (struct frame_id l)
edb3359d
DJ
687{
688 if (!frame_id_p (l))
689 return 0;
690
193facb3 691 return (l.artificial_depth != 0);
edb3359d
DJ
692}
693
7a424e99
AC
694int
695frame_id_eq (struct frame_id l, struct frame_id r)
696{
d0a55772 697 int eq;
1c4d3f96 698
5ce0145d
PA
699 if (l.stack_status == FID_STACK_INVALID && l.special_addr_p
700 && r.stack_status == FID_STACK_INVALID && r.special_addr_p)
005ca36a
JB
701 /* The outermost frame marker is equal to itself. This is the
702 dodgy thing about outer_frame_id, since between execution steps
703 we might step into another function - from which we can't
704 unwind either. More thought required to get rid of
705 outer_frame_id. */
706 eq = 1;
5ce0145d 707 else if (l.stack_status == FID_STACK_INVALID
f0d4ba1f 708 || r.stack_status == FID_STACK_INVALID)
12b0b6de
UW
709 /* Like a NaN, if either ID is invalid, the result is false.
710 Note that a frame ID is invalid iff it is the null frame ID. */
d0a55772 711 eq = 0;
5ce0145d 712 else if (l.stack_status != r.stack_status || l.stack_addr != r.stack_addr)
d0a55772
AC
713 /* If .stack addresses are different, the frames are different. */
714 eq = 0;
edb3359d
DJ
715 else if (l.code_addr_p && r.code_addr_p && l.code_addr != r.code_addr)
716 /* An invalid code addr is a wild card. If .code addresses are
717 different, the frames are different. */
48c66725 718 eq = 0;
edb3359d
DJ
719 else if (l.special_addr_p && r.special_addr_p
720 && l.special_addr != r.special_addr)
721 /* An invalid special addr is a wild card (or unused). Otherwise
722 if special addresses are different, the frames are different. */
723 eq = 0;
193facb3
JK
724 else if (l.artificial_depth != r.artificial_depth)
725 /* If artifical depths are different, the frames must be different. */
edb3359d
DJ
726 eq = 0;
727 else
48c66725 728 /* Frames are equal. */
d0a55772 729 eq = 1;
edb3359d 730
7f78e237
AC
731 if (frame_debug)
732 {
733 fprintf_unfiltered (gdb_stdlog, "{ frame_id_eq (l=");
734 fprint_frame_id (gdb_stdlog, l);
735 fprintf_unfiltered (gdb_stdlog, ",r=");
736 fprint_frame_id (gdb_stdlog, r);
737 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", eq);
738 }
d0a55772 739 return eq;
7a424e99
AC
740}
741
a45ae3ed
UW
742/* Safety net to check whether frame ID L should be inner to
743 frame ID R, according to their stack addresses.
744
745 This method cannot be used to compare arbitrary frames, as the
746 ranges of valid stack addresses may be discontiguous (e.g. due
747 to sigaltstack).
748
749 However, it can be used as safety net to discover invalid frame
0963b4bd 750 IDs in certain circumstances. Assuming that NEXT is the immediate
f06eadd9 751 inner frame to THIS and that NEXT and THIS are both NORMAL frames:
a45ae3ed 752
f06eadd9
JB
753 * The stack address of NEXT must be inner-than-or-equal to the stack
754 address of THIS.
a45ae3ed
UW
755
756 Therefore, if frame_id_inner (THIS, NEXT) holds, some unwind
757 error has occurred.
758
f06eadd9
JB
759 * If NEXT and THIS have different stack addresses, no other frame
760 in the frame chain may have a stack address in between.
a45ae3ed
UW
761
762 Therefore, if frame_id_inner (TEST, THIS) holds, but
763 frame_id_inner (TEST, NEXT) does not hold, TEST cannot refer
f06eadd9
JB
764 to a valid frame in the frame chain.
765
766 The sanity checks above cannot be performed when a SIGTRAMP frame
767 is involved, because signal handlers might be executed on a different
768 stack than the stack used by the routine that caused the signal
769 to be raised. This can happen for instance when a thread exceeds
0963b4bd 770 its maximum stack size. In this case, certain compilers implement
f06eadd9
JB
771 a stack overflow strategy that cause the handler to be run on a
772 different stack. */
a45ae3ed
UW
773
774static int
09a7aba8 775frame_id_inner (struct gdbarch *gdbarch, struct frame_id l, struct frame_id r)
7a424e99 776{
d0a55772 777 int inner;
1c4d3f96 778
5ce0145d
PA
779 if (l.stack_status != FID_STACK_VALID || r.stack_status != FID_STACK_VALID)
780 /* Like NaN, any operation involving an invalid ID always fails.
781 Likewise if either ID has an unavailable stack address. */
d0a55772 782 inner = 0;
193facb3 783 else if (l.artificial_depth > r.artificial_depth
edb3359d
DJ
784 && l.stack_addr == r.stack_addr
785 && l.code_addr_p == r.code_addr_p
786 && l.special_addr_p == r.special_addr_p
787 && l.special_addr == r.special_addr)
788 {
789 /* Same function, different inlined functions. */
3977b71f 790 const struct block *lb, *rb;
edb3359d
DJ
791
792 gdb_assert (l.code_addr_p && r.code_addr_p);
793
794 lb = block_for_pc (l.code_addr);
795 rb = block_for_pc (r.code_addr);
796
797 if (lb == NULL || rb == NULL)
798 /* Something's gone wrong. */
799 inner = 0;
800 else
801 /* This will return true if LB and RB are the same block, or
802 if the block with the smaller depth lexically encloses the
803 block with the greater depth. */
804 inner = contained_in (lb, rb);
805 }
d0a55772
AC
806 else
807 /* Only return non-zero when strictly inner than. Note that, per
808 comment in "frame.h", there is some fuzz here. Frameless
809 functions are not strictly inner than (same .stack but
48c66725 810 different .code and/or .special address). */
09a7aba8 811 inner = gdbarch_inner_than (gdbarch, l.stack_addr, r.stack_addr);
7f78e237
AC
812 if (frame_debug)
813 {
814 fprintf_unfiltered (gdb_stdlog, "{ frame_id_inner (l=");
815 fprint_frame_id (gdb_stdlog, l);
816 fprintf_unfiltered (gdb_stdlog, ",r=");
817 fprint_frame_id (gdb_stdlog, r);
818 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", inner);
819 }
d0a55772 820 return inner;
7a424e99
AC
821}
822
101dcfbe
AC
823struct frame_info *
824frame_find_by_id (struct frame_id id)
825{
a45ae3ed 826 struct frame_info *frame, *prev_frame;
101dcfbe
AC
827
828 /* ZERO denotes the null frame, let the caller decide what to do
829 about it. Should it instead return get_current_frame()? */
7a424e99 830 if (!frame_id_p (id))
101dcfbe
AC
831 return NULL;
832
df433d31
KB
833 /* Check for the sentinel frame. */
834 if (frame_id_eq (id, sentinel_frame_id))
835 return sentinel_frame;
836
b83e9eb7
JB
837 /* Try using the frame stash first. Finding it there removes the need
838 to perform the search by looping over all frames, which can be very
839 CPU-intensive if the number of frames is very high (the loop is O(n)
840 and get_prev_frame performs a series of checks that are relatively
841 expensive). This optimization is particularly useful when this function
842 is called from another function (such as value_fetch_lazy, case
843 VALUE_LVAL (val) == lval_register) which already loops over all frames,
844 making the overall behavior O(n^2). */
845 frame = frame_stash_find (id);
846 if (frame)
847 return frame;
848
a45ae3ed 849 for (frame = get_current_frame (); ; frame = prev_frame)
101dcfbe 850 {
fe978cb0 851 struct frame_id self = get_frame_id (frame);
bb9bcb69 852
fe978cb0 853 if (frame_id_eq (id, self))
7a424e99
AC
854 /* An exact match. */
855 return frame;
a45ae3ed
UW
856
857 prev_frame = get_prev_frame (frame);
858 if (!prev_frame)
859 return NULL;
860
861 /* As a safety net to avoid unnecessary backtracing while trying
862 to find an invalid ID, we check for a common situation where
863 we can detect from comparing stack addresses that no other
864 frame in the current frame chain can have this ID. See the
865 comment at frame_id_inner for details. */
866 if (get_frame_type (frame) == NORMAL_FRAME
fe978cb0 867 && !frame_id_inner (get_frame_arch (frame), id, self)
a45ae3ed
UW
868 && frame_id_inner (get_frame_arch (prev_frame), id,
869 get_frame_id (prev_frame)))
101dcfbe 870 return NULL;
101dcfbe
AC
871 }
872 return NULL;
873}
874
782d47df
PA
875static CORE_ADDR
876frame_unwind_pc (struct frame_info *this_frame)
f18c5a73 877{
782d47df 878 if (this_frame->prev_pc.status == CC_UNKNOWN)
f18c5a73 879 {
8bcb5208
AB
880 struct gdbarch *prev_gdbarch;
881 CORE_ADDR pc = 0;
882 int pc_p = 0;
883
884 /* The right way. The `pure' way. The one true way. This
885 method depends solely on the register-unwind code to
886 determine the value of registers in THIS frame, and hence
887 the value of this frame's PC (resume address). A typical
888 implementation is no more than:
889
890 frame_unwind_register (this_frame, ISA_PC_REGNUM, buf);
891 return extract_unsigned_integer (buf, size of ISA_PC_REGNUM);
892
893 Note: this method is very heavily dependent on a correct
894 register-unwind implementation, it pays to fix that
895 method first; this method is frame type agnostic, since
896 it only deals with register values, it works with any
897 frame. This is all in stark contrast to the old
898 FRAME_SAVED_PC which would try to directly handle all the
899 different ways that a PC could be unwound. */
900 prev_gdbarch = frame_unwind_arch (this_frame);
901
a70b8144 902 try
12cc2063 903 {
8bcb5208
AB
904 pc = gdbarch_unwind_pc (prev_gdbarch, this_frame);
905 pc_p = 1;
906 }
230d2906 907 catch (const gdb_exception_error &ex)
8bcb5208
AB
908 {
909 if (ex.error == NOT_AVAILABLE_ERROR)
e3eebbd7 910 {
8bcb5208
AB
911 this_frame->prev_pc.status = CC_UNAVAILABLE;
912
913 if (frame_debug)
914 fprintf_unfiltered (gdb_stdlog,
915 "{ frame_unwind_pc (this_frame=%d)"
916 " -> <unavailable> }\n",
917 this_frame->level);
e3eebbd7 918 }
8bcb5208 919 else if (ex.error == OPTIMIZED_OUT_ERROR)
e3eebbd7 920 {
8bcb5208 921 this_frame->prev_pc.status = CC_NOT_SAVED;
492d29ea 922
e3eebbd7
PA
923 if (frame_debug)
924 fprintf_unfiltered (gdb_stdlog,
8bcb5208
AB
925 "{ frame_unwind_pc (this_frame=%d)"
926 " -> <not saved> }\n",
927 this_frame->level);
e3eebbd7 928 }
8bcb5208 929 else
eedc3f4f 930 throw;
8bcb5208 931 }
8bcb5208
AB
932
933 if (pc_p)
934 {
935 this_frame->prev_pc.value = pc;
936 this_frame->prev_pc.status = CC_VALUE;
937 if (frame_debug)
938 fprintf_unfiltered (gdb_stdlog,
939 "{ frame_unwind_pc (this_frame=%d) "
940 "-> %s }\n",
941 this_frame->level,
942 hex_string (this_frame->prev_pc.value));
12cc2063 943 }
f18c5a73 944 }
e3eebbd7 945
782d47df
PA
946 if (this_frame->prev_pc.status == CC_VALUE)
947 return this_frame->prev_pc.value;
948 else if (this_frame->prev_pc.status == CC_UNAVAILABLE)
e3eebbd7 949 throw_error (NOT_AVAILABLE_ERROR, _("PC not available"));
782d47df
PA
950 else if (this_frame->prev_pc.status == CC_NOT_SAVED)
951 throw_error (OPTIMIZED_OUT_ERROR, _("PC not saved"));
e3eebbd7 952 else
782d47df
PA
953 internal_error (__FILE__, __LINE__,
954 "unexpected prev_pc status: %d",
955 (int) this_frame->prev_pc.status);
f18c5a73
AC
956}
957
edb3359d
DJ
958CORE_ADDR
959frame_unwind_caller_pc (struct frame_info *this_frame)
960{
33b4777c
MM
961 this_frame = skip_artificial_frames (this_frame);
962
963 /* We must have a non-artificial frame. The caller is supposed to check
964 the result of frame_unwind_caller_id (), which returns NULL_FRAME_ID
965 in this case. */
966 gdb_assert (this_frame != NULL);
967
968 return frame_unwind_pc (this_frame);
edb3359d
DJ
969}
970
e3eebbd7
PA
971int
972get_frame_func_if_available (struct frame_info *this_frame, CORE_ADDR *pc)
be41e9f4 973{
ef02daa9
DJ
974 struct frame_info *next_frame = this_frame->next;
975
976 if (!next_frame->prev_func.p)
be41e9f4 977 {
e3eebbd7
PA
978 CORE_ADDR addr_in_block;
979
57bfe177
AC
980 /* Make certain that this, and not the adjacent, function is
981 found. */
e3eebbd7
PA
982 if (!get_frame_address_in_block_if_available (this_frame, &addr_in_block))
983 {
984 next_frame->prev_func.p = -1;
985 if (frame_debug)
986 fprintf_unfiltered (gdb_stdlog,
987 "{ get_frame_func (this_frame=%d)"
988 " -> unavailable }\n",
989 this_frame->level);
990 }
991 else
992 {
993 next_frame->prev_func.p = 1;
994 next_frame->prev_func.addr = get_pc_function_start (addr_in_block);
995 if (frame_debug)
996 fprintf_unfiltered (gdb_stdlog,
997 "{ get_frame_func (this_frame=%d) -> %s }\n",
998 this_frame->level,
999 hex_string (next_frame->prev_func.addr));
1000 }
be41e9f4 1001 }
e3eebbd7
PA
1002
1003 if (next_frame->prev_func.p < 0)
1004 {
1005 *pc = -1;
1006 return 0;
1007 }
1008 else
1009 {
1010 *pc = next_frame->prev_func.addr;
1011 return 1;
1012 }
1013}
1014
1015CORE_ADDR
1016get_frame_func (struct frame_info *this_frame)
1017{
1018 CORE_ADDR pc;
1019
1020 if (!get_frame_func_if_available (this_frame, &pc))
1021 throw_error (NOT_AVAILABLE_ERROR, _("PC not available"));
1022
1023 return pc;
be41e9f4
AC
1024}
1025
daf6667d 1026std::unique_ptr<readonly_detached_regcache>
a81dcb05
AC
1027frame_save_as_regcache (struct frame_info *this_frame)
1028{
302abd6e
SM
1029 auto cooked_read = [this_frame] (int regnum, gdb_byte *buf)
1030 {
1031 if (!deprecated_frame_register_read (this_frame, regnum, buf))
1032 return REG_UNAVAILABLE;
1033 else
1034 return REG_VALID;
1035 };
1036
daf6667d 1037 std::unique_ptr<readonly_detached_regcache> regcache
302abd6e 1038 (new readonly_detached_regcache (get_frame_arch (this_frame), cooked_read));
1c4d3f96 1039
a81dcb05
AC
1040 return regcache;
1041}
1042
dbe9fe58 1043void
7a25a7c1
AC
1044frame_pop (struct frame_info *this_frame)
1045{
348473d5 1046 struct frame_info *prev_frame;
348473d5 1047
b89667eb
DE
1048 if (get_frame_type (this_frame) == DUMMY_FRAME)
1049 {
1050 /* Popping a dummy frame involves restoring more than just registers.
1051 dummy_frame_pop does all the work. */
00431a78 1052 dummy_frame_pop (get_frame_id (this_frame), inferior_thread ());
b89667eb
DE
1053 return;
1054 }
1055
348473d5 1056 /* Ensure that we have a frame to pop to. */
51d48146 1057 prev_frame = get_prev_frame_always (this_frame);
348473d5
NF
1058
1059 if (!prev_frame)
1060 error (_("Cannot pop the initial frame."));
1061
1ab3b62c
JK
1062 /* Ignore TAILCALL_FRAME type frames, they were executed already before
1063 entering THISFRAME. */
2f3ef606 1064 prev_frame = skip_tailcall_frames (prev_frame);
1ab3b62c 1065
33b4777c
MM
1066 if (prev_frame == NULL)
1067 error (_("Cannot find the caller frame."));
1068
c1bf6f65
AC
1069 /* Make a copy of all the register values unwound from this frame.
1070 Save them in a scratch buffer so that there isn't a race between
594f7785 1071 trying to extract the old values from the current regcache while
c1bf6f65 1072 at the same time writing new values into that same cache. */
daf6667d 1073 std::unique_ptr<readonly_detached_regcache> scratch
9ac86b52 1074 = frame_save_as_regcache (prev_frame);
c1bf6f65
AC
1075
1076 /* FIXME: cagney/2003-03-16: It should be possible to tell the
1077 target's register cache that it is about to be hit with a burst
1078 register transfer and that the sequence of register writes should
1079 be batched. The pair target_prepare_to_store() and
1080 target_store_registers() kind of suggest this functionality.
1081 Unfortunately, they don't implement it. Their lack of a formal
1082 definition can lead to targets writing back bogus values
1083 (arguably a bug in the target code mind). */
fc5b8736
YQ
1084 /* Now copy those saved registers into the current regcache. */
1085 get_current_regcache ()->restore (scratch.get ());
7a25a7c1 1086
7a25a7c1
AC
1087 /* We've made right mess of GDB's local state, just discard
1088 everything. */
35f196d9 1089 reinit_frame_cache ();
dbe9fe58 1090}
c689142b 1091
4f460812 1092void
0ee6c332 1093frame_register_unwind (frame_info *next_frame, int regnum,
0fdb4f18
PA
1094 int *optimizedp, int *unavailablep,
1095 enum lval_type *lvalp, CORE_ADDR *addrp,
1096 int *realnump, gdb_byte *bufferp)
4f460812 1097{
669fac23 1098 struct value *value;
7f78e237 1099
4f460812
AC
1100 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
1101 that the value proper does not need to be fetched. */
1102 gdb_assert (optimizedp != NULL);
1103 gdb_assert (lvalp != NULL);
1104 gdb_assert (addrp != NULL);
1105 gdb_assert (realnump != NULL);
1106 /* gdb_assert (bufferp != NULL); */
1107
0ee6c332 1108 value = frame_unwind_register_value (next_frame, regnum);
4f460812 1109
669fac23 1110 gdb_assert (value != NULL);
c50901fd 1111
669fac23 1112 *optimizedp = value_optimized_out (value);
0fdb4f18 1113 *unavailablep = !value_entirely_available (value);
669fac23 1114 *lvalp = VALUE_LVAL (value);
42ae5230 1115 *addrp = value_address (value);
7c2ba67e
YQ
1116 if (*lvalp == lval_register)
1117 *realnump = VALUE_REGNUM (value);
1118 else
1119 *realnump = -1;
6dc42492 1120
0fdb4f18
PA
1121 if (bufferp)
1122 {
1123 if (!*optimizedp && !*unavailablep)
1124 memcpy (bufferp, value_contents_all (value),
1125 TYPE_LENGTH (value_type (value)));
1126 else
1127 memset (bufferp, 0, TYPE_LENGTH (value_type (value)));
1128 }
669fac23
DJ
1129
1130 /* Dispose of the new value. This prevents watchpoints from
1131 trying to watch the saved frame pointer. */
1132 release_value (value);
4f460812
AC
1133}
1134
a216a322
AC
1135void
1136frame_register (struct frame_info *frame, int regnum,
0fdb4f18 1137 int *optimizedp, int *unavailablep, enum lval_type *lvalp,
10c42a71 1138 CORE_ADDR *addrp, int *realnump, gdb_byte *bufferp)
a216a322
AC
1139{
1140 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
1141 that the value proper does not need to be fetched. */
1142 gdb_assert (optimizedp != NULL);
1143 gdb_assert (lvalp != NULL);
1144 gdb_assert (addrp != NULL);
1145 gdb_assert (realnump != NULL);
1146 /* gdb_assert (bufferp != NULL); */
1147
a94dd1fd
AC
1148 /* Obtain the register value by unwinding the register from the next
1149 (more inner frame). */
1150 gdb_assert (frame != NULL && frame->next != NULL);
0fdb4f18
PA
1151 frame_register_unwind (frame->next, regnum, optimizedp, unavailablep,
1152 lvalp, addrp, realnump, bufferp);
a216a322
AC
1153}
1154
135c175f 1155void
0ee6c332 1156frame_unwind_register (frame_info *next_frame, int regnum, gdb_byte *buf)
135c175f
AC
1157{
1158 int optimized;
0fdb4f18 1159 int unavailable;
135c175f
AC
1160 CORE_ADDR addr;
1161 int realnum;
1162 enum lval_type lval;
1c4d3f96 1163
0ee6c332 1164 frame_register_unwind (next_frame, regnum, &optimized, &unavailable,
0fdb4f18 1165 &lval, &addr, &realnum, buf);
8fbca658
PA
1166
1167 if (optimized)
710409a2
PA
1168 throw_error (OPTIMIZED_OUT_ERROR,
1169 _("Register %d was not saved"), regnum);
8fbca658
PA
1170 if (unavailable)
1171 throw_error (NOT_AVAILABLE_ERROR,
1172 _("Register %d is not available"), regnum);
5b181d62
AC
1173}
1174
f0e7d0e8
AC
1175void
1176get_frame_register (struct frame_info *frame,
10c42a71 1177 int regnum, gdb_byte *buf)
f0e7d0e8
AC
1178{
1179 frame_unwind_register (frame->next, regnum, buf);
1180}
1181
669fac23 1182struct value *
0ee6c332 1183frame_unwind_register_value (frame_info *next_frame, int regnum)
669fac23 1184{
36f15f55 1185 struct gdbarch *gdbarch;
669fac23
DJ
1186 struct value *value;
1187
0ee6c332
SM
1188 gdb_assert (next_frame != NULL);
1189 gdbarch = frame_unwind_arch (next_frame);
669fac23
DJ
1190
1191 if (frame_debug)
1192 {
3e43a32a
MS
1193 fprintf_unfiltered (gdb_stdlog,
1194 "{ frame_unwind_register_value "
1195 "(frame=%d,regnum=%d(%s),...) ",
0ee6c332 1196 next_frame->level, regnum,
36f15f55 1197 user_reg_map_regnum_to_name (gdbarch, regnum));
669fac23
DJ
1198 }
1199
1200 /* Find the unwinder. */
0ee6c332
SM
1201 if (next_frame->unwind == NULL)
1202 frame_unwind_find_by_frame (next_frame, &next_frame->prologue_cache);
669fac23
DJ
1203
1204 /* Ask this frame to unwind its register. */
0ee6c332
SM
1205 value = next_frame->unwind->prev_register (next_frame,
1206 &next_frame->prologue_cache,
1207 regnum);
669fac23
DJ
1208
1209 if (frame_debug)
1210 {
1211 fprintf_unfiltered (gdb_stdlog, "->");
1212 if (value_optimized_out (value))
f6c01fc5
AB
1213 {
1214 fprintf_unfiltered (gdb_stdlog, " ");
1215 val_print_optimized_out (value, gdb_stdlog);
1216 }
669fac23
DJ
1217 else
1218 {
1219 if (VALUE_LVAL (value) == lval_register)
1220 fprintf_unfiltered (gdb_stdlog, " register=%d",
1221 VALUE_REGNUM (value));
1222 else if (VALUE_LVAL (value) == lval_memory)
5af949e3
UW
1223 fprintf_unfiltered (gdb_stdlog, " address=%s",
1224 paddress (gdbarch,
1225 value_address (value)));
669fac23
DJ
1226 else
1227 fprintf_unfiltered (gdb_stdlog, " computed");
1228
1229 if (value_lazy (value))
1230 fprintf_unfiltered (gdb_stdlog, " lazy");
1231 else
1232 {
1233 int i;
1234 const gdb_byte *buf = value_contents (value);
1235
1236 fprintf_unfiltered (gdb_stdlog, " bytes=");
1237 fprintf_unfiltered (gdb_stdlog, "[");
36f15f55 1238 for (i = 0; i < register_size (gdbarch, regnum); i++)
669fac23
DJ
1239 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1240 fprintf_unfiltered (gdb_stdlog, "]");
1241 }
1242 }
1243
1244 fprintf_unfiltered (gdb_stdlog, " }\n");
1245 }
1246
1247 return value;
1248}
1249
1250struct value *
1251get_frame_register_value (struct frame_info *frame, int regnum)
1252{
1253 return frame_unwind_register_value (frame->next, regnum);
1254}
1255
f0e7d0e8 1256LONGEST
0ee6c332 1257frame_unwind_register_signed (frame_info *next_frame, int regnum)
f0e7d0e8 1258{
0ee6c332 1259 struct gdbarch *gdbarch = frame_unwind_arch (next_frame);
e17a4113
UW
1260 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1261 int size = register_size (gdbarch, regnum);
0ee6c332 1262 struct value *value = frame_unwind_register_value (next_frame, regnum);
1c4d3f96 1263
9f7fb0aa
AH
1264 gdb_assert (value != NULL);
1265
1266 if (value_optimized_out (value))
1267 {
1268 throw_error (OPTIMIZED_OUT_ERROR,
1269 _("Register %d was not saved"), regnum);
1270 }
1271 if (!value_entirely_available (value))
1272 {
1273 throw_error (NOT_AVAILABLE_ERROR,
1274 _("Register %d is not available"), regnum);
1275 }
1276
1277 LONGEST r = extract_signed_integer (value_contents_all (value), size,
1278 byte_order);
1279
1280 release_value (value);
9f7fb0aa 1281 return r;
f0e7d0e8
AC
1282}
1283
1284LONGEST
1285get_frame_register_signed (struct frame_info *frame, int regnum)
1286{
1287 return frame_unwind_register_signed (frame->next, regnum);
1288}
1289
1290ULONGEST
0ee6c332 1291frame_unwind_register_unsigned (frame_info *next_frame, int regnum)
f0e7d0e8 1292{
0ee6c332 1293 struct gdbarch *gdbarch = frame_unwind_arch (next_frame);
e17a4113
UW
1294 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1295 int size = register_size (gdbarch, regnum);
0ee6c332 1296 struct value *value = frame_unwind_register_value (next_frame, regnum);
1c4d3f96 1297
2cad08ea
YQ
1298 gdb_assert (value != NULL);
1299
1300 if (value_optimized_out (value))
1301 {
1302 throw_error (OPTIMIZED_OUT_ERROR,
1303 _("Register %d was not saved"), regnum);
1304 }
1305 if (!value_entirely_available (value))
1306 {
1307 throw_error (NOT_AVAILABLE_ERROR,
1308 _("Register %d is not available"), regnum);
1309 }
1310
1311 ULONGEST r = extract_unsigned_integer (value_contents_all (value), size,
1312 byte_order);
1313
1314 release_value (value);
2cad08ea 1315 return r;
f0e7d0e8
AC
1316}
1317
1318ULONGEST
1319get_frame_register_unsigned (struct frame_info *frame, int regnum)
1320{
1321 return frame_unwind_register_unsigned (frame->next, regnum);
1322}
1323
ad5f7d6e
PA
1324int
1325read_frame_register_unsigned (struct frame_info *frame, int regnum,
1326 ULONGEST *val)
1327{
1328 struct value *regval = get_frame_register_value (frame, regnum);
1329
1330 if (!value_optimized_out (regval)
1331 && value_entirely_available (regval))
1332 {
1333 struct gdbarch *gdbarch = get_frame_arch (frame);
1334 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1335 int size = register_size (gdbarch, VALUE_REGNUM (regval));
1336
1337 *val = extract_unsigned_integer (value_contents (regval), size, byte_order);
1338 return 1;
1339 }
1340
1341 return 0;
1342}
1343
ff2e87ac 1344void
10c42a71
AC
1345put_frame_register (struct frame_info *frame, int regnum,
1346 const gdb_byte *buf)
ff2e87ac
AC
1347{
1348 struct gdbarch *gdbarch = get_frame_arch (frame);
1349 int realnum;
1350 int optim;
0fdb4f18 1351 int unavail;
ff2e87ac
AC
1352 enum lval_type lval;
1353 CORE_ADDR addr;
1c4d3f96 1354
0fdb4f18
PA
1355 frame_register (frame, regnum, &optim, &unavail,
1356 &lval, &addr, &realnum, NULL);
ff2e87ac 1357 if (optim)
901461f8 1358 error (_("Attempt to assign to a register that was not saved."));
ff2e87ac
AC
1359 switch (lval)
1360 {
1361 case lval_memory:
1362 {
954b50b3 1363 write_memory (addr, buf, register_size (gdbarch, regnum));
ff2e87ac
AC
1364 break;
1365 }
1366 case lval_register:
b66f5587 1367 get_current_regcache ()->cooked_write (realnum, buf);
ff2e87ac
AC
1368 break;
1369 default:
8a3fe4f8 1370 error (_("Attempt to assign to an unmodifiable value."));
ff2e87ac
AC
1371 }
1372}
1373
b2c7d45a
JB
1374/* This function is deprecated. Use get_frame_register_value instead,
1375 which provides more accurate information.
d65fe839 1376
cda5a58a 1377 Find and return the value of REGNUM for the specified stack frame.
5bc602c7 1378 The number of bytes copied is REGISTER_SIZE (REGNUM).
d65fe839 1379
cda5a58a 1380 Returns 0 if the register value could not be found. */
d65fe839 1381
cda5a58a 1382int
ca9d61b9 1383deprecated_frame_register_read (struct frame_info *frame, int regnum,
10c42a71 1384 gdb_byte *myaddr)
d65fe839 1385{
a216a322 1386 int optimized;
0fdb4f18 1387 int unavailable;
a216a322
AC
1388 enum lval_type lval;
1389 CORE_ADDR addr;
1390 int realnum;
1c4d3f96 1391
0fdb4f18
PA
1392 frame_register (frame, regnum, &optimized, &unavailable,
1393 &lval, &addr, &realnum, myaddr);
d65fe839 1394
0fdb4f18 1395 return !optimized && !unavailable;
d65fe839 1396}
e36180d7 1397
00fa51f6
UW
1398int
1399get_frame_register_bytes (struct frame_info *frame, int regnum,
8dccd430
PA
1400 CORE_ADDR offset, int len, gdb_byte *myaddr,
1401 int *optimizedp, int *unavailablep)
00fa51f6
UW
1402{
1403 struct gdbarch *gdbarch = get_frame_arch (frame);
3f27f2a4
AS
1404 int i;
1405 int maxsize;
68e007ca 1406 int numregs;
00fa51f6
UW
1407
1408 /* Skip registers wholly inside of OFFSET. */
1409 while (offset >= register_size (gdbarch, regnum))
1410 {
1411 offset -= register_size (gdbarch, regnum);
1412 regnum++;
1413 }
1414
26fae1d6
AS
1415 /* Ensure that we will not read beyond the end of the register file.
1416 This can only ever happen if the debug information is bad. */
3f27f2a4 1417 maxsize = -offset;
f6efe3f8 1418 numregs = gdbarch_num_cooked_regs (gdbarch);
68e007ca 1419 for (i = regnum; i < numregs; i++)
3f27f2a4
AS
1420 {
1421 int thissize = register_size (gdbarch, i);
bb9bcb69 1422
3f27f2a4 1423 if (thissize == 0)
26fae1d6 1424 break; /* This register is not available on this architecture. */
3f27f2a4
AS
1425 maxsize += thissize;
1426 }
1427 if (len > maxsize)
8dccd430
PA
1428 error (_("Bad debug information detected: "
1429 "Attempt to read %d bytes from registers."), len);
3f27f2a4 1430
00fa51f6
UW
1431 /* Copy the data. */
1432 while (len > 0)
1433 {
1434 int curr_len = register_size (gdbarch, regnum) - offset;
bb9bcb69 1435
00fa51f6
UW
1436 if (curr_len > len)
1437 curr_len = len;
1438
1439 if (curr_len == register_size (gdbarch, regnum))
1440 {
8dccd430
PA
1441 enum lval_type lval;
1442 CORE_ADDR addr;
1443 int realnum;
1444
1445 frame_register (frame, regnum, optimizedp, unavailablep,
1446 &lval, &addr, &realnum, myaddr);
1447 if (*optimizedp || *unavailablep)
00fa51f6
UW
1448 return 0;
1449 }
1450 else
1451 {
db3a1dc7
AH
1452 struct value *value = frame_unwind_register_value (frame->next,
1453 regnum);
1454 gdb_assert (value != NULL);
1455 *optimizedp = value_optimized_out (value);
1456 *unavailablep = !value_entirely_available (value);
bb9bcb69 1457
8dccd430 1458 if (*optimizedp || *unavailablep)
db3a1dc7
AH
1459 {
1460 release_value (value);
db3a1dc7
AH
1461 return 0;
1462 }
1463 memcpy (myaddr, value_contents_all (value) + offset, curr_len);
1464 release_value (value);
00fa51f6
UW
1465 }
1466
765f065a 1467 myaddr += curr_len;
00fa51f6
UW
1468 len -= curr_len;
1469 offset = 0;
1470 regnum++;
1471 }
1472
8dccd430
PA
1473 *optimizedp = 0;
1474 *unavailablep = 0;
00fa51f6
UW
1475 return 1;
1476}
1477
1478void
1479put_frame_register_bytes (struct frame_info *frame, int regnum,
1480 CORE_ADDR offset, int len, const gdb_byte *myaddr)
1481{
1482 struct gdbarch *gdbarch = get_frame_arch (frame);
1483
1484 /* Skip registers wholly inside of OFFSET. */
1485 while (offset >= register_size (gdbarch, regnum))
1486 {
1487 offset -= register_size (gdbarch, regnum);
1488 regnum++;
1489 }
1490
1491 /* Copy the data. */
1492 while (len > 0)
1493 {
1494 int curr_len = register_size (gdbarch, regnum) - offset;
bb9bcb69 1495
00fa51f6
UW
1496 if (curr_len > len)
1497 curr_len = len;
1498
1499 if (curr_len == register_size (gdbarch, regnum))
1500 {
1501 put_frame_register (frame, regnum, myaddr);
1502 }
1503 else
1504 {
db3a1dc7
AH
1505 struct value *value = frame_unwind_register_value (frame->next,
1506 regnum);
1507 gdb_assert (value != NULL);
1508
1509 memcpy ((char *) value_contents_writeable (value) + offset, myaddr,
1510 curr_len);
1511 put_frame_register (frame, regnum, value_contents_raw (value));
1512 release_value (value);
00fa51f6
UW
1513 }
1514
765f065a 1515 myaddr += curr_len;
00fa51f6
UW
1516 len -= curr_len;
1517 offset = 0;
1518 regnum++;
1519 }
1520}
e36180d7 1521
a94dd1fd
AC
1522/* Create a sentinel frame. */
1523
b9362cc7 1524static struct frame_info *
6c95b8df 1525create_sentinel_frame (struct program_space *pspace, struct regcache *regcache)
a94dd1fd
AC
1526{
1527 struct frame_info *frame = FRAME_OBSTACK_ZALLOC (struct frame_info);
1c4d3f96 1528
a94dd1fd 1529 frame->level = -1;
6c95b8df 1530 frame->pspace = pspace;
a01bda52 1531 frame->aspace = regcache->aspace ();
a94dd1fd
AC
1532 /* Explicitly initialize the sentinel frame's cache. Provide it
1533 with the underlying regcache. In the future additional
1534 information, such as the frame's thread will be added. */
6dc42492 1535 frame->prologue_cache = sentinel_frame_cache (regcache);
a94dd1fd 1536 /* For the moment there is only one sentinel frame implementation. */
39d7b0e2 1537 frame->unwind = &sentinel_frame_unwind;
a94dd1fd
AC
1538 /* Link this frame back to itself. The frame is self referential
1539 (the unwound PC is the same as the pc), so make it so. */
1540 frame->next = frame;
df433d31 1541 /* The sentinel frame has a special ID. */
d0a55772 1542 frame->this_id.p = 1;
df433d31 1543 frame->this_id.value = sentinel_frame_id;
7f78e237
AC
1544 if (frame_debug)
1545 {
1546 fprintf_unfiltered (gdb_stdlog, "{ create_sentinel_frame (...) -> ");
1547 fprint_frame (gdb_stdlog, frame);
1548 fprintf_unfiltered (gdb_stdlog, " }\n");
1549 }
a94dd1fd
AC
1550 return frame;
1551}
1552
4c1e7e9d
AC
1553/* Cache for frame addresses already read by gdb. Valid only while
1554 inferior is stopped. Control variables for the frame cache should
1555 be local to this module. */
1556
1557static struct obstack frame_cache_obstack;
1558
1559void *
479ab5a0 1560frame_obstack_zalloc (unsigned long size)
4c1e7e9d 1561{
479ab5a0 1562 void *data = obstack_alloc (&frame_cache_obstack, size);
1c4d3f96 1563
479ab5a0
AC
1564 memset (data, 0, size);
1565 return data;
4c1e7e9d
AC
1566}
1567
f245535c 1568static struct frame_info *get_prev_frame_always_1 (struct frame_info *this_frame);
4c1e7e9d
AC
1569
1570struct frame_info *
1571get_current_frame (void)
1572{
df433d31
KB
1573 struct frame_info *current_frame;
1574
0a1e1ca1
AC
1575 /* First check, and report, the lack of registers. Having GDB
1576 report "No stack!" or "No memory" when the target doesn't even
1577 have registers is very confusing. Besides, "printcmd.exp"
1578 explicitly checks that ``print $pc'' with no registers prints "No
1579 registers". */
a94dd1fd 1580 if (!target_has_registers)
8a3fe4f8 1581 error (_("No registers."));
0a1e1ca1 1582 if (!target_has_stack)
8a3fe4f8 1583 error (_("No stack."));
a94dd1fd 1584 if (!target_has_memory)
8a3fe4f8 1585 error (_("No memory."));
2ce6d6bf
SS
1586 /* Traceframes are effectively a substitute for the live inferior. */
1587 if (get_traceframe_number () < 0)
a911d87a 1588 validate_registers_access ();
8ea051c5 1589
df433d31
KB
1590 if (sentinel_frame == NULL)
1591 sentinel_frame =
1592 create_sentinel_frame (current_program_space, get_current_regcache ());
1593
1594 /* Set the current frame before computing the frame id, to avoid
1595 recursion inside compute_frame_id, in case the frame's
1596 unwinder decides to do a symbol lookup (which depends on the
1597 selected frame's block).
1598
1599 This call must always succeed. In particular, nothing inside
1600 get_prev_frame_always_1 should try to unwind from the
1601 sentinel frame, because that could fail/throw, and we always
1602 want to leave with the current frame created and linked in --
1603 we should never end up with the sentinel frame as outermost
1604 frame. */
1605 current_frame = get_prev_frame_always_1 (sentinel_frame);
1606 gdb_assert (current_frame != NULL);
f245535c 1607
4c1e7e9d
AC
1608 return current_frame;
1609}
1610
6e7f8b9c
AC
1611/* The "selected" stack frame is used by default for local and arg
1612 access. May be zero, for no selected frame. */
1613
206415a3 1614static struct frame_info *selected_frame;
6e7f8b9c 1615
9d49bdc2 1616int
8ea051c5
PA
1617has_stack_frames (void)
1618{
1619 if (!target_has_registers || !target_has_stack || !target_has_memory)
1620 return 0;
1621
861152be
LM
1622 /* Traceframes are effectively a substitute for the live inferior. */
1623 if (get_traceframe_number () < 0)
1624 {
1625 /* No current inferior, no frame. */
00431a78 1626 if (inferior_ptid == null_ptid)
861152be 1627 return 0;
d729566a 1628
00431a78 1629 thread_info *tp = inferior_thread ();
861152be 1630 /* Don't try to read from a dead thread. */
00431a78 1631 if (tp->state == THREAD_EXITED)
861152be 1632 return 0;
d729566a 1633
861152be 1634 /* ... or from a spinning thread. */
00431a78 1635 if (tp->executing)
861152be
LM
1636 return 0;
1637 }
8ea051c5
PA
1638
1639 return 1;
1640}
1641
bbde78fa 1642/* Return the selected frame. Always non-NULL (unless there isn't an
6e7f8b9c
AC
1643 inferior sufficient for creating a frame) in which case an error is
1644 thrown. */
1645
1646struct frame_info *
b04f3ab4 1647get_selected_frame (const char *message)
6e7f8b9c 1648{
206415a3 1649 if (selected_frame == NULL)
b04f3ab4 1650 {
8ea051c5 1651 if (message != NULL && !has_stack_frames ())
8a3fe4f8 1652 error (("%s"), message);
b04f3ab4
AC
1653 /* Hey! Don't trust this. It should really be re-finding the
1654 last selected frame of the currently selected thread. This,
1655 though, is better than nothing. */
1656 select_frame (get_current_frame ());
1657 }
6e7f8b9c 1658 /* There is always a frame. */
206415a3
DJ
1659 gdb_assert (selected_frame != NULL);
1660 return selected_frame;
6e7f8b9c
AC
1661}
1662
eb8c0621
TT
1663/* If there is a selected frame, return it. Otherwise, return NULL. */
1664
1665struct frame_info *
1666get_selected_frame_if_set (void)
1667{
1668 return selected_frame;
1669}
1670
bbde78fa 1671/* This is a variant of get_selected_frame() which can be called when
7dd88986 1672 the inferior does not have a frame; in that case it will return
bbde78fa 1673 NULL instead of calling error(). */
7dd88986
DJ
1674
1675struct frame_info *
1676deprecated_safe_get_selected_frame (void)
1677{
8ea051c5 1678 if (!has_stack_frames ())
7dd88986 1679 return NULL;
b04f3ab4 1680 return get_selected_frame (NULL);
7dd88986
DJ
1681}
1682
6e7f8b9c
AC
1683/* Select frame FI (or NULL - to invalidate the current frame). */
1684
1685void
1686select_frame (struct frame_info *fi)
1687{
206415a3 1688 selected_frame = fi;
bbde78fa 1689 /* NOTE: cagney/2002-05-04: FI can be NULL. This occurs when the
6e7f8b9c 1690 frame is being invalidated. */
6e7f8b9c
AC
1691
1692 /* FIXME: kseitz/2002-08-28: It would be nice to call
bbde78fa 1693 selected_frame_level_changed_event() right here, but due to limitations
6e7f8b9c 1694 in the current interfaces, we would end up flooding UIs with events
bbde78fa 1695 because select_frame() is used extensively internally.
6e7f8b9c
AC
1696
1697 Once we have frame-parameterized frame (and frame-related) commands,
1698 the event notification can be moved here, since this function will only
0963b4bd 1699 be called when the user's selected frame is being changed. */
6e7f8b9c
AC
1700
1701 /* Ensure that symbols for this frame are read in. Also, determine the
1702 source language of this frame, and switch to it if desired. */
1703 if (fi)
1704 {
e3eebbd7
PA
1705 CORE_ADDR pc;
1706
1707 /* We retrieve the frame's symtab by using the frame PC.
1708 However we cannot use the frame PC as-is, because it usually
1709 points to the instruction following the "call", which is
1710 sometimes the first instruction of another function. So we
1711 rely on get_frame_address_in_block() which provides us with a
1712 PC which is guaranteed to be inside the frame's code
1713 block. */
1714 if (get_frame_address_in_block_if_available (fi, &pc))
6e7f8b9c 1715 {
43f3e411 1716 struct compunit_symtab *cust = find_pc_compunit_symtab (pc);
e3eebbd7 1717
43f3e411
DE
1718 if (cust != NULL
1719 && compunit_language (cust) != current_language->la_language
1720 && compunit_language (cust) != language_unknown
e3eebbd7 1721 && language_mode == language_mode_auto)
43f3e411 1722 set_language (compunit_language (cust));
6e7f8b9c
AC
1723 }
1724 }
1725}
e3eebbd7 1726
4c1e7e9d
AC
1727/* Create an arbitrary (i.e. address specified by user) or innermost frame.
1728 Always returns a non-NULL value. */
1729
1730struct frame_info *
1731create_new_frame (CORE_ADDR addr, CORE_ADDR pc)
1732{
1733 struct frame_info *fi;
4c1e7e9d 1734
7f78e237
AC
1735 if (frame_debug)
1736 {
1737 fprintf_unfiltered (gdb_stdlog,
5af949e3
UW
1738 "{ create_new_frame (addr=%s, pc=%s) ",
1739 hex_string (addr), hex_string (pc));
7f78e237
AC
1740 }
1741
35d5d4ee 1742 fi = FRAME_OBSTACK_ZALLOC (struct frame_info);
4c1e7e9d 1743
3e43a32a
MS
1744 fi->next = create_sentinel_frame (current_program_space,
1745 get_current_regcache ());
7df05f2b 1746
1e275f79
PA
1747 /* Set/update this frame's cached PC value, found in the next frame.
1748 Do this before looking for this frame's unwinder. A sniffer is
1749 very likely to read this, and the corresponding unwinder is
1750 entitled to rely that the PC doesn't magically change. */
1751 fi->next->prev_pc.value = pc;
782d47df 1752 fi->next->prev_pc.status = CC_VALUE;
1e275f79 1753
6c95b8df
PA
1754 /* We currently assume that frame chain's can't cross spaces. */
1755 fi->pspace = fi->next->pspace;
1756 fi->aspace = fi->next->aspace;
1757
7df05f2b
AC
1758 /* Select/initialize both the unwind function and the frame's type
1759 based on the PC. */
9f9a8002 1760 frame_unwind_find_by_frame (fi, &fi->prologue_cache);
7df05f2b 1761
18adea3f 1762 fi->this_id.p = 1;
1e275f79 1763 fi->this_id.value = frame_id_build (addr, pc);
4c1e7e9d 1764
7f78e237
AC
1765 if (frame_debug)
1766 {
1767 fprintf_unfiltered (gdb_stdlog, "-> ");
1768 fprint_frame (gdb_stdlog, fi);
1769 fprintf_unfiltered (gdb_stdlog, " }\n");
1770 }
1771
4c1e7e9d
AC
1772 return fi;
1773}
1774
03febf99
AC
1775/* Return the frame that THIS_FRAME calls (NULL if THIS_FRAME is the
1776 innermost frame). Be careful to not fall off the bottom of the
1777 frame chain and onto the sentinel frame. */
4c1e7e9d
AC
1778
1779struct frame_info *
03febf99 1780get_next_frame (struct frame_info *this_frame)
4c1e7e9d 1781{
03febf99
AC
1782 if (this_frame->level > 0)
1783 return this_frame->next;
a94dd1fd
AC
1784 else
1785 return NULL;
4c1e7e9d
AC
1786}
1787
df433d31
KB
1788/* Return the frame that THIS_FRAME calls. If THIS_FRAME is the
1789 innermost (i.e. current) frame, return the sentinel frame. Thus,
1790 unlike get_next_frame(), NULL will never be returned. */
1791
1792struct frame_info *
1793get_next_frame_sentinel_okay (struct frame_info *this_frame)
1794{
1795 gdb_assert (this_frame != NULL);
1796
1797 /* Note that, due to the manner in which the sentinel frame is
1798 constructed, this_frame->next still works even when this_frame
1799 is the sentinel frame. But we disallow it here anyway because
1800 calling get_next_frame_sentinel_okay() on the sentinel frame
1801 is likely a coding error. */
1802 gdb_assert (this_frame != sentinel_frame);
1803
1804 return this_frame->next;
1805}
1806
f4c5303c
OF
1807/* Observer for the target_changed event. */
1808
2c0b251b 1809static void
f4c5303c
OF
1810frame_observer_target_changed (struct target_ops *target)
1811{
35f196d9 1812 reinit_frame_cache ();
f4c5303c
OF
1813}
1814
4c1e7e9d
AC
1815/* Flush the entire frame cache. */
1816
1817void
35f196d9 1818reinit_frame_cache (void)
4c1e7e9d 1819{
272dfcfd
AS
1820 struct frame_info *fi;
1821
1822 /* Tear down all frame caches. */
df433d31 1823 for (fi = sentinel_frame; fi != NULL; fi = fi->prev)
272dfcfd
AS
1824 {
1825 if (fi->prologue_cache && fi->unwind->dealloc_cache)
1826 fi->unwind->dealloc_cache (fi, fi->prologue_cache);
1827 if (fi->base_cache && fi->base->unwind->dealloc_cache)
1828 fi->base->unwind->dealloc_cache (fi, fi->base_cache);
1829 }
1830
0963b4bd 1831 /* Since we can't really be sure what the first object allocated was. */
4c1e7e9d
AC
1832 obstack_free (&frame_cache_obstack, 0);
1833 obstack_init (&frame_cache_obstack);
1834
df433d31 1835 if (sentinel_frame != NULL)
0d6ba1b1
DJ
1836 annotate_frames_invalid ();
1837
df433d31 1838 sentinel_frame = NULL; /* Invalidate cache */
4c1e7e9d 1839 select_frame (NULL);
b83e9eb7 1840 frame_stash_invalidate ();
7f78e237 1841 if (frame_debug)
35f196d9 1842 fprintf_unfiltered (gdb_stdlog, "{ reinit_frame_cache () }\n");
4c1e7e9d
AC
1843}
1844
e48af409
DJ
1845/* Find where a register is saved (in memory or another register).
1846 The result of frame_register_unwind is just where it is saved
5efde112 1847 relative to this particular frame. */
e48af409
DJ
1848
1849static void
1850frame_register_unwind_location (struct frame_info *this_frame, int regnum,
1851 int *optimizedp, enum lval_type *lvalp,
1852 CORE_ADDR *addrp, int *realnump)
1853{
1854 gdb_assert (this_frame == NULL || this_frame->level >= 0);
1855
1856 while (this_frame != NULL)
1857 {
0fdb4f18
PA
1858 int unavailable;
1859
1860 frame_register_unwind (this_frame, regnum, optimizedp, &unavailable,
1861 lvalp, addrp, realnump, NULL);
e48af409
DJ
1862
1863 if (*optimizedp)
1864 break;
1865
1866 if (*lvalp != lval_register)
1867 break;
1868
1869 regnum = *realnump;
1870 this_frame = get_next_frame (this_frame);
1871 }
1872}
1873
194cca41
PA
1874/* Get the previous raw frame, and check that it is not identical to
1875 same other frame frame already in the chain. If it is, there is
1876 most likely a stack cycle, so we discard it, and mark THIS_FRAME as
1877 outermost, with UNWIND_SAME_ID stop reason. Unlike the other
1878 validity tests, that compare THIS_FRAME and the next frame, we do
1879 this right after creating the previous frame, to avoid ever ending
1880 up with two frames with the same id in the frame chain. */
1881
1882static struct frame_info *
1883get_prev_frame_if_no_cycle (struct frame_info *this_frame)
1884{
1885 struct frame_info *prev_frame;
1886
1887 prev_frame = get_prev_frame_raw (this_frame);
f245535c
PA
1888
1889 /* Don't compute the frame id of the current frame yet. Unwinding
1890 the sentinel frame can fail (e.g., if the thread is gone and we
1891 can't thus read its registers). If we let the cycle detection
1892 code below try to compute a frame ID, then an error thrown from
1893 within the frame ID computation would result in the sentinel
1894 frame as outermost frame, which is bogus. Instead, we'll compute
1895 the current frame's ID lazily in get_frame_id. Note that there's
1896 no point in doing cycle detection when there's only one frame, so
1897 nothing is lost here. */
1898 if (prev_frame->level == 0)
1899 return prev_frame;
194cca41 1900
a70b8144 1901 try
194cca41 1902 {
09a5e1b5
TT
1903 compute_frame_id (prev_frame);
1904 if (!frame_stash_add (prev_frame))
938f0e2f 1905 {
09a5e1b5
TT
1906 /* Another frame with the same id was already in the stash. We just
1907 detected a cycle. */
1908 if (frame_debug)
1909 {
1910 fprintf_unfiltered (gdb_stdlog, "-> ");
1911 fprint_frame (gdb_stdlog, NULL);
1912 fprintf_unfiltered (gdb_stdlog, " // this frame has same ID }\n");
1913 }
1914 this_frame->stop_reason = UNWIND_SAME_ID;
1915 /* Unlink. */
1916 prev_frame->next = NULL;
1917 this_frame->prev = NULL;
1918 prev_frame = NULL;
938f0e2f 1919 }
09a5e1b5 1920 }
230d2906 1921 catch (const gdb_exception &ex)
09a5e1b5 1922 {
938f0e2f
AB
1923 prev_frame->next = NULL;
1924 this_frame->prev = NULL;
09a5e1b5 1925
eedc3f4f 1926 throw;
194cca41 1927 }
938f0e2f 1928
938f0e2f 1929 return prev_frame;
194cca41
PA
1930}
1931
53e8a631
AB
1932/* Helper function for get_prev_frame_always, this is called inside a
1933 TRY_CATCH block. Return the frame that called THIS_FRAME or NULL if
1934 there is no such frame. This may throw an exception. */
eb4f72c5 1935
53e8a631
AB
1936static struct frame_info *
1937get_prev_frame_always_1 (struct frame_info *this_frame)
eb4f72c5 1938{
b1bd0044 1939 struct gdbarch *gdbarch;
eb4f72c5 1940
5613d8d3 1941 gdb_assert (this_frame != NULL);
b1bd0044 1942 gdbarch = get_frame_arch (this_frame);
5613d8d3 1943
7f78e237
AC
1944 if (frame_debug)
1945 {
51d48146 1946 fprintf_unfiltered (gdb_stdlog, "{ get_prev_frame_always (this_frame=");
7f78e237
AC
1947 if (this_frame != NULL)
1948 fprintf_unfiltered (gdb_stdlog, "%d", this_frame->level);
1949 else
1950 fprintf_unfiltered (gdb_stdlog, "<NULL>");
1951 fprintf_unfiltered (gdb_stdlog, ") ");
1952 }
1953
5613d8d3
AC
1954 /* Only try to do the unwind once. */
1955 if (this_frame->prev_p)
1956 {
1957 if (frame_debug)
1958 {
1959 fprintf_unfiltered (gdb_stdlog, "-> ");
1960 fprint_frame (gdb_stdlog, this_frame->prev);
1961 fprintf_unfiltered (gdb_stdlog, " // cached \n");
1962 }
1963 return this_frame->prev;
1964 }
8fa75a5d 1965
0d254d6f
DJ
1966 /* If the frame unwinder hasn't been selected yet, we must do so
1967 before setting prev_p; otherwise the check for misbehaved
1968 sniffers will think that this frame's sniffer tried to unwind
1969 further (see frame_cleanup_after_sniffer). */
1970 if (this_frame->unwind == NULL)
9f9a8002 1971 frame_unwind_find_by_frame (this_frame, &this_frame->prologue_cache);
8fa75a5d 1972
5613d8d3 1973 this_frame->prev_p = 1;
55feb689 1974 this_frame->stop_reason = UNWIND_NO_REASON;
5613d8d3 1975
edb3359d
DJ
1976 /* If we are unwinding from an inline frame, all of the below tests
1977 were already performed when we unwound from the next non-inline
1978 frame. We must skip them, since we can not get THIS_FRAME's ID
1979 until we have unwound all the way down to the previous non-inline
1980 frame. */
1981 if (get_frame_type (this_frame) == INLINE_FRAME)
194cca41 1982 return get_prev_frame_if_no_cycle (this_frame);
edb3359d 1983
8fbca658
PA
1984 /* Check that this frame is unwindable. If it isn't, don't try to
1985 unwind to the prev frame. */
1986 this_frame->stop_reason
1987 = this_frame->unwind->stop_reason (this_frame,
1988 &this_frame->prologue_cache);
1989
1990 if (this_frame->stop_reason != UNWIND_NO_REASON)
a7300869
PA
1991 {
1992 if (frame_debug)
1993 {
1994 enum unwind_stop_reason reason = this_frame->stop_reason;
1995
1996 fprintf_unfiltered (gdb_stdlog, "-> ");
1997 fprint_frame (gdb_stdlog, NULL);
1998 fprintf_unfiltered (gdb_stdlog, " // %s }\n",
1999 frame_stop_reason_symbol_string (reason));
2000 }
2001 return NULL;
2002 }
8fbca658 2003
5613d8d3
AC
2004 /* Check that this frame's ID isn't inner to (younger, below, next)
2005 the next frame. This happens when a frame unwind goes backwards.
f06eadd9
JB
2006 This check is valid only if this frame and the next frame are NORMAL.
2007 See the comment at frame_id_inner for details. */
2008 if (get_frame_type (this_frame) == NORMAL_FRAME
2009 && this_frame->next->unwind->type == NORMAL_FRAME
da361ebd
JB
2010 && frame_id_inner (get_frame_arch (this_frame->next),
2011 get_frame_id (this_frame),
09a7aba8 2012 get_frame_id (this_frame->next)))
55feb689 2013 {
ebedcab5
JK
2014 CORE_ADDR this_pc_in_block;
2015 struct minimal_symbol *morestack_msym;
2016 const char *morestack_name = NULL;
2017
2018 /* gcc -fsplit-stack __morestack can continue the stack anywhere. */
2019 this_pc_in_block = get_frame_address_in_block (this_frame);
7cbd4a93 2020 morestack_msym = lookup_minimal_symbol_by_pc (this_pc_in_block).minsym;
ebedcab5 2021 if (morestack_msym)
efd66ac6 2022 morestack_name = MSYMBOL_LINKAGE_NAME (morestack_msym);
ebedcab5 2023 if (!morestack_name || strcmp (morestack_name, "__morestack") != 0)
55feb689 2024 {
ebedcab5
JK
2025 if (frame_debug)
2026 {
2027 fprintf_unfiltered (gdb_stdlog, "-> ");
2028 fprint_frame (gdb_stdlog, NULL);
3e43a32a
MS
2029 fprintf_unfiltered (gdb_stdlog,
2030 " // this frame ID is inner }\n");
ebedcab5
JK
2031 }
2032 this_frame->stop_reason = UNWIND_INNER_ID;
2033 return NULL;
55feb689 2034 }
55feb689 2035 }
5613d8d3 2036
e48af409
DJ
2037 /* Check that this and the next frame do not unwind the PC register
2038 to the same memory location. If they do, then even though they
2039 have different frame IDs, the new frame will be bogus; two
2040 functions can't share a register save slot for the PC. This can
2041 happen when the prologue analyzer finds a stack adjustment, but
d57df5e4
DJ
2042 no PC save.
2043
2044 This check does assume that the "PC register" is roughly a
2045 traditional PC, even if the gdbarch_unwind_pc method adjusts
2046 it (we do not rely on the value, only on the unwound PC being
2047 dependent on this value). A potential improvement would be
2048 to have the frame prev_pc method and the gdbarch unwind_pc
2049 method set the same lval and location information as
2050 frame_register_unwind. */
e48af409 2051 if (this_frame->level > 0
b1bd0044 2052 && gdbarch_pc_regnum (gdbarch) >= 0
e48af409 2053 && get_frame_type (this_frame) == NORMAL_FRAME
edb3359d
DJ
2054 && (get_frame_type (this_frame->next) == NORMAL_FRAME
2055 || get_frame_type (this_frame->next) == INLINE_FRAME))
e48af409 2056 {
32276632 2057 int optimized, realnum, nrealnum;
e48af409
DJ
2058 enum lval_type lval, nlval;
2059 CORE_ADDR addr, naddr;
2060
3e8c568d 2061 frame_register_unwind_location (this_frame,
b1bd0044 2062 gdbarch_pc_regnum (gdbarch),
3e8c568d
UW
2063 &optimized, &lval, &addr, &realnum);
2064 frame_register_unwind_location (get_next_frame (this_frame),
b1bd0044 2065 gdbarch_pc_regnum (gdbarch),
32276632 2066 &optimized, &nlval, &naddr, &nrealnum);
e48af409 2067
32276632
DJ
2068 if ((lval == lval_memory && lval == nlval && addr == naddr)
2069 || (lval == lval_register && lval == nlval && realnum == nrealnum))
e48af409
DJ
2070 {
2071 if (frame_debug)
2072 {
2073 fprintf_unfiltered (gdb_stdlog, "-> ");
2074 fprint_frame (gdb_stdlog, NULL);
2075 fprintf_unfiltered (gdb_stdlog, " // no saved PC }\n");
2076 }
2077
2078 this_frame->stop_reason = UNWIND_NO_SAVED_PC;
2079 this_frame->prev = NULL;
2080 return NULL;
2081 }
2082 }
2083
194cca41 2084 return get_prev_frame_if_no_cycle (this_frame);
edb3359d
DJ
2085}
2086
53e8a631
AB
2087/* Return a "struct frame_info" corresponding to the frame that called
2088 THIS_FRAME. Returns NULL if there is no such frame.
2089
2090 Unlike get_prev_frame, this function always tries to unwind the
2091 frame. */
2092
2093struct frame_info *
2094get_prev_frame_always (struct frame_info *this_frame)
2095{
53e8a631
AB
2096 struct frame_info *prev_frame = NULL;
2097
a70b8144 2098 try
53e8a631
AB
2099 {
2100 prev_frame = get_prev_frame_always_1 (this_frame);
2101 }
230d2906 2102 catch (const gdb_exception_error &ex)
53e8a631
AB
2103 {
2104 if (ex.error == MEMORY_ERROR)
2105 {
2106 this_frame->stop_reason = UNWIND_MEMORY_ERROR;
2107 if (ex.message != NULL)
2108 {
2109 char *stop_string;
2110 size_t size;
2111
2112 /* The error needs to live as long as the frame does.
2113 Allocate using stack local STOP_STRING then assign the
2114 pointer to the frame, this allows the STOP_STRING on the
2115 frame to be of type 'const char *'. */
3d6e9d23 2116 size = ex.message->size () + 1;
224c3ddb 2117 stop_string = (char *) frame_obstack_zalloc (size);
3d6e9d23 2118 memcpy (stop_string, ex.what (), size);
53e8a631
AB
2119 this_frame->stop_string = stop_string;
2120 }
2121 prev_frame = NULL;
2122 }
2123 else
eedc3f4f 2124 throw;
53e8a631
AB
2125 }
2126
2127 return prev_frame;
2128}
2129
edb3359d
DJ
2130/* Construct a new "struct frame_info" and link it previous to
2131 this_frame. */
2132
2133static struct frame_info *
2134get_prev_frame_raw (struct frame_info *this_frame)
2135{
2136 struct frame_info *prev_frame;
2137
5613d8d3
AC
2138 /* Allocate the new frame but do not wire it in to the frame chain.
2139 Some (bad) code in INIT_FRAME_EXTRA_INFO tries to look along
2140 frame->next to pull some fancy tricks (of course such code is, by
2141 definition, recursive). Try to prevent it.
2142
2143 There is no reason to worry about memory leaks, should the
2144 remainder of the function fail. The allocated memory will be
2145 quickly reclaimed when the frame cache is flushed, and the `we've
2146 been here before' check above will stop repeated memory
2147 allocation calls. */
2148 prev_frame = FRAME_OBSTACK_ZALLOC (struct frame_info);
2149 prev_frame->level = this_frame->level + 1;
2150
6c95b8df
PA
2151 /* For now, assume we don't have frame chains crossing address
2152 spaces. */
2153 prev_frame->pspace = this_frame->pspace;
2154 prev_frame->aspace = this_frame->aspace;
2155
5613d8d3
AC
2156 /* Don't yet compute ->unwind (and hence ->type). It is computed
2157 on-demand in get_frame_type, frame_register_unwind, and
2158 get_frame_id. */
2159
2160 /* Don't yet compute the frame's ID. It is computed on-demand by
2161 get_frame_id(). */
2162
2163 /* The unwound frame ID is validate at the start of this function,
2164 as part of the logic to decide if that frame should be further
2165 unwound, and not here while the prev frame is being created.
2166 Doing this makes it possible for the user to examine a frame that
2167 has an invalid frame ID.
2168
2169 Some very old VAX code noted: [...] For the sake of argument,
2170 suppose that the stack is somewhat trashed (which is one reason
2171 that "info frame" exists). So, return 0 (indicating we don't
2172 know the address of the arglist) if we don't know what frame this
2173 frame calls. */
2174
2175 /* Link it in. */
2176 this_frame->prev = prev_frame;
2177 prev_frame->next = this_frame;
2178
2179 if (frame_debug)
2180 {
2181 fprintf_unfiltered (gdb_stdlog, "-> ");
2182 fprint_frame (gdb_stdlog, prev_frame);
2183 fprintf_unfiltered (gdb_stdlog, " }\n");
2184 }
2185
2186 return prev_frame;
2187}
2188
2189/* Debug routine to print a NULL frame being returned. */
2190
2191static void
d2bf72c0 2192frame_debug_got_null_frame (struct frame_info *this_frame,
5613d8d3
AC
2193 const char *reason)
2194{
2195 if (frame_debug)
2196 {
2197 fprintf_unfiltered (gdb_stdlog, "{ get_prev_frame (this_frame=");
2198 if (this_frame != NULL)
2199 fprintf_unfiltered (gdb_stdlog, "%d", this_frame->level);
2200 else
2201 fprintf_unfiltered (gdb_stdlog, "<NULL>");
2202 fprintf_unfiltered (gdb_stdlog, ") -> // %s}\n", reason);
2203 }
2204}
2205
c8cd9f6c
AC
2206/* Is this (non-sentinel) frame in the "main"() function? */
2207
2208static int
2209inside_main_func (struct frame_info *this_frame)
2210{
3b7344d5 2211 struct bound_minimal_symbol msymbol;
c8cd9f6c
AC
2212 CORE_ADDR maddr;
2213
2214 if (symfile_objfile == 0)
2215 return 0;
2216 msymbol = lookup_minimal_symbol (main_name (), NULL, symfile_objfile);
3b7344d5 2217 if (msymbol.minsym == NULL)
c8cd9f6c
AC
2218 return 0;
2219 /* Make certain that the code, and not descriptor, address is
2220 returned. */
b1bd0044 2221 maddr = gdbarch_convert_from_func_ptr_addr (get_frame_arch (this_frame),
77e371c0 2222 BMSYMBOL_VALUE_ADDRESS (msymbol),
8b88a78e 2223 current_top_target ());
c8cd9f6c
AC
2224 return maddr == get_frame_func (this_frame);
2225}
2226
2315ffec
RC
2227/* Test whether THIS_FRAME is inside the process entry point function. */
2228
2229static int
2230inside_entry_func (struct frame_info *this_frame)
2231{
abd0a5fa
JK
2232 CORE_ADDR entry_point;
2233
2234 if (!entry_point_address_query (&entry_point))
2235 return 0;
2236
2237 return get_frame_func (this_frame) == entry_point;
2315ffec
RC
2238}
2239
5613d8d3
AC
2240/* Return a structure containing various interesting information about
2241 the frame that called THIS_FRAME. Returns NULL if there is entier
2242 no such frame or the frame fails any of a set of target-independent
2243 condition that should terminate the frame chain (e.g., as unwinding
2244 past main()).
2245
2246 This function should not contain target-dependent tests, such as
2247 checking whether the program-counter is zero. */
2248
2249struct frame_info *
2250get_prev_frame (struct frame_info *this_frame)
2251{
e3eebbd7
PA
2252 CORE_ADDR frame_pc;
2253 int frame_pc_p;
2254
eb4f72c5
AC
2255 /* There is always a frame. If this assertion fails, suspect that
2256 something should be calling get_selected_frame() or
2257 get_current_frame(). */
03febf99 2258 gdb_assert (this_frame != NULL);
256ae5db
KB
2259
2260 /* If this_frame is the current frame, then compute and stash
2261 its frame id prior to fetching and computing the frame id of the
2262 previous frame. Otherwise, the cycle detection code in
2263 get_prev_frame_if_no_cycle() will not work correctly. When
2264 get_frame_id() is called later on, an assertion error will
2265 be triggered in the event of a cycle between the current
2266 frame and its previous frame. */
2267 if (this_frame->level == 0)
2268 get_frame_id (this_frame);
2269
e3eebbd7 2270 frame_pc_p = get_frame_pc_if_available (this_frame, &frame_pc);
eb4f72c5 2271
cc9bed83
RC
2272 /* tausq/2004-12-07: Dummy frames are skipped because it doesn't make much
2273 sense to stop unwinding at a dummy frame. One place where a dummy
2274 frame may have an address "inside_main_func" is on HPUX. On HPUX, the
2275 pcsqh register (space register for the instruction at the head of the
2276 instruction queue) cannot be written directly; the only way to set it
2277 is to branch to code that is in the target space. In order to implement
2278 frame dummies on HPUX, the called function is made to jump back to where
2279 the inferior was when the user function was called. If gdb was inside
2280 the main function when we created the dummy frame, the dummy frame will
2281 point inside the main function. */
03febf99 2282 if (this_frame->level >= 0
edb3359d 2283 && get_frame_type (this_frame) == NORMAL_FRAME
d4c16835 2284 && !user_set_backtrace_options.backtrace_past_main
e3eebbd7 2285 && frame_pc_p
c8cd9f6c
AC
2286 && inside_main_func (this_frame))
2287 /* Don't unwind past main(). Note, this is done _before_ the
2288 frame has been marked as previously unwound. That way if the
2289 user later decides to enable unwinds past main(), that will
2290 automatically happen. */
ac2bd0a9 2291 {
d2bf72c0 2292 frame_debug_got_null_frame (this_frame, "inside main func");
ac2bd0a9
AC
2293 return NULL;
2294 }
eb4f72c5 2295
4a5e53e8
DJ
2296 /* If the user's backtrace limit has been exceeded, stop. We must
2297 add two to the current level; one of those accounts for backtrace_limit
2298 being 1-based and the level being 0-based, and the other accounts for
2299 the level of the new frame instead of the level of the current
2300 frame. */
d4c16835 2301 if (this_frame->level + 2 > user_set_backtrace_options.backtrace_limit)
25d29d70 2302 {
d2bf72c0 2303 frame_debug_got_null_frame (this_frame, "backtrace limit exceeded");
4a5e53e8 2304 return NULL;
25d29d70
AC
2305 }
2306
0714963c
AC
2307 /* If we're already inside the entry function for the main objfile,
2308 then it isn't valid. Don't apply this test to a dummy frame -
bbde78fa 2309 dummy frame PCs typically land in the entry func. Don't apply
0714963c
AC
2310 this test to the sentinel frame. Sentinel frames should always
2311 be allowed to unwind. */
2f72f850
AC
2312 /* NOTE: cagney/2003-07-07: Fixed a bug in inside_main_func() -
2313 wasn't checking for "main" in the minimal symbols. With that
2314 fixed asm-source tests now stop in "main" instead of halting the
bbde78fa 2315 backtrace in weird and wonderful ways somewhere inside the entry
2f72f850
AC
2316 file. Suspect that tests for inside the entry file/func were
2317 added to work around that (now fixed) case. */
0714963c
AC
2318 /* NOTE: cagney/2003-07-15: danielj (if I'm reading it right)
2319 suggested having the inside_entry_func test use the
bbde78fa
JM
2320 inside_main_func() msymbol trick (along with entry_point_address()
2321 I guess) to determine the address range of the start function.
0714963c
AC
2322 That should provide a far better stopper than the current
2323 heuristics. */
2315ffec
RC
2324 /* NOTE: tausq/2004-10-09: this is needed if, for example, the compiler
2325 applied tail-call optimizations to main so that a function called
2326 from main returns directly to the caller of main. Since we don't
2327 stop at main, we should at least stop at the entry point of the
2328 application. */
edb3359d
DJ
2329 if (this_frame->level >= 0
2330 && get_frame_type (this_frame) == NORMAL_FRAME
d4c16835 2331 && !user_set_backtrace_options.backtrace_past_entry
e3eebbd7 2332 && frame_pc_p
6e4c6c91 2333 && inside_entry_func (this_frame))
0714963c 2334 {
d2bf72c0 2335 frame_debug_got_null_frame (this_frame, "inside entry func");
0714963c
AC
2336 return NULL;
2337 }
2338
39ee2ff0
AC
2339 /* Assume that the only way to get a zero PC is through something
2340 like a SIGSEGV or a dummy frame, and hence that NORMAL frames
2341 will never unwind a zero PC. */
2342 if (this_frame->level > 0
edb3359d
DJ
2343 && (get_frame_type (this_frame) == NORMAL_FRAME
2344 || get_frame_type (this_frame) == INLINE_FRAME)
39ee2ff0 2345 && get_frame_type (get_next_frame (this_frame)) == NORMAL_FRAME
e3eebbd7 2346 && frame_pc_p && frame_pc == 0)
39ee2ff0 2347 {
d2bf72c0 2348 frame_debug_got_null_frame (this_frame, "zero PC");
39ee2ff0
AC
2349 return NULL;
2350 }
2351
51d48146 2352 return get_prev_frame_always (this_frame);
eb4f72c5
AC
2353}
2354
41b56feb
KB
2355struct frame_id
2356get_prev_frame_id_by_id (struct frame_id id)
2357{
2358 struct frame_id prev_id;
2359 struct frame_info *frame;
2360
2361 frame = frame_find_by_id (id);
2362
2363 if (frame != NULL)
2364 prev_id = get_frame_id (get_prev_frame (frame));
2365 else
2366 prev_id = null_frame_id;
2367
2368 return prev_id;
2369}
2370
4c1e7e9d
AC
2371CORE_ADDR
2372get_frame_pc (struct frame_info *frame)
2373{
d1340264 2374 gdb_assert (frame->next != NULL);
edb3359d 2375 return frame_unwind_pc (frame->next);
4c1e7e9d
AC
2376}
2377
e3eebbd7
PA
2378int
2379get_frame_pc_if_available (struct frame_info *frame, CORE_ADDR *pc)
2380{
e3eebbd7
PA
2381
2382 gdb_assert (frame->next != NULL);
2383
a70b8144 2384 try
e3eebbd7
PA
2385 {
2386 *pc = frame_unwind_pc (frame->next);
2387 }
230d2906 2388 catch (const gdb_exception_error &ex)
e3eebbd7
PA
2389 {
2390 if (ex.error == NOT_AVAILABLE_ERROR)
2391 return 0;
2392 else
eedc3f4f 2393 throw;
e3eebbd7
PA
2394 }
2395
2396 return 1;
2397}
2398
ad1193e7 2399/* Return an address that falls within THIS_FRAME's code block. */
8edd5d01
AC
2400
2401CORE_ADDR
ad1193e7 2402get_frame_address_in_block (struct frame_info *this_frame)
8edd5d01
AC
2403{
2404 /* A draft address. */
ad1193e7 2405 CORE_ADDR pc = get_frame_pc (this_frame);
8edd5d01 2406
ad1193e7
DJ
2407 struct frame_info *next_frame = this_frame->next;
2408
2409 /* Calling get_frame_pc returns the resume address for THIS_FRAME.
2410 Normally the resume address is inside the body of the function
2411 associated with THIS_FRAME, but there is a special case: when
2412 calling a function which the compiler knows will never return
2413 (for instance abort), the call may be the very last instruction
2414 in the calling function. The resume address will point after the
2415 call and may be at the beginning of a different function
2416 entirely.
2417
2418 If THIS_FRAME is a signal frame or dummy frame, then we should
2419 not adjust the unwound PC. For a dummy frame, GDB pushed the
2420 resume address manually onto the stack. For a signal frame, the
2421 OS may have pushed the resume address manually and invoked the
2422 handler (e.g. GNU/Linux), or invoked the trampoline which called
2423 the signal handler - but in either case the signal handler is
2424 expected to return to the trampoline. So in both of these
2425 cases we know that the resume address is executable and
2426 related. So we only need to adjust the PC if THIS_FRAME
2427 is a normal function.
2428
2429 If the program has been interrupted while THIS_FRAME is current,
2430 then clearly the resume address is inside the associated
2431 function. There are three kinds of interruption: debugger stop
2432 (next frame will be SENTINEL_FRAME), operating system
2433 signal or exception (next frame will be SIGTRAMP_FRAME),
2434 or debugger-induced function call (next frame will be
2435 DUMMY_FRAME). So we only need to adjust the PC if
2436 NEXT_FRAME is a normal function.
2437
2438 We check the type of NEXT_FRAME first, since it is already
2439 known; frame type is determined by the unwinder, and since
2440 we have THIS_FRAME we've already selected an unwinder for
edb3359d
DJ
2441 NEXT_FRAME.
2442
2443 If the next frame is inlined, we need to keep going until we find
2444 the real function - for instance, if a signal handler is invoked
2445 while in an inlined function, then the code address of the
2446 "calling" normal function should not be adjusted either. */
2447
2448 while (get_frame_type (next_frame) == INLINE_FRAME)
2449 next_frame = next_frame->next;
2450
111c6489
JK
2451 if ((get_frame_type (next_frame) == NORMAL_FRAME
2452 || get_frame_type (next_frame) == TAILCALL_FRAME)
edb3359d 2453 && (get_frame_type (this_frame) == NORMAL_FRAME
111c6489 2454 || get_frame_type (this_frame) == TAILCALL_FRAME
edb3359d 2455 || get_frame_type (this_frame) == INLINE_FRAME))
ad1193e7
DJ
2456 return pc - 1;
2457
2458 return pc;
8edd5d01
AC
2459}
2460
e3eebbd7
PA
2461int
2462get_frame_address_in_block_if_available (struct frame_info *this_frame,
2463 CORE_ADDR *pc)
2464{
e3eebbd7 2465
a70b8144 2466 try
e3eebbd7
PA
2467 {
2468 *pc = get_frame_address_in_block (this_frame);
2469 }
230d2906 2470 catch (const gdb_exception_error &ex)
7556d4a4
PA
2471 {
2472 if (ex.error == NOT_AVAILABLE_ERROR)
2473 return 0;
eedc3f4f 2474 throw;
7556d4a4
PA
2475 }
2476
2477 return 1;
e3eebbd7
PA
2478}
2479
51abb421
PA
2480symtab_and_line
2481find_frame_sal (frame_info *frame)
1058bca7 2482{
edb3359d
DJ
2483 struct frame_info *next_frame;
2484 int notcurrent;
e3eebbd7 2485 CORE_ADDR pc;
edb3359d
DJ
2486
2487 /* If the next frame represents an inlined function call, this frame's
2488 sal is the "call site" of that inlined function, which can not
2489 be inferred from get_frame_pc. */
2490 next_frame = get_next_frame (frame);
2491 if (frame_inlined_callees (frame) > 0)
2492 {
2493 struct symbol *sym;
2494
2495 if (next_frame)
2496 sym = get_frame_function (next_frame);
2497 else
00431a78 2498 sym = inline_skipped_symbol (inferior_thread ());
edb3359d 2499
f3df5b08
MS
2500 /* If frame is inline, it certainly has symbols. */
2501 gdb_assert (sym);
51abb421
PA
2502
2503 symtab_and_line sal;
edb3359d
DJ
2504 if (SYMBOL_LINE (sym) != 0)
2505 {
51abb421
PA
2506 sal.symtab = symbol_symtab (sym);
2507 sal.line = SYMBOL_LINE (sym);
edb3359d
DJ
2508 }
2509 else
2510 /* If the symbol does not have a location, we don't know where
2511 the call site is. Do not pretend to. This is jarring, but
2512 we can't do much better. */
51abb421 2513 sal.pc = get_frame_pc (frame);
edb3359d 2514
51abb421
PA
2515 sal.pspace = get_frame_program_space (frame);
2516 return sal;
edb3359d
DJ
2517 }
2518
1058bca7
AC
2519 /* If FRAME is not the innermost frame, that normally means that
2520 FRAME->pc points at the return instruction (which is *after* the
2521 call instruction), and we want to get the line containing the
2522 call (because the call is where the user thinks the program is).
2523 However, if the next frame is either a SIGTRAMP_FRAME or a
2524 DUMMY_FRAME, then the next frame will contain a saved interrupt
2525 PC and such a PC indicates the current (rather than next)
2526 instruction/line, consequently, for such cases, want to get the
2527 line containing fi->pc. */
e3eebbd7 2528 if (!get_frame_pc_if_available (frame, &pc))
51abb421 2529 return {};
e3eebbd7
PA
2530
2531 notcurrent = (pc != get_frame_address_in_block (frame));
51abb421 2532 return find_pc_line (pc, notcurrent);
1058bca7
AC
2533}
2534
c193f6ac
AC
2535/* Per "frame.h", return the ``address'' of the frame. Code should
2536 really be using get_frame_id(). */
2537CORE_ADDR
2538get_frame_base (struct frame_info *fi)
2539{
d0a55772 2540 return get_frame_id (fi).stack_addr;
c193f6ac
AC
2541}
2542
da62e633
AC
2543/* High-level offsets into the frame. Used by the debug info. */
2544
2545CORE_ADDR
2546get_frame_base_address (struct frame_info *fi)
2547{
7df05f2b 2548 if (get_frame_type (fi) != NORMAL_FRAME)
da62e633
AC
2549 return 0;
2550 if (fi->base == NULL)
86c31399 2551 fi->base = frame_base_find_by_frame (fi);
da62e633
AC
2552 /* Sneaky: If the low-level unwind and high-level base code share a
2553 common unwinder, let them share the prologue cache. */
2554 if (fi->base->unwind == fi->unwind)
669fac23
DJ
2555 return fi->base->this_base (fi, &fi->prologue_cache);
2556 return fi->base->this_base (fi, &fi->base_cache);
da62e633
AC
2557}
2558
2559CORE_ADDR
2560get_frame_locals_address (struct frame_info *fi)
2561{
7df05f2b 2562 if (get_frame_type (fi) != NORMAL_FRAME)
da62e633
AC
2563 return 0;
2564 /* If there isn't a frame address method, find it. */
2565 if (fi->base == NULL)
86c31399 2566 fi->base = frame_base_find_by_frame (fi);
da62e633
AC
2567 /* Sneaky: If the low-level unwind and high-level base code share a
2568 common unwinder, let them share the prologue cache. */
2569 if (fi->base->unwind == fi->unwind)
669fac23
DJ
2570 return fi->base->this_locals (fi, &fi->prologue_cache);
2571 return fi->base->this_locals (fi, &fi->base_cache);
da62e633
AC
2572}
2573
2574CORE_ADDR
2575get_frame_args_address (struct frame_info *fi)
2576{
7df05f2b 2577 if (get_frame_type (fi) != NORMAL_FRAME)
da62e633
AC
2578 return 0;
2579 /* If there isn't a frame address method, find it. */
2580 if (fi->base == NULL)
86c31399 2581 fi->base = frame_base_find_by_frame (fi);
da62e633
AC
2582 /* Sneaky: If the low-level unwind and high-level base code share a
2583 common unwinder, let them share the prologue cache. */
2584 if (fi->base->unwind == fi->unwind)
669fac23
DJ
2585 return fi->base->this_args (fi, &fi->prologue_cache);
2586 return fi->base->this_args (fi, &fi->base_cache);
da62e633
AC
2587}
2588
e7802207
TT
2589/* Return true if the frame unwinder for frame FI is UNWINDER; false
2590 otherwise. */
2591
2592int
2593frame_unwinder_is (struct frame_info *fi, const struct frame_unwind *unwinder)
2594{
2595 if (fi->unwind == NULL)
9f9a8002 2596 frame_unwind_find_by_frame (fi, &fi->prologue_cache);
e7802207
TT
2597 return fi->unwind == unwinder;
2598}
2599
85cf597a
AC
2600/* Level of the selected frame: 0 for innermost, 1 for its caller, ...
2601 or -1 for a NULL frame. */
2602
2603int
2604frame_relative_level (struct frame_info *fi)
2605{
2606 if (fi == NULL)
2607 return -1;
2608 else
2609 return fi->level;
2610}
2611
5a203e44
AC
2612enum frame_type
2613get_frame_type (struct frame_info *frame)
2614{
c1bf6f65
AC
2615 if (frame->unwind == NULL)
2616 /* Initialize the frame's unwinder because that's what
2617 provides the frame's type. */
9f9a8002 2618 frame_unwind_find_by_frame (frame, &frame->prologue_cache);
c1bf6f65 2619 return frame->unwind->type;
5a203e44
AC
2620}
2621
6c95b8df
PA
2622struct program_space *
2623get_frame_program_space (struct frame_info *frame)
2624{
2625 return frame->pspace;
2626}
2627
2628struct program_space *
2629frame_unwind_program_space (struct frame_info *this_frame)
2630{
2631 gdb_assert (this_frame);
2632
2633 /* This is really a placeholder to keep the API consistent --- we
2634 assume for now that we don't have frame chains crossing
2635 spaces. */
2636 return this_frame->pspace;
2637}
2638
8b86c959 2639const address_space *
6c95b8df
PA
2640get_frame_address_space (struct frame_info *frame)
2641{
2642 return frame->aspace;
2643}
2644
ae1e7417
AC
2645/* Memory access methods. */
2646
2647void
10c42a71
AC
2648get_frame_memory (struct frame_info *this_frame, CORE_ADDR addr,
2649 gdb_byte *buf, int len)
ae1e7417
AC
2650{
2651 read_memory (addr, buf, len);
2652}
2653
2654LONGEST
2655get_frame_memory_signed (struct frame_info *this_frame, CORE_ADDR addr,
2656 int len)
2657{
e17a4113
UW
2658 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2659 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1c4d3f96 2660
e17a4113 2661 return read_memory_integer (addr, len, byte_order);
ae1e7417
AC
2662}
2663
2664ULONGEST
2665get_frame_memory_unsigned (struct frame_info *this_frame, CORE_ADDR addr,
2666 int len)
2667{
e17a4113
UW
2668 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2669 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1c4d3f96 2670
e17a4113 2671 return read_memory_unsigned_integer (addr, len, byte_order);
ae1e7417
AC
2672}
2673
304396fb
AC
2674int
2675safe_frame_unwind_memory (struct frame_info *this_frame,
10c42a71 2676 CORE_ADDR addr, gdb_byte *buf, int len)
304396fb 2677{
8defab1a
DJ
2678 /* NOTE: target_read_memory returns zero on success! */
2679 return !target_read_memory (addr, buf, len);
304396fb
AC
2680}
2681
36f15f55 2682/* Architecture methods. */
ae1e7417
AC
2683
2684struct gdbarch *
2685get_frame_arch (struct frame_info *this_frame)
2686{
36f15f55
UW
2687 return frame_unwind_arch (this_frame->next);
2688}
2689
2690struct gdbarch *
2691frame_unwind_arch (struct frame_info *next_frame)
2692{
2693 if (!next_frame->prev_arch.p)
2694 {
2695 struct gdbarch *arch;
0701b271 2696
36f15f55 2697 if (next_frame->unwind == NULL)
9f9a8002 2698 frame_unwind_find_by_frame (next_frame, &next_frame->prologue_cache);
36f15f55
UW
2699
2700 if (next_frame->unwind->prev_arch != NULL)
2701 arch = next_frame->unwind->prev_arch (next_frame,
2702 &next_frame->prologue_cache);
2703 else
2704 arch = get_frame_arch (next_frame);
2705
2706 next_frame->prev_arch.arch = arch;
2707 next_frame->prev_arch.p = 1;
2708 if (frame_debug)
2709 fprintf_unfiltered (gdb_stdlog,
2710 "{ frame_unwind_arch (next_frame=%d) -> %s }\n",
2711 next_frame->level,
2712 gdbarch_bfd_arch_info (arch)->printable_name);
2713 }
2714
2715 return next_frame->prev_arch.arch;
2716}
2717
2718struct gdbarch *
2719frame_unwind_caller_arch (struct frame_info *next_frame)
2720{
33b4777c
MM
2721 next_frame = skip_artificial_frames (next_frame);
2722
2723 /* We must have a non-artificial frame. The caller is supposed to check
2724 the result of frame_unwind_caller_id (), which returns NULL_FRAME_ID
2725 in this case. */
2726 gdb_assert (next_frame != NULL);
2727
2728 return frame_unwind_arch (next_frame);
ae1e7417
AC
2729}
2730
06096720
AB
2731/* Gets the language of FRAME. */
2732
2733enum language
2734get_frame_language (struct frame_info *frame)
2735{
2736 CORE_ADDR pc = 0;
2737 int pc_p = 0;
2738
2739 gdb_assert (frame!= NULL);
2740
2741 /* We determine the current frame language by looking up its
2742 associated symtab. To retrieve this symtab, we use the frame
2743 PC. However we cannot use the frame PC as is, because it
2744 usually points to the instruction following the "call", which
2745 is sometimes the first instruction of another function. So
2746 we rely on get_frame_address_in_block(), it provides us with
2747 a PC that is guaranteed to be inside the frame's code
2748 block. */
2749
a70b8144 2750 try
06096720
AB
2751 {
2752 pc = get_frame_address_in_block (frame);
2753 pc_p = 1;
2754 }
230d2906 2755 catch (const gdb_exception_error &ex)
06096720
AB
2756 {
2757 if (ex.error != NOT_AVAILABLE_ERROR)
eedc3f4f 2758 throw;
06096720 2759 }
06096720
AB
2760
2761 if (pc_p)
2762 {
2763 struct compunit_symtab *cust = find_pc_compunit_symtab (pc);
2764
2765 if (cust != NULL)
2766 return compunit_language (cust);
2767 }
2768
2769 return language_unknown;
2770}
2771
a9e5fdc2
AC
2772/* Stack pointer methods. */
2773
2774CORE_ADDR
2775get_frame_sp (struct frame_info *this_frame)
2776{
d56907c1 2777 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1c4d3f96 2778
8bcb5208
AB
2779 /* NOTE drow/2008-06-28: gdbarch_unwind_sp could be converted to
2780 operate on THIS_FRAME now. */
2781 return gdbarch_unwind_sp (gdbarch, this_frame->next);
a9e5fdc2
AC
2782}
2783
55feb689
DJ
2784/* Return the reason why we can't unwind past FRAME. */
2785
2786enum unwind_stop_reason
2787get_frame_unwind_stop_reason (struct frame_info *frame)
2788{
824344ca 2789 /* Fill-in STOP_REASON. */
51d48146 2790 get_prev_frame_always (frame);
824344ca 2791 gdb_assert (frame->prev_p);
55feb689 2792
55feb689
DJ
2793 return frame->stop_reason;
2794}
2795
2796/* Return a string explaining REASON. */
2797
2798const char *
70e38b8e 2799unwind_stop_reason_to_string (enum unwind_stop_reason reason)
55feb689
DJ
2800{
2801 switch (reason)
2802 {
2231f1fb
KP
2803#define SET(name, description) \
2804 case name: return _(description);
2805#include "unwind_stop_reasons.def"
2806#undef SET
55feb689 2807
55feb689
DJ
2808 default:
2809 internal_error (__FILE__, __LINE__,
2810 "Invalid frame stop reason");
2811 }
2812}
2813
53e8a631
AB
2814const char *
2815frame_stop_reason_string (struct frame_info *fi)
2816{
2817 gdb_assert (fi->prev_p);
2818 gdb_assert (fi->prev == NULL);
2819
2820 /* Return the specific string if we have one. */
2821 if (fi->stop_string != NULL)
2822 return fi->stop_string;
2823
2824 /* Return the generic string if we have nothing better. */
2825 return unwind_stop_reason_to_string (fi->stop_reason);
2826}
2827
a7300869
PA
2828/* Return the enum symbol name of REASON as a string, to use in debug
2829 output. */
2830
2831static const char *
2832frame_stop_reason_symbol_string (enum unwind_stop_reason reason)
2833{
2834 switch (reason)
2835 {
2836#define SET(name, description) \
2837 case name: return #name;
2838#include "unwind_stop_reasons.def"
2839#undef SET
2840
2841 default:
2842 internal_error (__FILE__, __LINE__,
2843 "Invalid frame stop reason");
2844 }
2845}
2846
669fac23
DJ
2847/* Clean up after a failed (wrong unwinder) attempt to unwind past
2848 FRAME. */
2849
30a9c02f
TT
2850void
2851frame_cleanup_after_sniffer (struct frame_info *frame)
669fac23 2852{
669fac23
DJ
2853 /* The sniffer should not allocate a prologue cache if it did not
2854 match this frame. */
2855 gdb_assert (frame->prologue_cache == NULL);
2856
2857 /* No sniffer should extend the frame chain; sniff based on what is
2858 already certain. */
2859 gdb_assert (!frame->prev_p);
2860
2861 /* The sniffer should not check the frame's ID; that's circular. */
2862 gdb_assert (!frame->this_id.p);
2863
2864 /* Clear cached fields dependent on the unwinder.
2865
2866 The previous PC is independent of the unwinder, but the previous
ad1193e7 2867 function is not (see get_frame_address_in_block). */
669fac23
DJ
2868 frame->prev_func.p = 0;
2869 frame->prev_func.addr = 0;
2870
2871 /* Discard the unwinder last, so that we can easily find it if an assertion
2872 in this function triggers. */
2873 frame->unwind = NULL;
2874}
2875
2876/* Set FRAME's unwinder temporarily, so that we can call a sniffer.
30a9c02f
TT
2877 If sniffing fails, the caller should be sure to call
2878 frame_cleanup_after_sniffer. */
669fac23 2879
30a9c02f 2880void
669fac23
DJ
2881frame_prepare_for_sniffer (struct frame_info *frame,
2882 const struct frame_unwind *unwind)
2883{
2884 gdb_assert (frame->unwind == NULL);
2885 frame->unwind = unwind;
669fac23
DJ
2886}
2887
25d29d70
AC
2888static struct cmd_list_element *set_backtrace_cmdlist;
2889static struct cmd_list_element *show_backtrace_cmdlist;
2890
2891static void
981a3fb3 2892set_backtrace_cmd (const char *args, int from_tty)
25d29d70 2893{
635c7e8a
TT
2894 help_list (set_backtrace_cmdlist, "set backtrace ", all_commands,
2895 gdb_stdout);
25d29d70
AC
2896}
2897
2898static void
981a3fb3 2899show_backtrace_cmd (const char *args, int from_tty)
25d29d70
AC
2900{
2901 cmd_show_list (show_backtrace_cmdlist, from_tty, "");
2902}
2903
d4c16835
PA
2904/* Definition of the "set backtrace" settings that are exposed as
2905 "backtrace" command options. */
2906
2907using boolean_option_def
2908 = gdb::option::boolean_option_def<set_backtrace_options>;
2909using uinteger_option_def
2910 = gdb::option::uinteger_option_def<set_backtrace_options>;
2911
2912const gdb::option::option_def set_backtrace_option_defs[] = {
2913
2914 boolean_option_def {
2915 "past-main",
2916 [] (set_backtrace_options *opt) { return &opt->backtrace_past_main; },
2917 show_backtrace_past_main, /* show_cmd_cb */
2918 N_("Set whether backtraces should continue past \"main\"."),
2919 N_("Show whether backtraces should continue past \"main\"."),
2920 N_("Normally the caller of \"main\" is not of interest, so GDB will terminate\n\
2921the backtrace at \"main\". Set this if you need to see the rest\n\
2922of the stack trace."),
2923 },
2924
2925 boolean_option_def {
2926 "past-entry",
2927 [] (set_backtrace_options *opt) { return &opt->backtrace_past_entry; },
2928 show_backtrace_past_entry, /* show_cmd_cb */
2929 N_("Set whether backtraces should continue past the entry point of a program."),
2930 N_("Show whether backtraces should continue past the entry point of a program."),
2931 N_("Normally there are no callers beyond the entry point of a program, so GDB\n\
2932will terminate the backtrace there. Set this if you need to see\n\
2933the rest of the stack trace."),
2934 },
2935};
2936
4c1e7e9d
AC
2937void
2938_initialize_frame (void)
2939{
2940 obstack_init (&frame_cache_obstack);
eb4f72c5 2941
3de661e6
PM
2942 frame_stash_create ();
2943
76727919 2944 gdb::observers::target_changed.attach (frame_observer_target_changed);
f4c5303c 2945
1bedd215 2946 add_prefix_cmd ("backtrace", class_maintenance, set_backtrace_cmd, _("\
25d29d70 2947Set backtrace specific variables.\n\
1bedd215 2948Configure backtrace variables such as the backtrace limit"),
25d29d70
AC
2949 &set_backtrace_cmdlist, "set backtrace ",
2950 0/*allow-unknown*/, &setlist);
1bedd215 2951 add_prefix_cmd ("backtrace", class_maintenance, show_backtrace_cmd, _("\
25d29d70 2952Show backtrace specific variables\n\
1bedd215 2953Show backtrace variables such as the backtrace limit"),
25d29d70
AC
2954 &show_backtrace_cmdlist, "show backtrace ",
2955 0/*allow-unknown*/, &showlist);
2956
883b9c6c 2957 add_setshow_uinteger_cmd ("limit", class_obscure,
d4c16835 2958 &user_set_backtrace_options.backtrace_limit, _("\
7915a72c
AC
2959Set an upper bound on the number of backtrace levels."), _("\
2960Show the upper bound on the number of backtrace levels."), _("\
fec74868 2961No more than the specified number of frames can be displayed or examined.\n\
f81d1120 2962Literal \"unlimited\" or zero means no limit."),
883b9c6c
YQ
2963 NULL,
2964 show_backtrace_limit,
2965 &set_backtrace_cmdlist,
2966 &show_backtrace_cmdlist);
ac2bd0a9 2967
d4c16835
PA
2968 gdb::option::add_setshow_cmds_for_options
2969 (class_stack, &user_set_backtrace_options,
2970 set_backtrace_option_defs, &set_backtrace_cmdlist, &show_backtrace_cmdlist);
2971
0963b4bd 2972 /* Debug this files internals. */
ccce17b0 2973 add_setshow_zuinteger_cmd ("frame", class_maintenance, &frame_debug, _("\
85c07804
AC
2974Set frame debugging."), _("\
2975Show frame debugging."), _("\
2976When non-zero, frame specific internal debugging is enabled."),
ccce17b0
YQ
2977 NULL,
2978 show_frame_debug,
2979 &setdebuglist, &showdebuglist);
4c1e7e9d 2980}
This page took 1.779427 seconds and 4 git commands to generate.