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