aboutsummaryrefslogtreecommitdiff
path: root/gdb/frame.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2013-12-06 19:48:00 +0000
committerPedro Alves <palves@redhat.com>2013-12-06 19:50:10 +0000
commit782d47dfbdfde099cccd06a944e843368cccda76 (patch)
tree0c7a765c7696e7653a2b00659b214d215be87e50 /gdb/frame.c
parent710409a221f27f39d8b8e33c5676c97cb04cf4b8 (diff)
downloadgdb-782d47dfbdfde099cccd06a944e843368cccda76.zip
gdb-782d47dfbdfde099cccd06a944e843368cccda76.tar.gz
gdb-782d47dfbdfde099cccd06a944e843368cccda76.tar.bz2
Fix "info frame" in the outermost frame.
Doing "info frame" in the outermost frame, when that was indicated by the next frame saying the unwound PC is undefined/not saved, results in error and incomplete output: (gdb) bt #0 thread_function0 (arg=0x0) at threads.c:63 #1 0x00000034cf407d14 in start_thread (arg=0x7ffff7fcb700) at pthread_create.c:309 #2 0x000000323d4f168d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115 (gdb) frame 2 #2 0x000000323d4f168d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115 115 call *%rax (gdb) info frame Stack level 2, frame at 0x0: rip = 0x323d4f168d in clone (../sysdeps/unix/sysv/linux/x86_64/clone.S:115); saved rip Register 16 was not saved (gdb) Not saved register values are treated as optimized out values internally throughout. stack.c:frame_info is handing unvailable values, but not optimized out ones. The patch deletes the frame_unwind_caller_pc_if_available wrapper function and instead lets errors propagate to frame_info (it's only user). As frame_unwind_pc now needs to be able to handle and cache two different error scenarios, the prev_pc.p variable is replaced with an enumeration. (FWIW, I looked into making gdbarch_unwind_pc or a variant return struct value's instead, but it results in lots of boxing and unboxing for no real gain -- e.g., the mips and arm implementations need to do computation on the unboxed PC value. Might as well throw an error on first attempt to get at invalid contents.) After the patch, we get: (gdb) info frame Stack level 2, frame at 0x0: rip = 0x323d4f168d in clone (../sysdeps/unix/sysv/linux/x86_64/clone.S:115); saved rip = <not saved> Outermost frame: outermost caller of frame at 0x7ffff7fcafc0 source language asm. Arglist at 0x7ffff7fcafb8, args: Locals at 0x7ffff7fcafb8, Previous frame's sp is 0x7ffff7fcafc8 (gdb) A new test is added. It's based off dw2-reg-undefined.exp, and tweaked to mark the return address (rip) of "stop_frame" as undefined. Tested on x86_64 Fedora 17. gdb/ 2013-12-06 Pedro Alves <palves@redhat.com> * frame.c (enum cached_copy_status): New enum. (struct frame_info) <prev_pc.p>: Change type to enum cached_copy_status. (fprint_frame): Handle not saved and unavailable prev_pc values. (frame_unwind_pc_if_available): Delete and merge contents into ... (frame_unwind_pc): ... here. Handle OPTIMIZED_OUT_ERROR. Adjust to use enum cached_copy_status. (frame_unwind_caller_pc_if_available): Delete. (create_new_frame): Adjust. * frame.h (frame_unwind_caller_pc_if_available): Delete declaration. * stack.c (frame_info): Use frame_unwind_caller_pc instead of frame_unwind_caller_pc_if_available, and handle NOT_AVAILABLE_ERROR and OPTIMIZED_OUT_ERROR errors. * valprint.c (val_print_optimized_out): Use val_print_not_saved. (val_print_not_saved): New function. * valprint.h (val_print_not_saved): Declare. gdb/testsuite/ 2013-12-06 Pedro Alves <palves@redhat.com> * gdb.dwarf2/dw2-undefined-ret-addr.S: New file. * gdb.dwarf2/dw2-undefined-ret-addr.c: New file. * gdb.dwarf2/dw2-undefined-ret-addr.exp: New file.
Diffstat (limited to 'gdb/frame.c')
-rw-r--r--gdb/frame.c108
1 files changed, 62 insertions, 46 deletions
diff --git a/gdb/frame.c b/gdb/frame.c
index 0ba1d4d..6a8b5ae 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -50,6 +50,23 @@ static struct frame_info *get_prev_frame_1 (struct frame_info *this_frame);
static struct frame_info *get_prev_frame_raw (struct frame_info *this_frame);
static const char *frame_stop_reason_symbol_string (enum unwind_stop_reason reason);
+/* Status of some values cached in the frame_info object. */
+
+enum cached_copy_status
+{
+ /* Value is unknown. */
+ CC_UNKNOWN,
+
+ /* We have a value. */
+ CC_VALUE,
+
+ /* Value was not saved. */
+ CC_NOT_SAVED,
+
+ /* Value is unavailable. */
+ CC_UNAVAILABLE
+};
+
/* We keep a cache of stack frames, each of which is a "struct
frame_info". The innermost one gets allocated (in
wait_for_inferior) each time the inferior stops; current_frame
@@ -96,7 +113,7 @@ struct frame_info
/* Cached copy of the previous frame's resume address. */
struct {
- int p;
+ enum cached_copy_status status;
CORE_ADDR value;
} prev_pc;
@@ -366,10 +383,15 @@ fprint_frame (struct ui_file *file, struct frame_info *fi)
fprintf_unfiltered (file, "<unknown>");
fprintf_unfiltered (file, ",");
fprintf_unfiltered (file, "pc=");
- if (fi->next != NULL && fi->next->prev_pc.p)
- fprintf_unfiltered (file, "%s", hex_string (fi->next->prev_pc.value));
- else
+ if (fi->next == NULL || fi->next->prev_pc.status == CC_UNKNOWN)
fprintf_unfiltered (file, "<unknown>");
+ else if (fi->next->prev_pc.status == CC_VALUE)
+ fprintf_unfiltered (file, "%s",
+ hex_string (fi->next->prev_pc.value));
+ else if (fi->next->prev_pc.status == CC_NOT_SAVED)
+ val_print_not_saved (file);
+ else if (fi->next->prev_pc.status == CC_UNAVAILABLE)
+ val_print_unavailable (file);
fprintf_unfiltered (file, ",");
fprintf_unfiltered (file, "id=");
if (fi->this_id.p)
@@ -707,10 +729,10 @@ frame_find_by_id (struct frame_id id)
return NULL;
}
-static int
-frame_unwind_pc_if_available (struct frame_info *this_frame, CORE_ADDR *pc)
+static CORE_ADDR
+frame_unwind_pc (struct frame_info *this_frame)
{
- if (!this_frame->prev_pc.p)
+ if (this_frame->prev_pc.status == CC_UNKNOWN)
{
if (gdbarch_unwind_pc_p (frame_unwind_arch (this_frame)))
{
@@ -740,24 +762,35 @@ frame_unwind_pc_if_available (struct frame_info *this_frame, CORE_ADDR *pc)
{
pc = gdbarch_unwind_pc (prev_gdbarch, this_frame);
}
- if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
+ if (ex.reason < 0)
{
- this_frame->prev_pc.p = -1;
-
- if (frame_debug)
- fprintf_unfiltered (gdb_stdlog,
- "{ frame_unwind_pc (this_frame=%d)"
- " -> <unavailable> }\n",
- this_frame->level);
- }
- else if (ex.reason < 0)
- {
- throw_exception (ex);
+ if (ex.error == NOT_AVAILABLE_ERROR)
+ {
+ this_frame->prev_pc.status = CC_UNAVAILABLE;
+
+ if (frame_debug)
+ fprintf_unfiltered (gdb_stdlog,
+ "{ frame_unwind_pc (this_frame=%d)"
+ " -> <unavailable> }\n",
+ this_frame->level);
+ }
+ else if (ex.error == OPTIMIZED_OUT_ERROR)
+ {
+ this_frame->prev_pc.status = CC_NOT_SAVED;
+
+ if (frame_debug)
+ fprintf_unfiltered (gdb_stdlog,
+ "{ frame_unwind_pc (this_frame=%d)"
+ " -> <not saved> }\n",
+ this_frame->level);
+ }
+ else
+ throw_exception (ex);
}
else
{
this_frame->prev_pc.value = pc;
- this_frame->prev_pc.p = 1;
+ this_frame->prev_pc.status = CC_VALUE;
if (frame_debug)
fprintf_unfiltered (gdb_stdlog,
"{ frame_unwind_pc (this_frame=%d) "
@@ -769,27 +802,17 @@ frame_unwind_pc_if_available (struct frame_info *this_frame, CORE_ADDR *pc)
else
internal_error (__FILE__, __LINE__, _("No unwind_pc method"));
}
- if (this_frame->prev_pc.p < 0)
- {
- *pc = -1;
- return 0;
- }
- else
- {
- *pc = this_frame->prev_pc.value;
- return 1;
- }
-}
-static CORE_ADDR
-frame_unwind_pc (struct frame_info *this_frame)
-{
- CORE_ADDR pc;
-
- if (!frame_unwind_pc_if_available (this_frame, &pc))
+ if (this_frame->prev_pc.status == CC_VALUE)
+ return this_frame->prev_pc.value;
+ else if (this_frame->prev_pc.status == CC_UNAVAILABLE)
throw_error (NOT_AVAILABLE_ERROR, _("PC not available"));
+ else if (this_frame->prev_pc.status == CC_NOT_SAVED)
+ throw_error (OPTIMIZED_OUT_ERROR, _("PC not saved"));
else
- return pc;
+ internal_error (__FILE__, __LINE__,
+ "unexpected prev_pc status: %d",
+ (int) this_frame->prev_pc.status);
}
CORE_ADDR
@@ -799,13 +822,6 @@ frame_unwind_caller_pc (struct frame_info *this_frame)
}
int
-frame_unwind_caller_pc_if_available (struct frame_info *this_frame,
- CORE_ADDR *pc)
-{
- return frame_unwind_pc_if_available (skip_artificial_frames (this_frame), pc);
-}
-
-int
get_frame_func_if_available (struct frame_info *this_frame, CORE_ADDR *pc)
{
struct frame_info *next_frame = this_frame->next;
@@ -1572,7 +1588,7 @@ create_new_frame (CORE_ADDR addr, CORE_ADDR pc)
very likely to read this, and the corresponding unwinder is
entitled to rely that the PC doesn't magically change. */
fi->next->prev_pc.value = pc;
- fi->next->prev_pc.p = 1;
+ fi->next->prev_pc.status = CC_VALUE;
/* We currently assume that frame chain's can't cross spaces. */
fi->pspace = fi->next->pspace;