/* Cache and manage frames for GDB, the GNU debugger.
Copyright (C) 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000, 2001,
- 2002, 2003, 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
+ Free Software Foundation, Inc.
This file is part of GDB.
show_backtrace_past_main (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("\
-Whether backtraces should continue past \"main\" is %s.\n"),
+ fprintf_filtered (file,
+ _("Whether backtraces should "
+ "continue past \"main\" is %s.\n"),
value);
}
show_backtrace_past_entry (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("\
-Whether backtraces should continue past the entry point of a program is %s.\n"),
+ fprintf_filtered (file, _("Whether backtraces should continue past the "
+ "entry point of a program is %s.\n"),
value);
}
show_backtrace_limit (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("\
-An upper bound on the number of backtrace levels is %s.\n"),
+ fprintf_filtered (file,
+ _("An upper bound on the number "
+ "of backtrace levels is %s.\n"),
value);
}
fi->level);
/* Find the unwinder. */
if (fi->unwind == NULL)
- fi->unwind = frame_unwind_find_by_frame (fi, &fi->prologue_cache);
+ frame_unwind_find_by_frame (fi, &fi->prologue_cache);
/* Find THIS frame's ID. */
/* Default to outermost if no ID is found. */
fi->this_id.value = outer_frame_id;
CORE_ADDR special_addr)
{
struct frame_id id = null_frame_id;
+
id.stack_addr = stack_addr;
id.stack_addr_p = 1;
id.code_addr = code_addr;
frame_id_build (CORE_ADDR stack_addr, CORE_ADDR code_addr)
{
struct frame_id id = null_frame_id;
+
id.stack_addr = stack_addr;
id.stack_addr_p = 1;
id.code_addr = code_addr;
frame_id_build_wild (CORE_ADDR stack_addr)
{
struct frame_id id = null_frame_id;
+
id.stack_addr = stack_addr;
id.stack_addr_p = 1;
return id;
frame_id_p (struct frame_id l)
{
int p;
+
/* The frame is valid iff it has a valid stack address. */
p = l.stack_addr_p;
/* outer_frame_id is also valid. */
frame_id_eq (struct frame_id l, struct frame_id r)
{
int eq;
- if (!l.stack_addr_p && l.special_addr_p && !r.stack_addr_p && r.special_addr_p)
+
+ if (!l.stack_addr_p && l.special_addr_p
+ && !r.stack_addr_p && r.special_addr_p)
/* The outermost frame marker is equal to itself. This is the
dodgy thing about outer_frame_id, since between execution steps
we might step into another function - from which we can't
to sigaltstack).
However, it can be used as safety net to discover invalid frame
- IDs in certain circumstances. Assuming that NEXT is the immediate
+ IDs in certain circumstances. Assuming that NEXT is the immediate
inner frame to THIS and that NEXT and THIS are both NORMAL frames:
* The stack address of NEXT must be inner-than-or-equal to the stack
is involved, because signal handlers might be executed on a different
stack than the stack used by the routine that caused the signal
to be raised. This can happen for instance when a thread exceeds
- its maximum stack size. In this case, certain compilers implement
+ its maximum stack size. In this case, certain compilers implement
a stack overflow strategy that cause the handler to be run on a
different stack. */
frame_id_inner (struct gdbarch *gdbarch, struct frame_id l, struct frame_id r)
{
int inner;
+
if (!l.stack_addr_p || !r.stack_addr_p)
/* Like NaN, any operation involving an invalid ID always fails. */
inner = 0;
for (frame = get_current_frame (); ; frame = prev_frame)
{
struct frame_id this = get_frame_id (frame);
+
if (frame_id_eq (id, this))
/* An exact match. */
return frame;
if (!this_frame->prev_pc.p)
{
CORE_ADDR pc;
+
if (gdbarch_unwind_pc_p (frame_unwind_arch (this_frame)))
{
/* The right way. The `pure' way. The one true way. This
this_frame->prev_pc.p = 1;
if (frame_debug)
fprintf_unfiltered (gdb_stdlog,
- "{ frame_unwind_caller_pc (this_frame=%d) -> %s }\n",
+ "{ frame_unwind_caller_pc "
+ "(this_frame=%d) -> %s }\n",
this_frame->level,
hex_string (this_frame->prev_pc.value));
}
return next_frame->prev_func.addr;
}
-static int
+static enum register_status
do_frame_register_read (void *src, int regnum, gdb_byte *buf)
{
- return frame_register_read (src, regnum, buf);
+ if (!frame_register_read (src, regnum, buf))
+ return REG_UNAVAILABLE;
+ else
+ return REG_VALID;
}
struct regcache *
struct regcache *regcache = regcache_xmalloc (get_frame_arch (this_frame),
aspace);
struct cleanup *cleanups = make_cleanup_regcache_xfree (regcache);
+
regcache_save (regcache, do_frame_register_read, this_frame);
discard_cleanups (cleanups);
return regcache;
*addrp = value_address (value);
*realnump = VALUE_REGNUM (value);
- if (bufferp)
+ if (bufferp && !*optimizedp)
memcpy (bufferp, value_contents_all (value),
TYPE_LENGTH (value_type (value)));
CORE_ADDR addr;
int realnum;
enum lval_type lval;
+
frame_register_unwind (frame, regnum, &optimized, &lval, &addr,
&realnum, buf);
}
if (frame_debug)
{
- fprintf_unfiltered (gdb_stdlog, "\
-{ frame_unwind_register_value (frame=%d,regnum=%d(%s),...) ",
+ fprintf_unfiltered (gdb_stdlog,
+ "{ frame_unwind_register_value "
+ "(frame=%d,regnum=%d(%s),...) ",
frame->level, regnum,
user_reg_map_regnum_to_name (gdbarch, regnum));
}
/* Find the unwinder. */
if (frame->unwind == NULL)
- frame->unwind = frame_unwind_find_by_frame (frame, &frame->prologue_cache);
+ frame_unwind_find_by_frame (frame, &frame->prologue_cache);
/* Ask this frame to unwind its register. */
value = frame->unwind->prev_register (frame, &frame->prologue_cache, regnum);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
int size = register_size (gdbarch, regnum);
gdb_byte buf[MAX_REGISTER_SIZE];
+
frame_unwind_register (frame, regnum, buf);
return extract_signed_integer (buf, size, byte_order);
}
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
int size = register_size (gdbarch, regnum);
gdb_byte buf[MAX_REGISTER_SIZE];
+
frame_unwind_register (frame, regnum, buf);
return extract_unsigned_integer (buf, size, byte_order);
}
int optim;
enum lval_type lval;
CORE_ADDR addr;
+
frame_register (frame, regnum, &optim, &lval, &addr, &realnum, NULL);
if (optim)
error (_("Attempt to assign to a value that was optimized out."));
/* FIXME: write_memory doesn't yet take constant buffers.
Arrrg! */
gdb_byte tmp[MAX_REGISTER_SIZE];
+
memcpy (tmp, buf, register_size (gdbarch, regnum));
write_memory (addr, tmp, register_size (gdbarch, regnum));
break;
enum lval_type lval;
CORE_ADDR addr;
int realnum;
+
frame_register (frame, regnum, &optimized, &lval, &addr, &realnum, myaddr);
return !optimized;
for (i = regnum; i < numregs; i++)
{
int thissize = register_size (gdbarch, i);
+
if (thissize == 0)
break; /* This register is not available on this architecture. */
maxsize += thissize;
while (len > 0)
{
int curr_len = register_size (gdbarch, regnum) - offset;
+
if (curr_len > len)
curr_len = len;
else
{
gdb_byte buf[MAX_REGISTER_SIZE];
+
if (!frame_register_read (frame, regnum, buf))
return 0;
memcpy (myaddr, buf + offset, curr_len);
while (len > 0)
{
int curr_len = register_size (gdbarch, regnum) - offset;
+
if (curr_len > len)
curr_len = len;
else
{
gdb_byte buf[MAX_REGISTER_SIZE];
+
frame_register_read (frame, regnum, buf);
memcpy (buf + offset, myaddr, curr_len);
put_frame_register (frame, regnum, buf);
create_sentinel_frame (struct program_space *pspace, struct regcache *regcache)
{
struct frame_info *frame = FRAME_OBSTACK_ZALLOC (struct frame_info);
+
frame->level = -1;
frame->pspace = pspace;
frame->aspace = get_regcache_aspace (regcache);
information, such as the frame's thread will be added. */
frame->prologue_cache = sentinel_frame_cache (regcache);
/* For the moment there is only one sentinel frame implementation. */
- frame->unwind = sentinel_frame_unwind;
+ frame->unwind = &sentinel_frame_unwind;
/* Link this frame back to itself. The frame is self referential
(the unwound PC is the same as the pc), so make it so. */
frame->next = frame;
return frame;
}
-/* Info about the innermost stack frame (contents of FP register) */
+/* Info about the innermost stack frame (contents of FP register). */
static struct frame_info *current_frame;
frame_obstack_zalloc (unsigned long size)
{
void *data = obstack_alloc (&frame_cache_obstack, size);
+
memset (data, 0, size);
return data;
}
unwind_to_current_frame (struct ui_out *ui_out, void *args)
{
struct frame_info *frame = get_prev_frame (args);
+
/* A sentinel frame can fail to unwind, e.g., because its PC value
lands in somewhere like start. */
if (frame == NULL)
return selected_frame;
}
+/* If there is a selected frame, return it. Otherwise, return NULL. */
+
+struct frame_info *
+get_selected_frame_if_set (void)
+{
+ return selected_frame;
+}
+
/* This is a variant of get_selected_frame() which can be called when
the inferior does not have a frame; in that case it will return
NULL instead of calling error(). */
Once we have frame-parameterized frame (and frame-related) commands,
the event notification can be moved here, since this function will only
- be called when the user's selected frame is being changed. */
+ be called when the user's selected frame is being changed. */
/* Ensure that symbols for this frame are read in. Also, determine the
source language of this frame, and switch to it if desired. */
fi = FRAME_OBSTACK_ZALLOC (struct frame_info);
- fi->next = create_sentinel_frame (current_program_space, get_current_regcache ());
+ fi->next = create_sentinel_frame (current_program_space,
+ get_current_regcache ());
/* Set/update this frame's cached PC value, found in the next frame.
Do this before looking for this frame's unwinder. A sniffer is
/* Select/initialize both the unwind function and the frame's type
based on the PC. */
- fi->unwind = frame_unwind_find_by_frame (fi, &fi->prologue_cache);
+ frame_unwind_find_by_frame (fi, &fi->prologue_cache);
fi->this_id.p = 1;
fi->this_id.value = frame_id_build (addr, pc);
fi->base->unwind->dealloc_cache (fi, fi->base_cache);
}
- /* Since we can't really be sure what the first object allocated was */
+ /* Since we can't really be sure what the first object allocated was. */
obstack_free (&frame_cache_obstack, 0);
obstack_init (&frame_cache_obstack);
sniffers will think that this frame's sniffer tried to unwind
further (see frame_cleanup_after_sniffer). */
if (this_frame->unwind == NULL)
- this_frame->unwind
- = frame_unwind_find_by_frame (this_frame, &this_frame->prologue_cache);
+ frame_unwind_find_by_frame (this_frame, &this_frame->prologue_cache);
this_frame->prev_p = 1;
this_frame->stop_reason = UNWIND_NO_REASON;
&& frame_id_inner (get_frame_arch (this_frame->next), this_id,
get_frame_id (this_frame->next)))
{
- if (frame_debug)
+ CORE_ADDR this_pc_in_block;
+ struct minimal_symbol *morestack_msym;
+ const char *morestack_name = NULL;
+
+ /* gcc -fsplit-stack __morestack can continue the stack anywhere. */
+ this_pc_in_block = get_frame_address_in_block (this_frame);
+ morestack_msym = lookup_minimal_symbol_by_pc (this_pc_in_block);
+ if (morestack_msym)
+ morestack_name = SYMBOL_LINKAGE_NAME (morestack_msym);
+ if (!morestack_name || strcmp (morestack_name, "__morestack") != 0)
{
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame (gdb_stdlog, NULL);
- fprintf_unfiltered (gdb_stdlog, " // this frame ID is inner }\n");
+ if (frame_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog, "-> ");
+ fprint_frame (gdb_stdlog, NULL);
+ fprintf_unfiltered (gdb_stdlog,
+ " // this frame ID is inner }\n");
+ }
+ this_frame->stop_reason = UNWIND_INNER_ID;
+ return NULL;
}
- this_frame->stop_reason = UNWIND_INNER_ID;
- return NULL;
}
/* Check that this and the next frame are not identical. If they
else
sym = inline_skipped_symbol (inferior_ptid);
+ /* If frame is inline, it certainly has symbols. */
+ gdb_assert (sym);
init_sal (sal);
if (SYMBOL_LINE (sym) != 0)
{
frame_unwinder_is (struct frame_info *fi, const struct frame_unwind *unwinder)
{
if (fi->unwind == NULL)
- fi->unwind = frame_unwind_find_by_frame (fi, &fi->prologue_cache);
+ frame_unwind_find_by_frame (fi, &fi->prologue_cache);
return fi->unwind == unwinder;
}
if (frame->unwind == NULL)
/* Initialize the frame's unwinder because that's what
provides the frame's type. */
- frame->unwind = frame_unwind_find_by_frame (frame, &frame->prologue_cache);
+ frame_unwind_find_by_frame (frame, &frame->prologue_cache);
return frame->unwind->type;
}
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
return read_memory_integer (addr, len, byte_order);
}
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
return read_memory_unsigned_integer (addr, len, byte_order);
}
struct gdbarch *arch;
if (next_frame->unwind == NULL)
- next_frame->unwind
- = frame_unwind_find_by_frame (next_frame,
- &next_frame->prologue_cache);
+ frame_unwind_find_by_frame (next_frame, &next_frame->prologue_cache);
if (next_frame->unwind->prev_arch != NULL)
arch = next_frame->unwind->prev_arch (next_frame,
get_frame_sp (struct frame_info *this_frame)
{
struct gdbarch *gdbarch = get_frame_arch (this_frame);
+
/* Normality - an architecture that provides a way of obtaining any
frame inner-most address. */
if (gdbarch_unwind_sp_p (gdbarch))
Show whether backtraces should continue past the entry point of a program."),
_("\
Normally there are no callers beyond the entry point of a program, so GDB\n\
-will terminate the backtrace there. Set this variable if you need to see \n\
+will terminate the backtrace there. Set this variable if you need to see\n\
the rest of the stack trace."),
NULL,
show_backtrace_past_entry,
&set_backtrace_cmdlist,
&show_backtrace_cmdlist);
- /* Debug this files internals. */
+ /* Debug this files internals. */
add_setshow_zinteger_cmd ("frame", class_maintenance, &frame_debug, _("\
Set frame debugging."), _("\
Show frame debugging."), _("\