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