* gdbtypes.c (make_pointer_type, make_reference_type,
[deliverable/binutils-gdb.git] / gdb / frame.c
1 /* Cache and manage frames for GDB, the GNU debugger.
2
3 Copyright (C) 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, 2001,
4 2002, 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include "defs.h"
22 #include "frame.h"
23 #include "target.h"
24 #include "value.h"
25 #include "inferior.h" /* for inferior_ptid */
26 #include "regcache.h"
27 #include "gdb_assert.h"
28 #include "gdb_string.h"
29 #include "user-regs.h"
30 #include "gdb_obstack.h"
31 #include "dummy-frame.h"
32 #include "sentinel-frame.h"
33 #include "gdbcore.h"
34 #include "annotate.h"
35 #include "language.h"
36 #include "frame-unwind.h"
37 #include "frame-base.h"
38 #include "command.h"
39 #include "gdbcmd.h"
40 #include "observer.h"
41 #include "objfiles.h"
42 #include "exceptions.h"
43 #include "gdbthread.h"
44 #include "block.h"
45 #include "inline-frame.h"
46
47 static struct frame_info *get_prev_frame_1 (struct frame_info *this_frame);
48 static struct frame_info *get_prev_frame_raw (struct frame_info *this_frame);
49
50 /* We keep a cache of stack frames, each of which is a "struct
51 frame_info". The innermost one gets allocated (in
52 wait_for_inferior) each time the inferior stops; current_frame
53 points to it. Additional frames get allocated (in get_prev_frame)
54 as needed, and are chained through the next and prev fields. Any
55 time that the frame cache becomes invalid (most notably when we
56 execute something, but also if we change how we interpret the
57 frames (e.g. "set heuristic-fence-post" in mips-tdep.c, or anything
58 which reads new symbols)), we should call reinit_frame_cache. */
59
60 struct frame_info
61 {
62 /* Level of this frame. The inner-most (youngest) frame is at level
63 0. As you move towards the outer-most (oldest) frame, the level
64 increases. This is a cached value. It could just as easily be
65 computed by counting back from the selected frame to the inner
66 most frame. */
67 /* NOTE: cagney/2002-04-05: Perhaps a level of ``-1'' should be
68 reserved to indicate a bogus frame - one that has been created
69 just to keep GDB happy (GDB always needs a frame). For the
70 moment leave this as speculation. */
71 int level;
72
73 /* The frame's low-level unwinder and corresponding cache. The
74 low-level unwinder is responsible for unwinding register values
75 for the previous frame. The low-level unwind methods are
76 selected based on the presence, or otherwise, of register unwind
77 information such as CFI. */
78 void *prologue_cache;
79 const struct frame_unwind *unwind;
80
81 /* Cached copy of the previous frame's resume address. */
82 struct {
83 int p;
84 CORE_ADDR value;
85 } prev_pc;
86
87 /* Cached copy of the previous frame's function address. */
88 struct
89 {
90 CORE_ADDR addr;
91 int p;
92 } prev_func;
93
94 /* This frame's ID. */
95 struct
96 {
97 int p;
98 struct frame_id value;
99 } this_id;
100
101 /* The frame's high-level base methods, and corresponding cache.
102 The high level base methods are selected based on the frame's
103 debug info. */
104 const struct frame_base *base;
105 void *base_cache;
106
107 /* Pointers to the next (down, inner, younger) and previous (up,
108 outer, older) frame_info's in the frame cache. */
109 struct frame_info *next; /* down, inner, younger */
110 int prev_p;
111 struct frame_info *prev; /* up, outer, older */
112
113 /* The reason why we could not set PREV, or UNWIND_NO_REASON if we
114 could. Only valid when PREV_P is set. */
115 enum unwind_stop_reason stop_reason;
116 };
117
118 /* Flag to control debugging. */
119
120 int frame_debug;
121 static void
122 show_frame_debug (struct ui_file *file, int from_tty,
123 struct cmd_list_element *c, const char *value)
124 {
125 fprintf_filtered (file, _("Frame debugging is %s.\n"), value);
126 }
127
128 /* Flag to indicate whether backtraces should stop at main et.al. */
129
130 static int backtrace_past_main;
131 static void
132 show_backtrace_past_main (struct ui_file *file, int from_tty,
133 struct cmd_list_element *c, const char *value)
134 {
135 fprintf_filtered (file, _("\
136 Whether backtraces should continue past \"main\" is %s.\n"),
137 value);
138 }
139
140 static int backtrace_past_entry;
141 static void
142 show_backtrace_past_entry (struct ui_file *file, int from_tty,
143 struct cmd_list_element *c, const char *value)
144 {
145 fprintf_filtered (file, _("\
146 Whether backtraces should continue past the entry point of a program is %s.\n"),
147 value);
148 }
149
150 static int backtrace_limit = INT_MAX;
151 static void
152 show_backtrace_limit (struct ui_file *file, int from_tty,
153 struct cmd_list_element *c, const char *value)
154 {
155 fprintf_filtered (file, _("\
156 An upper bound on the number of backtrace levels is %s.\n"),
157 value);
158 }
159
160
161 static void
162 fprint_field (struct ui_file *file, const char *name, int p, CORE_ADDR addr)
163 {
164 if (p)
165 fprintf_unfiltered (file, "%s=0x%s", name, paddr_nz (addr));
166 else
167 fprintf_unfiltered (file, "!%s", name);
168 }
169
170 void
171 fprint_frame_id (struct ui_file *file, struct frame_id id)
172 {
173 fprintf_unfiltered (file, "{");
174 fprint_field (file, "stack", id.stack_addr_p, id.stack_addr);
175 fprintf_unfiltered (file, ",");
176 fprint_field (file, "code", id.code_addr_p, id.code_addr);
177 fprintf_unfiltered (file, ",");
178 fprint_field (file, "special", id.special_addr_p, id.special_addr);
179 if (id.inline_depth)
180 fprintf_unfiltered (file, ",inlined=%d", id.inline_depth);
181 fprintf_unfiltered (file, "}");
182 }
183
184 static void
185 fprint_frame_type (struct ui_file *file, enum frame_type type)
186 {
187 switch (type)
188 {
189 case NORMAL_FRAME:
190 fprintf_unfiltered (file, "NORMAL_FRAME");
191 return;
192 case DUMMY_FRAME:
193 fprintf_unfiltered (file, "DUMMY_FRAME");
194 return;
195 case INLINE_FRAME:
196 fprintf_unfiltered (file, "INLINE_FRAME");
197 return;
198 case SENTINEL_FRAME:
199 fprintf_unfiltered (file, "SENTINEL_FRAME");
200 return;
201 case SIGTRAMP_FRAME:
202 fprintf_unfiltered (file, "SIGTRAMP_FRAME");
203 return;
204 default:
205 fprintf_unfiltered (file, "<unknown type>");
206 return;
207 };
208 }
209
210 static void
211 fprint_frame (struct ui_file *file, struct frame_info *fi)
212 {
213 if (fi == NULL)
214 {
215 fprintf_unfiltered (file, "<NULL frame>");
216 return;
217 }
218 fprintf_unfiltered (file, "{");
219 fprintf_unfiltered (file, "level=%d", fi->level);
220 fprintf_unfiltered (file, ",");
221 fprintf_unfiltered (file, "type=");
222 if (fi->unwind != NULL)
223 fprint_frame_type (file, fi->unwind->type);
224 else
225 fprintf_unfiltered (file, "<unknown>");
226 fprintf_unfiltered (file, ",");
227 fprintf_unfiltered (file, "unwind=");
228 if (fi->unwind != NULL)
229 gdb_print_host_address (fi->unwind, file);
230 else
231 fprintf_unfiltered (file, "<unknown>");
232 fprintf_unfiltered (file, ",");
233 fprintf_unfiltered (file, "pc=");
234 if (fi->next != NULL && fi->next->prev_pc.p)
235 fprintf_unfiltered (file, "0x%s", paddr_nz (fi->next->prev_pc.value));
236 else
237 fprintf_unfiltered (file, "<unknown>");
238 fprintf_unfiltered (file, ",");
239 fprintf_unfiltered (file, "id=");
240 if (fi->this_id.p)
241 fprint_frame_id (file, fi->this_id.value);
242 else
243 fprintf_unfiltered (file, "<unknown>");
244 fprintf_unfiltered (file, ",");
245 fprintf_unfiltered (file, "func=");
246 if (fi->next != NULL && fi->next->prev_func.p)
247 fprintf_unfiltered (file, "0x%s", paddr_nz (fi->next->prev_func.addr));
248 else
249 fprintf_unfiltered (file, "<unknown>");
250 fprintf_unfiltered (file, "}");
251 }
252
253 /* Given FRAME, return the enclosing normal frame for inlined
254 function frames. Otherwise return the original frame. */
255
256 static struct frame_info *
257 skip_inlined_frames (struct frame_info *frame)
258 {
259 while (get_frame_type (frame) == INLINE_FRAME)
260 frame = get_prev_frame (frame);
261
262 return frame;
263 }
264
265 /* Return a frame uniq ID that can be used to, later, re-find the
266 frame. */
267
268 struct frame_id
269 get_frame_id (struct frame_info *fi)
270 {
271 if (fi == NULL)
272 {
273 return null_frame_id;
274 }
275 if (!fi->this_id.p)
276 {
277 if (frame_debug)
278 fprintf_unfiltered (gdb_stdlog, "{ get_frame_id (fi=%d) ",
279 fi->level);
280 /* Find the unwinder. */
281 if (fi->unwind == NULL)
282 fi->unwind = frame_unwind_find_by_frame (fi, &fi->prologue_cache);
283 /* Find THIS frame's ID. */
284 fi->unwind->this_id (fi, &fi->prologue_cache, &fi->this_id.value);
285 fi->this_id.p = 1;
286 if (frame_debug)
287 {
288 fprintf_unfiltered (gdb_stdlog, "-> ");
289 fprint_frame_id (gdb_stdlog, fi->this_id.value);
290 fprintf_unfiltered (gdb_stdlog, " }\n");
291 }
292 }
293 return fi->this_id.value;
294 }
295
296 struct frame_id
297 get_stack_frame_id (struct frame_info *next_frame)
298 {
299 return get_frame_id (skip_inlined_frames (next_frame));
300 }
301
302 struct frame_id
303 frame_unwind_caller_id (struct frame_info *next_frame)
304 {
305 struct frame_info *this_frame;
306
307 /* Use get_prev_frame_1, and not get_prev_frame. The latter will truncate
308 the frame chain, leading to this function unintentionally
309 returning a null_frame_id (e.g., when a caller requests the frame
310 ID of "main()"s caller. */
311
312 next_frame = skip_inlined_frames (next_frame);
313 this_frame = get_prev_frame_1 (next_frame);
314 if (this_frame)
315 return get_frame_id (skip_inlined_frames (this_frame));
316 else
317 return null_frame_id;
318 }
319
320 const struct frame_id null_frame_id; /* All zeros. */
321
322 struct frame_id
323 frame_id_build_special (CORE_ADDR stack_addr, CORE_ADDR code_addr,
324 CORE_ADDR special_addr)
325 {
326 struct frame_id id = null_frame_id;
327 id.stack_addr = stack_addr;
328 id.stack_addr_p = 1;
329 id.code_addr = code_addr;
330 id.code_addr_p = 1;
331 id.special_addr = special_addr;
332 id.special_addr_p = 1;
333 return id;
334 }
335
336 struct frame_id
337 frame_id_build (CORE_ADDR stack_addr, CORE_ADDR code_addr)
338 {
339 struct frame_id id = null_frame_id;
340 id.stack_addr = stack_addr;
341 id.stack_addr_p = 1;
342 id.code_addr = code_addr;
343 id.code_addr_p = 1;
344 return id;
345 }
346
347 struct frame_id
348 frame_id_build_wild (CORE_ADDR stack_addr)
349 {
350 struct frame_id id = null_frame_id;
351 id.stack_addr = stack_addr;
352 id.stack_addr_p = 1;
353 return id;
354 }
355
356 int
357 frame_id_p (struct frame_id l)
358 {
359 int p;
360 /* The frame is valid iff it has a valid stack address. */
361 p = l.stack_addr_p;
362 if (frame_debug)
363 {
364 fprintf_unfiltered (gdb_stdlog, "{ frame_id_p (l=");
365 fprint_frame_id (gdb_stdlog, l);
366 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", p);
367 }
368 return p;
369 }
370
371 int
372 frame_id_inlined_p (struct frame_id l)
373 {
374 if (!frame_id_p (l))
375 return 0;
376
377 return (l.inline_depth != 0);
378 }
379
380 int
381 frame_id_eq (struct frame_id l, struct frame_id r)
382 {
383 int eq;
384 if (!l.stack_addr_p || !r.stack_addr_p)
385 /* Like a NaN, if either ID is invalid, the result is false.
386 Note that a frame ID is invalid iff it is the null frame ID. */
387 eq = 0;
388 else if (l.stack_addr != r.stack_addr)
389 /* If .stack addresses are different, the frames are different. */
390 eq = 0;
391 else if (l.code_addr_p && r.code_addr_p && l.code_addr != r.code_addr)
392 /* An invalid code addr is a wild card. If .code addresses are
393 different, the frames are different. */
394 eq = 0;
395 else if (l.special_addr_p && r.special_addr_p
396 && l.special_addr != r.special_addr)
397 /* An invalid special addr is a wild card (or unused). Otherwise
398 if special addresses are different, the frames are different. */
399 eq = 0;
400 else if (l.inline_depth != r.inline_depth)
401 /* If inline depths are different, the frames must be different. */
402 eq = 0;
403 else
404 /* Frames are equal. */
405 eq = 1;
406
407 if (frame_debug)
408 {
409 fprintf_unfiltered (gdb_stdlog, "{ frame_id_eq (l=");
410 fprint_frame_id (gdb_stdlog, l);
411 fprintf_unfiltered (gdb_stdlog, ",r=");
412 fprint_frame_id (gdb_stdlog, r);
413 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", eq);
414 }
415 return eq;
416 }
417
418 /* Safety net to check whether frame ID L should be inner to
419 frame ID R, according to their stack addresses.
420
421 This method cannot be used to compare arbitrary frames, as the
422 ranges of valid stack addresses may be discontiguous (e.g. due
423 to sigaltstack).
424
425 However, it can be used as safety net to discover invalid frame
426 IDs in certain circumstances. Assuming that NEXT is the immediate
427 inner frame to THIS and that NEXT and THIS are both NORMAL frames:
428
429 * The stack address of NEXT must be inner-than-or-equal to the stack
430 address of THIS.
431
432 Therefore, if frame_id_inner (THIS, NEXT) holds, some unwind
433 error has occurred.
434
435 * If NEXT and THIS have different stack addresses, no other frame
436 in the frame chain may have a stack address in between.
437
438 Therefore, if frame_id_inner (TEST, THIS) holds, but
439 frame_id_inner (TEST, NEXT) does not hold, TEST cannot refer
440 to a valid frame in the frame chain.
441
442 The sanity checks above cannot be performed when a SIGTRAMP frame
443 is involved, because signal handlers might be executed on a different
444 stack than the stack used by the routine that caused the signal
445 to be raised. This can happen for instance when a thread exceeds
446 its maximum stack size. In this case, certain compilers implement
447 a stack overflow strategy that cause the handler to be run on a
448 different stack. */
449
450 static int
451 frame_id_inner (struct gdbarch *gdbarch, struct frame_id l, struct frame_id r)
452 {
453 int inner;
454 if (!l.stack_addr_p || !r.stack_addr_p)
455 /* Like NaN, any operation involving an invalid ID always fails. */
456 inner = 0;
457 else if (l.inline_depth > r.inline_depth
458 && l.stack_addr == r.stack_addr
459 && l.code_addr_p == r.code_addr_p
460 && l.special_addr_p == r.special_addr_p
461 && l.special_addr == r.special_addr)
462 {
463 /* Same function, different inlined functions. */
464 struct block *lb, *rb;
465
466 gdb_assert (l.code_addr_p && r.code_addr_p);
467
468 lb = block_for_pc (l.code_addr);
469 rb = block_for_pc (r.code_addr);
470
471 if (lb == NULL || rb == NULL)
472 /* Something's gone wrong. */
473 inner = 0;
474 else
475 /* This will return true if LB and RB are the same block, or
476 if the block with the smaller depth lexically encloses the
477 block with the greater depth. */
478 inner = contained_in (lb, rb);
479 }
480 else
481 /* Only return non-zero when strictly inner than. Note that, per
482 comment in "frame.h", there is some fuzz here. Frameless
483 functions are not strictly inner than (same .stack but
484 different .code and/or .special address). */
485 inner = gdbarch_inner_than (gdbarch, l.stack_addr, r.stack_addr);
486 if (frame_debug)
487 {
488 fprintf_unfiltered (gdb_stdlog, "{ frame_id_inner (l=");
489 fprint_frame_id (gdb_stdlog, l);
490 fprintf_unfiltered (gdb_stdlog, ",r=");
491 fprint_frame_id (gdb_stdlog, r);
492 fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", inner);
493 }
494 return inner;
495 }
496
497 struct frame_info *
498 frame_find_by_id (struct frame_id id)
499 {
500 struct frame_info *frame, *prev_frame;
501
502 /* ZERO denotes the null frame, let the caller decide what to do
503 about it. Should it instead return get_current_frame()? */
504 if (!frame_id_p (id))
505 return NULL;
506
507 for (frame = get_current_frame (); ; frame = prev_frame)
508 {
509 struct frame_id this = get_frame_id (frame);
510 if (frame_id_eq (id, this))
511 /* An exact match. */
512 return frame;
513
514 prev_frame = get_prev_frame (frame);
515 if (!prev_frame)
516 return NULL;
517
518 /* As a safety net to avoid unnecessary backtracing while trying
519 to find an invalid ID, we check for a common situation where
520 we can detect from comparing stack addresses that no other
521 frame in the current frame chain can have this ID. See the
522 comment at frame_id_inner for details. */
523 if (get_frame_type (frame) == NORMAL_FRAME
524 && !frame_id_inner (get_frame_arch (frame), id, this)
525 && frame_id_inner (get_frame_arch (prev_frame), id,
526 get_frame_id (prev_frame)))
527 return NULL;
528 }
529 return NULL;
530 }
531
532 static CORE_ADDR
533 frame_unwind_pc (struct frame_info *this_frame)
534 {
535 if (!this_frame->prev_pc.p)
536 {
537 CORE_ADDR pc;
538 if (gdbarch_unwind_pc_p (get_frame_arch (this_frame)))
539 {
540 /* The right way. The `pure' way. The one true way. This
541 method depends solely on the register-unwind code to
542 determine the value of registers in THIS frame, and hence
543 the value of this frame's PC (resume address). A typical
544 implementation is no more than:
545
546 frame_unwind_register (this_frame, ISA_PC_REGNUM, buf);
547 return extract_unsigned_integer (buf, size of ISA_PC_REGNUM);
548
549 Note: this method is very heavily dependent on a correct
550 register-unwind implementation, it pays to fix that
551 method first; this method is frame type agnostic, since
552 it only deals with register values, it works with any
553 frame. This is all in stark contrast to the old
554 FRAME_SAVED_PC which would try to directly handle all the
555 different ways that a PC could be unwound. */
556 pc = gdbarch_unwind_pc (get_frame_arch (this_frame), this_frame);
557 }
558 else
559 internal_error (__FILE__, __LINE__, _("No unwind_pc method"));
560 this_frame->prev_pc.value = pc;
561 this_frame->prev_pc.p = 1;
562 if (frame_debug)
563 fprintf_unfiltered (gdb_stdlog,
564 "{ frame_unwind_caller_pc (this_frame=%d) -> 0x%s }\n",
565 this_frame->level,
566 paddr_nz (this_frame->prev_pc.value));
567 }
568 return this_frame->prev_pc.value;
569 }
570
571 CORE_ADDR
572 frame_unwind_caller_pc (struct frame_info *this_frame)
573 {
574 return frame_unwind_pc (skip_inlined_frames (this_frame));
575 }
576
577 CORE_ADDR
578 get_frame_func (struct frame_info *this_frame)
579 {
580 struct frame_info *next_frame = this_frame->next;
581
582 if (!next_frame->prev_func.p)
583 {
584 /* Make certain that this, and not the adjacent, function is
585 found. */
586 CORE_ADDR addr_in_block = get_frame_address_in_block (this_frame);
587 next_frame->prev_func.p = 1;
588 next_frame->prev_func.addr = get_pc_function_start (addr_in_block);
589 if (frame_debug)
590 fprintf_unfiltered (gdb_stdlog,
591 "{ get_frame_func (this_frame=%d) -> 0x%s }\n",
592 this_frame->level,
593 paddr_nz (next_frame->prev_func.addr));
594 }
595 return next_frame->prev_func.addr;
596 }
597
598 static int
599 do_frame_register_read (void *src, int regnum, gdb_byte *buf)
600 {
601 return frame_register_read (src, regnum, buf);
602 }
603
604 struct regcache *
605 frame_save_as_regcache (struct frame_info *this_frame)
606 {
607 struct regcache *regcache = regcache_xmalloc (get_frame_arch (this_frame));
608 struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
609 regcache_save (regcache, do_frame_register_read, this_frame);
610 discard_cleanups (cleanups);
611 return regcache;
612 }
613
614 void
615 frame_pop (struct frame_info *this_frame)
616 {
617 struct frame_info *prev_frame;
618 struct regcache *scratch;
619 struct cleanup *cleanups;
620
621 if (get_frame_type (this_frame) == DUMMY_FRAME)
622 {
623 /* Popping a dummy frame involves restoring more than just registers.
624 dummy_frame_pop does all the work. */
625 dummy_frame_pop (get_frame_id (this_frame));
626 return;
627 }
628
629 /* Ensure that we have a frame to pop to. */
630 prev_frame = get_prev_frame_1 (this_frame);
631
632 if (!prev_frame)
633 error (_("Cannot pop the initial frame."));
634
635 /* Make a copy of all the register values unwound from this frame.
636 Save them in a scratch buffer so that there isn't a race between
637 trying to extract the old values from the current regcache while
638 at the same time writing new values into that same cache. */
639 scratch = frame_save_as_regcache (prev_frame);
640 cleanups = make_cleanup_regcache_xfree (scratch);
641
642 /* FIXME: cagney/2003-03-16: It should be possible to tell the
643 target's register cache that it is about to be hit with a burst
644 register transfer and that the sequence of register writes should
645 be batched. The pair target_prepare_to_store() and
646 target_store_registers() kind of suggest this functionality.
647 Unfortunately, they don't implement it. Their lack of a formal
648 definition can lead to targets writing back bogus values
649 (arguably a bug in the target code mind). */
650 /* Now copy those saved registers into the current regcache.
651 Here, regcache_cpy() calls regcache_restore(). */
652 regcache_cpy (get_current_regcache (), scratch);
653 do_cleanups (cleanups);
654
655 /* We've made right mess of GDB's local state, just discard
656 everything. */
657 reinit_frame_cache ();
658 }
659
660 void
661 frame_register_unwind (struct frame_info *frame, int regnum,
662 int *optimizedp, enum lval_type *lvalp,
663 CORE_ADDR *addrp, int *realnump, gdb_byte *bufferp)
664 {
665 struct value *value;
666
667 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
668 that the value proper does not need to be fetched. */
669 gdb_assert (optimizedp != NULL);
670 gdb_assert (lvalp != NULL);
671 gdb_assert (addrp != NULL);
672 gdb_assert (realnump != NULL);
673 /* gdb_assert (bufferp != NULL); */
674
675 value = frame_unwind_register_value (frame, regnum);
676
677 gdb_assert (value != NULL);
678
679 *optimizedp = value_optimized_out (value);
680 *lvalp = VALUE_LVAL (value);
681 *addrp = value_address (value);
682 *realnump = VALUE_REGNUM (value);
683
684 if (bufferp)
685 memcpy (bufferp, value_contents_all (value),
686 TYPE_LENGTH (value_type (value)));
687
688 /* Dispose of the new value. This prevents watchpoints from
689 trying to watch the saved frame pointer. */
690 release_value (value);
691 value_free (value);
692 }
693
694 void
695 frame_register (struct frame_info *frame, int regnum,
696 int *optimizedp, enum lval_type *lvalp,
697 CORE_ADDR *addrp, int *realnump, gdb_byte *bufferp)
698 {
699 /* Require all but BUFFERP to be valid. A NULL BUFFERP indicates
700 that the value proper does not need to be fetched. */
701 gdb_assert (optimizedp != NULL);
702 gdb_assert (lvalp != NULL);
703 gdb_assert (addrp != NULL);
704 gdb_assert (realnump != NULL);
705 /* gdb_assert (bufferp != NULL); */
706
707 /* Obtain the register value by unwinding the register from the next
708 (more inner frame). */
709 gdb_assert (frame != NULL && frame->next != NULL);
710 frame_register_unwind (frame->next, regnum, optimizedp, lvalp, addrp,
711 realnump, bufferp);
712 }
713
714 void
715 frame_unwind_register (struct frame_info *frame, int regnum, gdb_byte *buf)
716 {
717 int optimized;
718 CORE_ADDR addr;
719 int realnum;
720 enum lval_type lval;
721 frame_register_unwind (frame, regnum, &optimized, &lval, &addr,
722 &realnum, buf);
723 }
724
725 void
726 get_frame_register (struct frame_info *frame,
727 int regnum, gdb_byte *buf)
728 {
729 frame_unwind_register (frame->next, regnum, buf);
730 }
731
732 struct value *
733 frame_unwind_register_value (struct frame_info *frame, int regnum)
734 {
735 struct value *value;
736
737 gdb_assert (frame != NULL);
738
739 if (frame_debug)
740 {
741 fprintf_unfiltered (gdb_stdlog, "\
742 { frame_unwind_register_value (frame=%d,regnum=%d(%s),...) ",
743 frame->level, regnum,
744 user_reg_map_regnum_to_name
745 (get_frame_arch (frame), regnum));
746 }
747
748 /* Find the unwinder. */
749 if (frame->unwind == NULL)
750 frame->unwind = frame_unwind_find_by_frame (frame, &frame->prologue_cache);
751
752 /* Ask this frame to unwind its register. */
753 value = frame->unwind->prev_register (frame, &frame->prologue_cache, regnum);
754
755 if (frame_debug)
756 {
757 fprintf_unfiltered (gdb_stdlog, "->");
758 if (value_optimized_out (value))
759 fprintf_unfiltered (gdb_stdlog, " optimized out");
760 else
761 {
762 if (VALUE_LVAL (value) == lval_register)
763 fprintf_unfiltered (gdb_stdlog, " register=%d",
764 VALUE_REGNUM (value));
765 else if (VALUE_LVAL (value) == lval_memory)
766 fprintf_unfiltered (gdb_stdlog, " address=0x%s",
767 paddr_nz (value_address (value)));
768 else
769 fprintf_unfiltered (gdb_stdlog, " computed");
770
771 if (value_lazy (value))
772 fprintf_unfiltered (gdb_stdlog, " lazy");
773 else
774 {
775 int i;
776 const gdb_byte *buf = value_contents (value);
777
778 fprintf_unfiltered (gdb_stdlog, " bytes=");
779 fprintf_unfiltered (gdb_stdlog, "[");
780 for (i = 0; i < register_size (get_frame_arch (frame), regnum); i++)
781 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
782 fprintf_unfiltered (gdb_stdlog, "]");
783 }
784 }
785
786 fprintf_unfiltered (gdb_stdlog, " }\n");
787 }
788
789 return value;
790 }
791
792 struct value *
793 get_frame_register_value (struct frame_info *frame, int regnum)
794 {
795 return frame_unwind_register_value (frame->next, regnum);
796 }
797
798 LONGEST
799 frame_unwind_register_signed (struct frame_info *frame, int regnum)
800 {
801 gdb_byte buf[MAX_REGISTER_SIZE];
802 frame_unwind_register (frame, regnum, buf);
803 return extract_signed_integer (buf, register_size (get_frame_arch (frame),
804 regnum));
805 }
806
807 LONGEST
808 get_frame_register_signed (struct frame_info *frame, int regnum)
809 {
810 return frame_unwind_register_signed (frame->next, regnum);
811 }
812
813 ULONGEST
814 frame_unwind_register_unsigned (struct frame_info *frame, int regnum)
815 {
816 gdb_byte buf[MAX_REGISTER_SIZE];
817 frame_unwind_register (frame, regnum, buf);
818 return extract_unsigned_integer (buf, register_size (get_frame_arch (frame),
819 regnum));
820 }
821
822 ULONGEST
823 get_frame_register_unsigned (struct frame_info *frame, int regnum)
824 {
825 return frame_unwind_register_unsigned (frame->next, regnum);
826 }
827
828 void
829 put_frame_register (struct frame_info *frame, int regnum,
830 const gdb_byte *buf)
831 {
832 struct gdbarch *gdbarch = get_frame_arch (frame);
833 int realnum;
834 int optim;
835 enum lval_type lval;
836 CORE_ADDR addr;
837 frame_register (frame, regnum, &optim, &lval, &addr, &realnum, NULL);
838 if (optim)
839 error (_("Attempt to assign to a value that was optimized out."));
840 switch (lval)
841 {
842 case lval_memory:
843 {
844 /* FIXME: write_memory doesn't yet take constant buffers.
845 Arrrg! */
846 gdb_byte tmp[MAX_REGISTER_SIZE];
847 memcpy (tmp, buf, register_size (gdbarch, regnum));
848 write_memory (addr, tmp, register_size (gdbarch, regnum));
849 break;
850 }
851 case lval_register:
852 regcache_cooked_write (get_current_regcache (), realnum, buf);
853 break;
854 default:
855 error (_("Attempt to assign to an unmodifiable value."));
856 }
857 }
858
859 /* frame_register_read ()
860
861 Find and return the value of REGNUM for the specified stack frame.
862 The number of bytes copied is REGISTER_SIZE (REGNUM).
863
864 Returns 0 if the register value could not be found. */
865
866 int
867 frame_register_read (struct frame_info *frame, int regnum,
868 gdb_byte *myaddr)
869 {
870 int optimized;
871 enum lval_type lval;
872 CORE_ADDR addr;
873 int realnum;
874 frame_register (frame, regnum, &optimized, &lval, &addr, &realnum, myaddr);
875
876 return !optimized;
877 }
878
879 int
880 get_frame_register_bytes (struct frame_info *frame, int regnum,
881 CORE_ADDR offset, int len, gdb_byte *myaddr)
882 {
883 struct gdbarch *gdbarch = get_frame_arch (frame);
884 int i;
885 int maxsize;
886 int numregs;
887
888 /* Skip registers wholly inside of OFFSET. */
889 while (offset >= register_size (gdbarch, regnum))
890 {
891 offset -= register_size (gdbarch, regnum);
892 regnum++;
893 }
894
895 /* Ensure that we will not read beyond the end of the register file.
896 This can only ever happen if the debug information is bad. */
897 maxsize = -offset;
898 numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
899 for (i = regnum; i < numregs; i++)
900 {
901 int thissize = register_size (gdbarch, i);
902 if (thissize == 0)
903 break; /* This register is not available on this architecture. */
904 maxsize += thissize;
905 }
906 if (len > maxsize)
907 {
908 warning (_("Bad debug information detected: "
909 "Attempt to read %d bytes from registers."), len);
910 return 0;
911 }
912
913 /* Copy the data. */
914 while (len > 0)
915 {
916 int curr_len = register_size (gdbarch, regnum) - offset;
917 if (curr_len > len)
918 curr_len = len;
919
920 if (curr_len == register_size (gdbarch, regnum))
921 {
922 if (!frame_register_read (frame, regnum, myaddr))
923 return 0;
924 }
925 else
926 {
927 gdb_byte buf[MAX_REGISTER_SIZE];
928 if (!frame_register_read (frame, regnum, buf))
929 return 0;
930 memcpy (myaddr, buf + offset, curr_len);
931 }
932
933 myaddr += curr_len;
934 len -= curr_len;
935 offset = 0;
936 regnum++;
937 }
938
939 return 1;
940 }
941
942 void
943 put_frame_register_bytes (struct frame_info *frame, int regnum,
944 CORE_ADDR offset, int len, const gdb_byte *myaddr)
945 {
946 struct gdbarch *gdbarch = get_frame_arch (frame);
947
948 /* Skip registers wholly inside of OFFSET. */
949 while (offset >= register_size (gdbarch, regnum))
950 {
951 offset -= register_size (gdbarch, regnum);
952 regnum++;
953 }
954
955 /* Copy the data. */
956 while (len > 0)
957 {
958 int curr_len = register_size (gdbarch, regnum) - offset;
959 if (curr_len > len)
960 curr_len = len;
961
962 if (curr_len == register_size (gdbarch, regnum))
963 {
964 put_frame_register (frame, regnum, myaddr);
965 }
966 else
967 {
968 gdb_byte buf[MAX_REGISTER_SIZE];
969 frame_register_read (frame, regnum, buf);
970 memcpy (buf + offset, myaddr, curr_len);
971 put_frame_register (frame, regnum, buf);
972 }
973
974 myaddr += curr_len;
975 len -= curr_len;
976 offset = 0;
977 regnum++;
978 }
979 }
980
981 /* Create a sentinel frame. */
982
983 static struct frame_info *
984 create_sentinel_frame (struct regcache *regcache)
985 {
986 struct frame_info *frame = FRAME_OBSTACK_ZALLOC (struct frame_info);
987 frame->level = -1;
988 /* Explicitly initialize the sentinel frame's cache. Provide it
989 with the underlying regcache. In the future additional
990 information, such as the frame's thread will be added. */
991 frame->prologue_cache = sentinel_frame_cache (regcache);
992 /* For the moment there is only one sentinel frame implementation. */
993 frame->unwind = sentinel_frame_unwind;
994 /* Link this frame back to itself. The frame is self referential
995 (the unwound PC is the same as the pc), so make it so. */
996 frame->next = frame;
997 /* Make the sentinel frame's ID valid, but invalid. That way all
998 comparisons with it should fail. */
999 frame->this_id.p = 1;
1000 frame->this_id.value = null_frame_id;
1001 if (frame_debug)
1002 {
1003 fprintf_unfiltered (gdb_stdlog, "{ create_sentinel_frame (...) -> ");
1004 fprint_frame (gdb_stdlog, frame);
1005 fprintf_unfiltered (gdb_stdlog, " }\n");
1006 }
1007 return frame;
1008 }
1009
1010 /* Info about the innermost stack frame (contents of FP register) */
1011
1012 static struct frame_info *current_frame;
1013
1014 /* Cache for frame addresses already read by gdb. Valid only while
1015 inferior is stopped. Control variables for the frame cache should
1016 be local to this module. */
1017
1018 static struct obstack frame_cache_obstack;
1019
1020 void *
1021 frame_obstack_zalloc (unsigned long size)
1022 {
1023 void *data = obstack_alloc (&frame_cache_obstack, size);
1024 memset (data, 0, size);
1025 return data;
1026 }
1027
1028 /* Return the innermost (currently executing) stack frame. This is
1029 split into two functions. The function unwind_to_current_frame()
1030 is wrapped in catch exceptions so that, even when the unwind of the
1031 sentinel frame fails, the function still returns a stack frame. */
1032
1033 static int
1034 unwind_to_current_frame (struct ui_out *ui_out, void *args)
1035 {
1036 struct frame_info *frame = get_prev_frame (args);
1037 /* A sentinel frame can fail to unwind, e.g., because its PC value
1038 lands in somewhere like start. */
1039 if (frame == NULL)
1040 return 1;
1041 current_frame = frame;
1042 return 0;
1043 }
1044
1045 struct frame_info *
1046 get_current_frame (void)
1047 {
1048 /* First check, and report, the lack of registers. Having GDB
1049 report "No stack!" or "No memory" when the target doesn't even
1050 have registers is very confusing. Besides, "printcmd.exp"
1051 explicitly checks that ``print $pc'' with no registers prints "No
1052 registers". */
1053 if (!target_has_registers)
1054 error (_("No registers."));
1055 if (!target_has_stack)
1056 error (_("No stack."));
1057 if (!target_has_memory)
1058 error (_("No memory."));
1059 if (ptid_equal (inferior_ptid, null_ptid))
1060 error (_("No selected thread."));
1061 if (is_exited (inferior_ptid))
1062 error (_("Invalid selected thread."));
1063 if (is_executing (inferior_ptid))
1064 error (_("Target is executing."));
1065
1066 if (current_frame == NULL)
1067 {
1068 struct frame_info *sentinel_frame =
1069 create_sentinel_frame (get_current_regcache ());
1070 if (catch_exceptions (uiout, unwind_to_current_frame, sentinel_frame,
1071 RETURN_MASK_ERROR) != 0)
1072 {
1073 /* Oops! Fake a current frame? Is this useful? It has a PC
1074 of zero, for instance. */
1075 current_frame = sentinel_frame;
1076 }
1077 }
1078 return current_frame;
1079 }
1080
1081 /* The "selected" stack frame is used by default for local and arg
1082 access. May be zero, for no selected frame. */
1083
1084 static struct frame_info *selected_frame;
1085
1086 int
1087 has_stack_frames (void)
1088 {
1089 if (!target_has_registers || !target_has_stack || !target_has_memory)
1090 return 0;
1091
1092 /* No current inferior, no frame. */
1093 if (ptid_equal (inferior_ptid, null_ptid))
1094 return 0;
1095
1096 /* Don't try to read from a dead thread. */
1097 if (is_exited (inferior_ptid))
1098 return 0;
1099
1100 /* ... or from a spinning thread. */
1101 if (is_executing (inferior_ptid))
1102 return 0;
1103
1104 return 1;
1105 }
1106
1107 /* Return the selected frame. Always non-NULL (unless there isn't an
1108 inferior sufficient for creating a frame) in which case an error is
1109 thrown. */
1110
1111 struct frame_info *
1112 get_selected_frame (const char *message)
1113 {
1114 if (selected_frame == NULL)
1115 {
1116 if (message != NULL && !has_stack_frames ())
1117 error (("%s"), message);
1118 /* Hey! Don't trust this. It should really be re-finding the
1119 last selected frame of the currently selected thread. This,
1120 though, is better than nothing. */
1121 select_frame (get_current_frame ());
1122 }
1123 /* There is always a frame. */
1124 gdb_assert (selected_frame != NULL);
1125 return selected_frame;
1126 }
1127
1128 /* This is a variant of get_selected_frame() which can be called when
1129 the inferior does not have a frame; in that case it will return
1130 NULL instead of calling error(). */
1131
1132 struct frame_info *
1133 deprecated_safe_get_selected_frame (void)
1134 {
1135 if (!has_stack_frames ())
1136 return NULL;
1137 return get_selected_frame (NULL);
1138 }
1139
1140 /* Select frame FI (or NULL - to invalidate the current frame). */
1141
1142 void
1143 select_frame (struct frame_info *fi)
1144 {
1145 struct symtab *s;
1146
1147 selected_frame = fi;
1148 /* NOTE: cagney/2002-05-04: FI can be NULL. This occurs when the
1149 frame is being invalidated. */
1150 if (deprecated_selected_frame_level_changed_hook)
1151 deprecated_selected_frame_level_changed_hook (frame_relative_level (fi));
1152
1153 /* FIXME: kseitz/2002-08-28: It would be nice to call
1154 selected_frame_level_changed_event() right here, but due to limitations
1155 in the current interfaces, we would end up flooding UIs with events
1156 because select_frame() is used extensively internally.
1157
1158 Once we have frame-parameterized frame (and frame-related) commands,
1159 the event notification can be moved here, since this function will only
1160 be called when the user's selected frame is being changed. */
1161
1162 /* Ensure that symbols for this frame are read in. Also, determine the
1163 source language of this frame, and switch to it if desired. */
1164 if (fi)
1165 {
1166 /* We retrieve the frame's symtab by using the frame PC. However
1167 we cannot use the frame PC as-is, because it usually points to
1168 the instruction following the "call", which is sometimes the
1169 first instruction of another function. So we rely on
1170 get_frame_address_in_block() which provides us with a PC which
1171 is guaranteed to be inside the frame's code block. */
1172 s = find_pc_symtab (get_frame_address_in_block (fi));
1173 if (s
1174 && s->language != current_language->la_language
1175 && s->language != language_unknown
1176 && language_mode == language_mode_auto)
1177 {
1178 set_language (s->language);
1179 }
1180 }
1181 }
1182
1183 /* Create an arbitrary (i.e. address specified by user) or innermost frame.
1184 Always returns a non-NULL value. */
1185
1186 struct frame_info *
1187 create_new_frame (CORE_ADDR addr, CORE_ADDR pc)
1188 {
1189 struct frame_info *fi;
1190
1191 if (frame_debug)
1192 {
1193 fprintf_unfiltered (gdb_stdlog,
1194 "{ create_new_frame (addr=0x%s, pc=0x%s) ",
1195 paddr_nz (addr), paddr_nz (pc));
1196 }
1197
1198 fi = FRAME_OBSTACK_ZALLOC (struct frame_info);
1199
1200 fi->next = create_sentinel_frame (get_current_regcache ());
1201
1202 /* Set/update this frame's cached PC value, found in the next frame.
1203 Do this before looking for this frame's unwinder. A sniffer is
1204 very likely to read this, and the corresponding unwinder is
1205 entitled to rely that the PC doesn't magically change. */
1206 fi->next->prev_pc.value = pc;
1207 fi->next->prev_pc.p = 1;
1208
1209 /* Select/initialize both the unwind function and the frame's type
1210 based on the PC. */
1211 fi->unwind = frame_unwind_find_by_frame (fi, &fi->prologue_cache);
1212
1213 fi->this_id.p = 1;
1214 fi->this_id.value = frame_id_build (addr, pc);
1215
1216 if (frame_debug)
1217 {
1218 fprintf_unfiltered (gdb_stdlog, "-> ");
1219 fprint_frame (gdb_stdlog, fi);
1220 fprintf_unfiltered (gdb_stdlog, " }\n");
1221 }
1222
1223 return fi;
1224 }
1225
1226 /* Return the frame that THIS_FRAME calls (NULL if THIS_FRAME is the
1227 innermost frame). Be careful to not fall off the bottom of the
1228 frame chain and onto the sentinel frame. */
1229
1230 struct frame_info *
1231 get_next_frame (struct frame_info *this_frame)
1232 {
1233 if (this_frame->level > 0)
1234 return this_frame->next;
1235 else
1236 return NULL;
1237 }
1238
1239 /* Observer for the target_changed event. */
1240
1241 static void
1242 frame_observer_target_changed (struct target_ops *target)
1243 {
1244 reinit_frame_cache ();
1245 }
1246
1247 /* Flush the entire frame cache. */
1248
1249 void
1250 reinit_frame_cache (void)
1251 {
1252 struct frame_info *fi;
1253
1254 /* Tear down all frame caches. */
1255 for (fi = current_frame; fi != NULL; fi = fi->prev)
1256 {
1257 if (fi->prologue_cache && fi->unwind->dealloc_cache)
1258 fi->unwind->dealloc_cache (fi, fi->prologue_cache);
1259 if (fi->base_cache && fi->base->unwind->dealloc_cache)
1260 fi->base->unwind->dealloc_cache (fi, fi->base_cache);
1261 }
1262
1263 /* Since we can't really be sure what the first object allocated was */
1264 obstack_free (&frame_cache_obstack, 0);
1265 obstack_init (&frame_cache_obstack);
1266
1267 if (current_frame != NULL)
1268 annotate_frames_invalid ();
1269
1270 current_frame = NULL; /* Invalidate cache */
1271 select_frame (NULL);
1272 if (frame_debug)
1273 fprintf_unfiltered (gdb_stdlog, "{ reinit_frame_cache () }\n");
1274 }
1275
1276 /* Find where a register is saved (in memory or another register).
1277 The result of frame_register_unwind is just where it is saved
1278 relative to this particular frame. */
1279
1280 static void
1281 frame_register_unwind_location (struct frame_info *this_frame, int regnum,
1282 int *optimizedp, enum lval_type *lvalp,
1283 CORE_ADDR *addrp, int *realnump)
1284 {
1285 gdb_assert (this_frame == NULL || this_frame->level >= 0);
1286
1287 while (this_frame != NULL)
1288 {
1289 frame_register_unwind (this_frame, regnum, optimizedp, lvalp,
1290 addrp, realnump, NULL);
1291
1292 if (*optimizedp)
1293 break;
1294
1295 if (*lvalp != lval_register)
1296 break;
1297
1298 regnum = *realnump;
1299 this_frame = get_next_frame (this_frame);
1300 }
1301 }
1302
1303 /* Return a "struct frame_info" corresponding to the frame that called
1304 THIS_FRAME. Returns NULL if there is no such frame.
1305
1306 Unlike get_prev_frame, this function always tries to unwind the
1307 frame. */
1308
1309 static struct frame_info *
1310 get_prev_frame_1 (struct frame_info *this_frame)
1311 {
1312 struct frame_id this_id;
1313 struct gdbarch *gdbarch;
1314
1315 gdb_assert (this_frame != NULL);
1316 gdbarch = get_frame_arch (this_frame);
1317
1318 if (frame_debug)
1319 {
1320 fprintf_unfiltered (gdb_stdlog, "{ get_prev_frame_1 (this_frame=");
1321 if (this_frame != NULL)
1322 fprintf_unfiltered (gdb_stdlog, "%d", this_frame->level);
1323 else
1324 fprintf_unfiltered (gdb_stdlog, "<NULL>");
1325 fprintf_unfiltered (gdb_stdlog, ") ");
1326 }
1327
1328 /* Only try to do the unwind once. */
1329 if (this_frame->prev_p)
1330 {
1331 if (frame_debug)
1332 {
1333 fprintf_unfiltered (gdb_stdlog, "-> ");
1334 fprint_frame (gdb_stdlog, this_frame->prev);
1335 fprintf_unfiltered (gdb_stdlog, " // cached \n");
1336 }
1337 return this_frame->prev;
1338 }
1339
1340 /* If the frame unwinder hasn't been selected yet, we must do so
1341 before setting prev_p; otherwise the check for misbehaved
1342 sniffers will think that this frame's sniffer tried to unwind
1343 further (see frame_cleanup_after_sniffer). */
1344 if (this_frame->unwind == NULL)
1345 this_frame->unwind
1346 = frame_unwind_find_by_frame (this_frame, &this_frame->prologue_cache);
1347
1348 this_frame->prev_p = 1;
1349 this_frame->stop_reason = UNWIND_NO_REASON;
1350
1351 /* If we are unwinding from an inline frame, all of the below tests
1352 were already performed when we unwound from the next non-inline
1353 frame. We must skip them, since we can not get THIS_FRAME's ID
1354 until we have unwound all the way down to the previous non-inline
1355 frame. */
1356 if (get_frame_type (this_frame) == INLINE_FRAME)
1357 return get_prev_frame_raw (this_frame);
1358
1359 /* Check that this frame's ID was valid. If it wasn't, don't try to
1360 unwind to the prev frame. Be careful to not apply this test to
1361 the sentinel frame. */
1362 this_id = get_frame_id (this_frame);
1363 if (this_frame->level >= 0 && !frame_id_p (this_id))
1364 {
1365 if (frame_debug)
1366 {
1367 fprintf_unfiltered (gdb_stdlog, "-> ");
1368 fprint_frame (gdb_stdlog, NULL);
1369 fprintf_unfiltered (gdb_stdlog, " // this ID is NULL }\n");
1370 }
1371 this_frame->stop_reason = UNWIND_NULL_ID;
1372 return NULL;
1373 }
1374
1375 /* Check that this frame's ID isn't inner to (younger, below, next)
1376 the next frame. This happens when a frame unwind goes backwards.
1377 This check is valid only if this frame and the next frame are NORMAL.
1378 See the comment at frame_id_inner for details. */
1379 if (get_frame_type (this_frame) == NORMAL_FRAME
1380 && this_frame->next->unwind->type == NORMAL_FRAME
1381 && frame_id_inner (get_frame_arch (this_frame->next), this_id,
1382 get_frame_id (this_frame->next)))
1383 {
1384 if (frame_debug)
1385 {
1386 fprintf_unfiltered (gdb_stdlog, "-> ");
1387 fprint_frame (gdb_stdlog, NULL);
1388 fprintf_unfiltered (gdb_stdlog, " // this frame ID is inner }\n");
1389 }
1390 this_frame->stop_reason = UNWIND_INNER_ID;
1391 return NULL;
1392 }
1393
1394 /* Check that this and the next frame are not identical. If they
1395 are, there is most likely a stack cycle. As with the inner-than
1396 test above, avoid comparing the inner-most and sentinel frames. */
1397 if (this_frame->level > 0
1398 && frame_id_eq (this_id, get_frame_id (this_frame->next)))
1399 {
1400 if (frame_debug)
1401 {
1402 fprintf_unfiltered (gdb_stdlog, "-> ");
1403 fprint_frame (gdb_stdlog, NULL);
1404 fprintf_unfiltered (gdb_stdlog, " // this frame has same ID }\n");
1405 }
1406 this_frame->stop_reason = UNWIND_SAME_ID;
1407 return NULL;
1408 }
1409
1410 /* Check that this and the next frame do not unwind the PC register
1411 to the same memory location. If they do, then even though they
1412 have different frame IDs, the new frame will be bogus; two
1413 functions can't share a register save slot for the PC. This can
1414 happen when the prologue analyzer finds a stack adjustment, but
1415 no PC save.
1416
1417 This check does assume that the "PC register" is roughly a
1418 traditional PC, even if the gdbarch_unwind_pc method adjusts
1419 it (we do not rely on the value, only on the unwound PC being
1420 dependent on this value). A potential improvement would be
1421 to have the frame prev_pc method and the gdbarch unwind_pc
1422 method set the same lval and location information as
1423 frame_register_unwind. */
1424 if (this_frame->level > 0
1425 && gdbarch_pc_regnum (gdbarch) >= 0
1426 && get_frame_type (this_frame) == NORMAL_FRAME
1427 && (get_frame_type (this_frame->next) == NORMAL_FRAME
1428 || get_frame_type (this_frame->next) == INLINE_FRAME))
1429 {
1430 int optimized, realnum, nrealnum;
1431 enum lval_type lval, nlval;
1432 CORE_ADDR addr, naddr;
1433
1434 frame_register_unwind_location (this_frame,
1435 gdbarch_pc_regnum (gdbarch),
1436 &optimized, &lval, &addr, &realnum);
1437 frame_register_unwind_location (get_next_frame (this_frame),
1438 gdbarch_pc_regnum (gdbarch),
1439 &optimized, &nlval, &naddr, &nrealnum);
1440
1441 if ((lval == lval_memory && lval == nlval && addr == naddr)
1442 || (lval == lval_register && lval == nlval && realnum == nrealnum))
1443 {
1444 if (frame_debug)
1445 {
1446 fprintf_unfiltered (gdb_stdlog, "-> ");
1447 fprint_frame (gdb_stdlog, NULL);
1448 fprintf_unfiltered (gdb_stdlog, " // no saved PC }\n");
1449 }
1450
1451 this_frame->stop_reason = UNWIND_NO_SAVED_PC;
1452 this_frame->prev = NULL;
1453 return NULL;
1454 }
1455 }
1456
1457 return get_prev_frame_raw (this_frame);
1458 }
1459
1460 /* Construct a new "struct frame_info" and link it previous to
1461 this_frame. */
1462
1463 static struct frame_info *
1464 get_prev_frame_raw (struct frame_info *this_frame)
1465 {
1466 struct frame_info *prev_frame;
1467
1468 /* Allocate the new frame but do not wire it in to the frame chain.
1469 Some (bad) code in INIT_FRAME_EXTRA_INFO tries to look along
1470 frame->next to pull some fancy tricks (of course such code is, by
1471 definition, recursive). Try to prevent it.
1472
1473 There is no reason to worry about memory leaks, should the
1474 remainder of the function fail. The allocated memory will be
1475 quickly reclaimed when the frame cache is flushed, and the `we've
1476 been here before' check above will stop repeated memory
1477 allocation calls. */
1478 prev_frame = FRAME_OBSTACK_ZALLOC (struct frame_info);
1479 prev_frame->level = this_frame->level + 1;
1480
1481 /* Don't yet compute ->unwind (and hence ->type). It is computed
1482 on-demand in get_frame_type, frame_register_unwind, and
1483 get_frame_id. */
1484
1485 /* Don't yet compute the frame's ID. It is computed on-demand by
1486 get_frame_id(). */
1487
1488 /* The unwound frame ID is validate at the start of this function,
1489 as part of the logic to decide if that frame should be further
1490 unwound, and not here while the prev frame is being created.
1491 Doing this makes it possible for the user to examine a frame that
1492 has an invalid frame ID.
1493
1494 Some very old VAX code noted: [...] For the sake of argument,
1495 suppose that the stack is somewhat trashed (which is one reason
1496 that "info frame" exists). So, return 0 (indicating we don't
1497 know the address of the arglist) if we don't know what frame this
1498 frame calls. */
1499
1500 /* Link it in. */
1501 this_frame->prev = prev_frame;
1502 prev_frame->next = this_frame;
1503
1504 if (frame_debug)
1505 {
1506 fprintf_unfiltered (gdb_stdlog, "-> ");
1507 fprint_frame (gdb_stdlog, prev_frame);
1508 fprintf_unfiltered (gdb_stdlog, " }\n");
1509 }
1510
1511 return prev_frame;
1512 }
1513
1514 /* Debug routine to print a NULL frame being returned. */
1515
1516 static void
1517 frame_debug_got_null_frame (struct frame_info *this_frame,
1518 const char *reason)
1519 {
1520 if (frame_debug)
1521 {
1522 fprintf_unfiltered (gdb_stdlog, "{ get_prev_frame (this_frame=");
1523 if (this_frame != NULL)
1524 fprintf_unfiltered (gdb_stdlog, "%d", this_frame->level);
1525 else
1526 fprintf_unfiltered (gdb_stdlog, "<NULL>");
1527 fprintf_unfiltered (gdb_stdlog, ") -> // %s}\n", reason);
1528 }
1529 }
1530
1531 /* Is this (non-sentinel) frame in the "main"() function? */
1532
1533 static int
1534 inside_main_func (struct frame_info *this_frame)
1535 {
1536 struct minimal_symbol *msymbol;
1537 CORE_ADDR maddr;
1538
1539 if (symfile_objfile == 0)
1540 return 0;
1541 msymbol = lookup_minimal_symbol (main_name (), NULL, symfile_objfile);
1542 if (msymbol == NULL)
1543 return 0;
1544 /* Make certain that the code, and not descriptor, address is
1545 returned. */
1546 maddr = gdbarch_convert_from_func_ptr_addr (get_frame_arch (this_frame),
1547 SYMBOL_VALUE_ADDRESS (msymbol),
1548 &current_target);
1549 return maddr == get_frame_func (this_frame);
1550 }
1551
1552 /* Test whether THIS_FRAME is inside the process entry point function. */
1553
1554 static int
1555 inside_entry_func (struct frame_info *this_frame)
1556 {
1557 return (get_frame_func (this_frame) == entry_point_address ());
1558 }
1559
1560 /* Return a structure containing various interesting information about
1561 the frame that called THIS_FRAME. Returns NULL if there is entier
1562 no such frame or the frame fails any of a set of target-independent
1563 condition that should terminate the frame chain (e.g., as unwinding
1564 past main()).
1565
1566 This function should not contain target-dependent tests, such as
1567 checking whether the program-counter is zero. */
1568
1569 struct frame_info *
1570 get_prev_frame (struct frame_info *this_frame)
1571 {
1572 struct frame_info *prev_frame;
1573
1574 /* There is always a frame. If this assertion fails, suspect that
1575 something should be calling get_selected_frame() or
1576 get_current_frame(). */
1577 gdb_assert (this_frame != NULL);
1578
1579 /* tausq/2004-12-07: Dummy frames are skipped because it doesn't make much
1580 sense to stop unwinding at a dummy frame. One place where a dummy
1581 frame may have an address "inside_main_func" is on HPUX. On HPUX, the
1582 pcsqh register (space register for the instruction at the head of the
1583 instruction queue) cannot be written directly; the only way to set it
1584 is to branch to code that is in the target space. In order to implement
1585 frame dummies on HPUX, the called function is made to jump back to where
1586 the inferior was when the user function was called. If gdb was inside
1587 the main function when we created the dummy frame, the dummy frame will
1588 point inside the main function. */
1589 if (this_frame->level >= 0
1590 && get_frame_type (this_frame) == NORMAL_FRAME
1591 && !backtrace_past_main
1592 && inside_main_func (this_frame))
1593 /* Don't unwind past main(). Note, this is done _before_ the
1594 frame has been marked as previously unwound. That way if the
1595 user later decides to enable unwinds past main(), that will
1596 automatically happen. */
1597 {
1598 frame_debug_got_null_frame (this_frame, "inside main func");
1599 return NULL;
1600 }
1601
1602 /* If the user's backtrace limit has been exceeded, stop. We must
1603 add two to the current level; one of those accounts for backtrace_limit
1604 being 1-based and the level being 0-based, and the other accounts for
1605 the level of the new frame instead of the level of the current
1606 frame. */
1607 if (this_frame->level + 2 > backtrace_limit)
1608 {
1609 frame_debug_got_null_frame (this_frame, "backtrace limit exceeded");
1610 return NULL;
1611 }
1612
1613 /* If we're already inside the entry function for the main objfile,
1614 then it isn't valid. Don't apply this test to a dummy frame -
1615 dummy frame PCs typically land in the entry func. Don't apply
1616 this test to the sentinel frame. Sentinel frames should always
1617 be allowed to unwind. */
1618 /* NOTE: cagney/2003-07-07: Fixed a bug in inside_main_func() -
1619 wasn't checking for "main" in the minimal symbols. With that
1620 fixed asm-source tests now stop in "main" instead of halting the
1621 backtrace in weird and wonderful ways somewhere inside the entry
1622 file. Suspect that tests for inside the entry file/func were
1623 added to work around that (now fixed) case. */
1624 /* NOTE: cagney/2003-07-15: danielj (if I'm reading it right)
1625 suggested having the inside_entry_func test use the
1626 inside_main_func() msymbol trick (along with entry_point_address()
1627 I guess) to determine the address range of the start function.
1628 That should provide a far better stopper than the current
1629 heuristics. */
1630 /* NOTE: tausq/2004-10-09: this is needed if, for example, the compiler
1631 applied tail-call optimizations to main so that a function called
1632 from main returns directly to the caller of main. Since we don't
1633 stop at main, we should at least stop at the entry point of the
1634 application. */
1635 if (this_frame->level >= 0
1636 && get_frame_type (this_frame) == NORMAL_FRAME
1637 && !backtrace_past_entry
1638 && inside_entry_func (this_frame))
1639 {
1640 frame_debug_got_null_frame (this_frame, "inside entry func");
1641 return NULL;
1642 }
1643
1644 /* Assume that the only way to get a zero PC is through something
1645 like a SIGSEGV or a dummy frame, and hence that NORMAL frames
1646 will never unwind a zero PC. */
1647 if (this_frame->level > 0
1648 && (get_frame_type (this_frame) == NORMAL_FRAME
1649 || get_frame_type (this_frame) == INLINE_FRAME)
1650 && get_frame_type (get_next_frame (this_frame)) == NORMAL_FRAME
1651 && get_frame_pc (this_frame) == 0)
1652 {
1653 frame_debug_got_null_frame (this_frame, "zero PC");
1654 return NULL;
1655 }
1656
1657 return get_prev_frame_1 (this_frame);
1658 }
1659
1660 CORE_ADDR
1661 get_frame_pc (struct frame_info *frame)
1662 {
1663 gdb_assert (frame->next != NULL);
1664 return frame_unwind_pc (frame->next);
1665 }
1666
1667 /* Return an address that falls within THIS_FRAME's code block. */
1668
1669 CORE_ADDR
1670 get_frame_address_in_block (struct frame_info *this_frame)
1671 {
1672 /* A draft address. */
1673 CORE_ADDR pc = get_frame_pc (this_frame);
1674
1675 struct frame_info *next_frame = this_frame->next;
1676
1677 /* Calling get_frame_pc returns the resume address for THIS_FRAME.
1678 Normally the resume address is inside the body of the function
1679 associated with THIS_FRAME, but there is a special case: when
1680 calling a function which the compiler knows will never return
1681 (for instance abort), the call may be the very last instruction
1682 in the calling function. The resume address will point after the
1683 call and may be at the beginning of a different function
1684 entirely.
1685
1686 If THIS_FRAME is a signal frame or dummy frame, then we should
1687 not adjust the unwound PC. For a dummy frame, GDB pushed the
1688 resume address manually onto the stack. For a signal frame, the
1689 OS may have pushed the resume address manually and invoked the
1690 handler (e.g. GNU/Linux), or invoked the trampoline which called
1691 the signal handler - but in either case the signal handler is
1692 expected to return to the trampoline. So in both of these
1693 cases we know that the resume address is executable and
1694 related. So we only need to adjust the PC if THIS_FRAME
1695 is a normal function.
1696
1697 If the program has been interrupted while THIS_FRAME is current,
1698 then clearly the resume address is inside the associated
1699 function. There are three kinds of interruption: debugger stop
1700 (next frame will be SENTINEL_FRAME), operating system
1701 signal or exception (next frame will be SIGTRAMP_FRAME),
1702 or debugger-induced function call (next frame will be
1703 DUMMY_FRAME). So we only need to adjust the PC if
1704 NEXT_FRAME is a normal function.
1705
1706 We check the type of NEXT_FRAME first, since it is already
1707 known; frame type is determined by the unwinder, and since
1708 we have THIS_FRAME we've already selected an unwinder for
1709 NEXT_FRAME.
1710
1711 If the next frame is inlined, we need to keep going until we find
1712 the real function - for instance, if a signal handler is invoked
1713 while in an inlined function, then the code address of the
1714 "calling" normal function should not be adjusted either. */
1715
1716 while (get_frame_type (next_frame) == INLINE_FRAME)
1717 next_frame = next_frame->next;
1718
1719 if (get_frame_type (next_frame) == NORMAL_FRAME
1720 && (get_frame_type (this_frame) == NORMAL_FRAME
1721 || get_frame_type (this_frame) == INLINE_FRAME))
1722 return pc - 1;
1723
1724 return pc;
1725 }
1726
1727 void
1728 find_frame_sal (struct frame_info *frame, struct symtab_and_line *sal)
1729 {
1730 struct frame_info *next_frame;
1731 int notcurrent;
1732
1733 /* If the next frame represents an inlined function call, this frame's
1734 sal is the "call site" of that inlined function, which can not
1735 be inferred from get_frame_pc. */
1736 next_frame = get_next_frame (frame);
1737 if (frame_inlined_callees (frame) > 0)
1738 {
1739 struct symbol *sym;
1740
1741 if (next_frame)
1742 sym = get_frame_function (next_frame);
1743 else
1744 sym = inline_skipped_symbol (inferior_ptid);
1745
1746 init_sal (sal);
1747 if (SYMBOL_LINE (sym) != 0)
1748 {
1749 sal->symtab = SYMBOL_SYMTAB (sym);
1750 sal->line = SYMBOL_LINE (sym);
1751 }
1752 else
1753 /* If the symbol does not have a location, we don't know where
1754 the call site is. Do not pretend to. This is jarring, but
1755 we can't do much better. */
1756 sal->pc = get_frame_pc (frame);
1757
1758 return;
1759 }
1760
1761 /* If FRAME is not the innermost frame, that normally means that
1762 FRAME->pc points at the return instruction (which is *after* the
1763 call instruction), and we want to get the line containing the
1764 call (because the call is where the user thinks the program is).
1765 However, if the next frame is either a SIGTRAMP_FRAME or a
1766 DUMMY_FRAME, then the next frame will contain a saved interrupt
1767 PC and such a PC indicates the current (rather than next)
1768 instruction/line, consequently, for such cases, want to get the
1769 line containing fi->pc. */
1770 notcurrent = (get_frame_pc (frame) != get_frame_address_in_block (frame));
1771 (*sal) = find_pc_line (get_frame_pc (frame), notcurrent);
1772 }
1773
1774 /* Per "frame.h", return the ``address'' of the frame. Code should
1775 really be using get_frame_id(). */
1776 CORE_ADDR
1777 get_frame_base (struct frame_info *fi)
1778 {
1779 return get_frame_id (fi).stack_addr;
1780 }
1781
1782 /* High-level offsets into the frame. Used by the debug info. */
1783
1784 CORE_ADDR
1785 get_frame_base_address (struct frame_info *fi)
1786 {
1787 if (get_frame_type (fi) != NORMAL_FRAME)
1788 return 0;
1789 if (fi->base == NULL)
1790 fi->base = frame_base_find_by_frame (fi);
1791 /* Sneaky: If the low-level unwind and high-level base code share a
1792 common unwinder, let them share the prologue cache. */
1793 if (fi->base->unwind == fi->unwind)
1794 return fi->base->this_base (fi, &fi->prologue_cache);
1795 return fi->base->this_base (fi, &fi->base_cache);
1796 }
1797
1798 CORE_ADDR
1799 get_frame_locals_address (struct frame_info *fi)
1800 {
1801 void **cache;
1802 if (get_frame_type (fi) != NORMAL_FRAME)
1803 return 0;
1804 /* If there isn't a frame address method, find it. */
1805 if (fi->base == NULL)
1806 fi->base = frame_base_find_by_frame (fi);
1807 /* Sneaky: If the low-level unwind and high-level base code share a
1808 common unwinder, let them share the prologue cache. */
1809 if (fi->base->unwind == fi->unwind)
1810 return fi->base->this_locals (fi, &fi->prologue_cache);
1811 return fi->base->this_locals (fi, &fi->base_cache);
1812 }
1813
1814 CORE_ADDR
1815 get_frame_args_address (struct frame_info *fi)
1816 {
1817 void **cache;
1818 if (get_frame_type (fi) != NORMAL_FRAME)
1819 return 0;
1820 /* If there isn't a frame address method, find it. */
1821 if (fi->base == NULL)
1822 fi->base = frame_base_find_by_frame (fi);
1823 /* Sneaky: If the low-level unwind and high-level base code share a
1824 common unwinder, let them share the prologue cache. */
1825 if (fi->base->unwind == fi->unwind)
1826 return fi->base->this_args (fi, &fi->prologue_cache);
1827 return fi->base->this_args (fi, &fi->base_cache);
1828 }
1829
1830 /* Level of the selected frame: 0 for innermost, 1 for its caller, ...
1831 or -1 for a NULL frame. */
1832
1833 int
1834 frame_relative_level (struct frame_info *fi)
1835 {
1836 if (fi == NULL)
1837 return -1;
1838 else
1839 return fi->level;
1840 }
1841
1842 enum frame_type
1843 get_frame_type (struct frame_info *frame)
1844 {
1845 if (frame->unwind == NULL)
1846 /* Initialize the frame's unwinder because that's what
1847 provides the frame's type. */
1848 frame->unwind = frame_unwind_find_by_frame (frame, &frame->prologue_cache);
1849 return frame->unwind->type;
1850 }
1851
1852 /* Memory access methods. */
1853
1854 void
1855 get_frame_memory (struct frame_info *this_frame, CORE_ADDR addr,
1856 gdb_byte *buf, int len)
1857 {
1858 read_memory (addr, buf, len);
1859 }
1860
1861 LONGEST
1862 get_frame_memory_signed (struct frame_info *this_frame, CORE_ADDR addr,
1863 int len)
1864 {
1865 return read_memory_integer (addr, len);
1866 }
1867
1868 ULONGEST
1869 get_frame_memory_unsigned (struct frame_info *this_frame, CORE_ADDR addr,
1870 int len)
1871 {
1872 return read_memory_unsigned_integer (addr, len);
1873 }
1874
1875 int
1876 safe_frame_unwind_memory (struct frame_info *this_frame,
1877 CORE_ADDR addr, gdb_byte *buf, int len)
1878 {
1879 /* NOTE: target_read_memory returns zero on success! */
1880 return !target_read_memory (addr, buf, len);
1881 }
1882
1883 /* Architecture method. */
1884
1885 struct gdbarch *
1886 get_frame_arch (struct frame_info *this_frame)
1887 {
1888 /* In the future, this function will return a per-frame
1889 architecture instead of current_gdbarch. Calling the
1890 routine with a NULL value of this_frame is a bug! */
1891 gdb_assert (this_frame);
1892
1893 return current_gdbarch;
1894 }
1895
1896 /* Stack pointer methods. */
1897
1898 CORE_ADDR
1899 get_frame_sp (struct frame_info *this_frame)
1900 {
1901 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1902 /* Normality - an architecture that provides a way of obtaining any
1903 frame inner-most address. */
1904 if (gdbarch_unwind_sp_p (gdbarch))
1905 /* NOTE drow/2008-06-28: gdbarch_unwind_sp could be converted to
1906 operate on THIS_FRAME now. */
1907 return gdbarch_unwind_sp (gdbarch, this_frame->next);
1908 /* Now things are really are grim. Hope that the value returned by
1909 the gdbarch_sp_regnum register is meaningful. */
1910 if (gdbarch_sp_regnum (gdbarch) >= 0)
1911 return get_frame_register_unsigned (this_frame,
1912 gdbarch_sp_regnum (gdbarch));
1913 internal_error (__FILE__, __LINE__, _("Missing unwind SP method"));
1914 }
1915
1916 /* Return the reason why we can't unwind past FRAME. */
1917
1918 enum unwind_stop_reason
1919 get_frame_unwind_stop_reason (struct frame_info *frame)
1920 {
1921 /* If we haven't tried to unwind past this point yet, then assume
1922 that unwinding would succeed. */
1923 if (frame->prev_p == 0)
1924 return UNWIND_NO_REASON;
1925
1926 /* Otherwise, we set a reason when we succeeded (or failed) to
1927 unwind. */
1928 return frame->stop_reason;
1929 }
1930
1931 /* Return a string explaining REASON. */
1932
1933 const char *
1934 frame_stop_reason_string (enum unwind_stop_reason reason)
1935 {
1936 switch (reason)
1937 {
1938 case UNWIND_NULL_ID:
1939 return _("unwinder did not report frame ID");
1940
1941 case UNWIND_INNER_ID:
1942 return _("previous frame inner to this frame (corrupt stack?)");
1943
1944 case UNWIND_SAME_ID:
1945 return _("previous frame identical to this frame (corrupt stack?)");
1946
1947 case UNWIND_NO_SAVED_PC:
1948 return _("frame did not save the PC");
1949
1950 case UNWIND_NO_REASON:
1951 case UNWIND_FIRST_ERROR:
1952 default:
1953 internal_error (__FILE__, __LINE__,
1954 "Invalid frame stop reason");
1955 }
1956 }
1957
1958 /* Clean up after a failed (wrong unwinder) attempt to unwind past
1959 FRAME. */
1960
1961 static void
1962 frame_cleanup_after_sniffer (void *arg)
1963 {
1964 struct frame_info *frame = arg;
1965
1966 /* The sniffer should not allocate a prologue cache if it did not
1967 match this frame. */
1968 gdb_assert (frame->prologue_cache == NULL);
1969
1970 /* No sniffer should extend the frame chain; sniff based on what is
1971 already certain. */
1972 gdb_assert (!frame->prev_p);
1973
1974 /* The sniffer should not check the frame's ID; that's circular. */
1975 gdb_assert (!frame->this_id.p);
1976
1977 /* Clear cached fields dependent on the unwinder.
1978
1979 The previous PC is independent of the unwinder, but the previous
1980 function is not (see get_frame_address_in_block). */
1981 frame->prev_func.p = 0;
1982 frame->prev_func.addr = 0;
1983
1984 /* Discard the unwinder last, so that we can easily find it if an assertion
1985 in this function triggers. */
1986 frame->unwind = NULL;
1987 }
1988
1989 /* Set FRAME's unwinder temporarily, so that we can call a sniffer.
1990 Return a cleanup which should be called if unwinding fails, and
1991 discarded if it succeeds. */
1992
1993 struct cleanup *
1994 frame_prepare_for_sniffer (struct frame_info *frame,
1995 const struct frame_unwind *unwind)
1996 {
1997 gdb_assert (frame->unwind == NULL);
1998 frame->unwind = unwind;
1999 return make_cleanup (frame_cleanup_after_sniffer, frame);
2000 }
2001
2002 extern initialize_file_ftype _initialize_frame; /* -Wmissing-prototypes */
2003
2004 static struct cmd_list_element *set_backtrace_cmdlist;
2005 static struct cmd_list_element *show_backtrace_cmdlist;
2006
2007 static void
2008 set_backtrace_cmd (char *args, int from_tty)
2009 {
2010 help_list (set_backtrace_cmdlist, "set backtrace ", -1, gdb_stdout);
2011 }
2012
2013 static void
2014 show_backtrace_cmd (char *args, int from_tty)
2015 {
2016 cmd_show_list (show_backtrace_cmdlist, from_tty, "");
2017 }
2018
2019 void
2020 _initialize_frame (void)
2021 {
2022 obstack_init (&frame_cache_obstack);
2023
2024 observer_attach_target_changed (frame_observer_target_changed);
2025
2026 add_prefix_cmd ("backtrace", class_maintenance, set_backtrace_cmd, _("\
2027 Set backtrace specific variables.\n\
2028 Configure backtrace variables such as the backtrace limit"),
2029 &set_backtrace_cmdlist, "set backtrace ",
2030 0/*allow-unknown*/, &setlist);
2031 add_prefix_cmd ("backtrace", class_maintenance, show_backtrace_cmd, _("\
2032 Show backtrace specific variables\n\
2033 Show backtrace variables such as the backtrace limit"),
2034 &show_backtrace_cmdlist, "show backtrace ",
2035 0/*allow-unknown*/, &showlist);
2036
2037 add_setshow_boolean_cmd ("past-main", class_obscure,
2038 &backtrace_past_main, _("\
2039 Set whether backtraces should continue past \"main\"."), _("\
2040 Show whether backtraces should continue past \"main\"."), _("\
2041 Normally the caller of \"main\" is not of interest, so GDB will terminate\n\
2042 the backtrace at \"main\". Set this variable if you need to see the rest\n\
2043 of the stack trace."),
2044 NULL,
2045 show_backtrace_past_main,
2046 &set_backtrace_cmdlist,
2047 &show_backtrace_cmdlist);
2048
2049 add_setshow_boolean_cmd ("past-entry", class_obscure,
2050 &backtrace_past_entry, _("\
2051 Set whether backtraces should continue past the entry point of a program."),
2052 _("\
2053 Show whether backtraces should continue past the entry point of a program."),
2054 _("\
2055 Normally there are no callers beyond the entry point of a program, so GDB\n\
2056 will terminate the backtrace there. Set this variable if you need to see \n\
2057 the rest of the stack trace."),
2058 NULL,
2059 show_backtrace_past_entry,
2060 &set_backtrace_cmdlist,
2061 &show_backtrace_cmdlist);
2062
2063 add_setshow_integer_cmd ("limit", class_obscure,
2064 &backtrace_limit, _("\
2065 Set an upper bound on the number of backtrace levels."), _("\
2066 Show the upper bound on the number of backtrace levels."), _("\
2067 No more than the specified number of frames can be displayed or examined.\n\
2068 Zero is unlimited."),
2069 NULL,
2070 show_backtrace_limit,
2071 &set_backtrace_cmdlist,
2072 &show_backtrace_cmdlist);
2073
2074 /* Debug this files internals. */
2075 add_setshow_zinteger_cmd ("frame", class_maintenance, &frame_debug, _("\
2076 Set frame debugging."), _("\
2077 Show frame debugging."), _("\
2078 When non-zero, frame specific internal debugging is enabled."),
2079 NULL,
2080 show_frame_debug,
2081 &setdebuglist, &showdebuglist);
2082 }
This page took 0.082944 seconds and 4 git commands to generate.