/* Cache and manage frames for GDB, the GNU debugger.
- Copyright (C) 1986-2020 Free Software Foundation, Inc.
+ Copyright (C) 1986-2021 Free Software Foundation, Inc.
This file is part of GDB.
value);
}
+/* See frame.h. */
-static void
-fprint_field (struct ui_file *file, const char *name, int p, CORE_ADDR addr)
+std::string
+frame_id::to_string () const
{
- if (p)
- fprintf_unfiltered (file, "%s=%s", name, hex_string (addr));
- else
- fprintf_unfiltered (file, "!%s", name);
-}
+ const struct frame_id &id = *this;
-void
-fprint_frame_id (struct ui_file *file, struct frame_id id)
-{
- fprintf_unfiltered (file, "{");
+ std::string res = "{";
if (id.stack_status == FID_STACK_INVALID)
- fprintf_unfiltered (file, "!stack");
+ res += "!stack";
else if (id.stack_status == FID_STACK_UNAVAILABLE)
- fprintf_unfiltered (file, "stack=<unavailable>");
+ res += "stack=<unavailable>";
else if (id.stack_status == FID_STACK_SENTINEL)
- fprintf_unfiltered (file, "stack=<sentinel>");
+ res += "stack=<sentinel>";
else if (id.stack_status == FID_STACK_OUTER)
- fprintf_unfiltered (file, "stack=<outer>");
+ res += "stack=<outer>";
else
- fprintf_unfiltered (file, "stack=%s", hex_string (id.stack_addr));
-
- fprintf_unfiltered (file, ",");
+ res += std::string ("stack=") + hex_string (id.stack_addr);
- fprint_field (file, "code", id.code_addr_p, id.code_addr);
- fprintf_unfiltered (file, ",");
+ /* Helper function to format 'N=A' if P is true, otherwise '!N'. */
+ auto field_to_string = [] (const char *n, bool p, CORE_ADDR a) -> std::string
+ {
+ if (p)
+ return std::string (n) + "=" + core_addr_to_string (a);
+ else
+ return std::string ("!") + std::string (n);
+ };
- fprint_field (file, "special", id.special_addr_p, id.special_addr);
+ res += (std::string (",")
+ + field_to_string ("code", id.code_addr_p, id.code_addr)
+ + std::string (",")
+ + field_to_string ("special", id.special_addr_p, id.special_addr));
if (id.artificial_depth)
- fprintf_unfiltered (file, ",artificial=%d", id.artificial_depth);
-
- fprintf_unfiltered (file, "}");
+ res += ",artificial=" + std::to_string (id.artificial_depth);
+ res += "}";
+ return res;
}
static void
else if (fi->this_id.p == frame_id_status::COMPUTING)
fprintf_unfiltered (file, "<computing>");
else
- fprint_frame_id (file, fi->this_id.value);
+ fprintf_unfiltered (file, "%s", fi->this_id.value.to_string ().c_str ());
fprintf_unfiltered (file, ",");
fprintf_unfiltered (file, "func=");
fi->this_id.p = frame_id_status::COMPUTED;
if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "-> ");
- fprint_frame_id (gdb_stdlog, fi->this_id.value);
- fprintf_unfiltered (gdb_stdlog, " }\n");
- }
+ fprintf_unfiltered (gdb_stdlog, "-> %s }\n",
+ fi->this_id.value.to_string ().c_str ());
}
catch (const gdb_exception &ex)
{
bool p = l.stack_status != FID_STACK_INVALID;
if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "{ frame_id_p (l=");
- fprint_frame_id (gdb_stdlog, l);
- fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", p);
- }
+ fprintf_unfiltered (gdb_stdlog, "{ frame_id_p (l=%s) -> %d }\n",
+ l.to_string ().c_str (), p);
return p;
}
eq = true;
if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "{ frame_id_eq (l=");
- fprint_frame_id (gdb_stdlog, l);
- fprintf_unfiltered (gdb_stdlog, ",r=");
- fprint_frame_id (gdb_stdlog, r);
- fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", eq);
- }
+ fprintf_unfiltered (gdb_stdlog, "{ frame_id_eq (l=%s,r=%s) -> %d }\n",
+ l.to_string ().c_str (), r.to_string ().c_str (), eq);
return eq;
}
inner = gdbarch_inner_than (gdbarch, l.stack_addr, r.stack_addr);
if (frame_debug)
- {
- fprintf_unfiltered (gdb_stdlog, "{ frame_id_inner (l=");
- fprint_frame_id (gdb_stdlog, l);
- fprintf_unfiltered (gdb_stdlog, ",r=");
- fprint_frame_id (gdb_stdlog, r);
- fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", inner);
- }
+ fprintf_unfiltered (gdb_stdlog, "{ frame_id_inner (l=%s,r=%s) -> %d }\n",
+ l.to_string ().c_str (), r.to_string ().c_str (),
+ inner);
return inner;
}
bool
get_frame_register_bytes (frame_info *frame, int regnum,
- CORE_ADDR offset, int len, gdb_byte *myaddr,
+ CORE_ADDR offset,
+ gdb::array_view<gdb_byte> buffer,
int *optimizedp, int *unavailablep)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
break; /* This register is not available on this architecture. */
maxsize += thissize;
}
+
+ int len = buffer.size ();
if (len > maxsize)
error (_("Bad debug information detected: "
"Attempt to read %d bytes from registers."), len);
if (curr_len > len)
curr_len = len;
+ gdb_byte *myaddr = buffer.data ();
+
if (curr_len == register_size (gdbarch, regnum))
{
enum lval_type lval;
void
put_frame_register_bytes (struct frame_info *frame, int regnum,
- CORE_ADDR offset, int len, const gdb_byte *myaddr)
+ CORE_ADDR offset,
+ gdb::array_view<const gdb_byte> buffer)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
regnum++;
}
+ int len = buffer.size ();
/* Copy the data. */
while (len > 0)
{
if (curr_len > len)
curr_len = len;
+ const gdb_byte *myaddr = buffer.data ();
if (curr_len == register_size (gdbarch, regnum))
{
put_frame_register (frame, regnum, myaddr);
/* Convert any function descriptor addresses into the actual function
code address. */
- sym_addr
- = gdbarch_convert_from_func_ptr_addr (get_frame_arch (this_frame),
- sym_addr, current_top_target ());
+ sym_addr = gdbarch_convert_from_func_ptr_addr
+ (get_frame_arch (this_frame), sym_addr, current_inferior ()->top_target ());
return sym_addr == get_frame_func (this_frame);
}
void
get_frame_memory (struct frame_info *this_frame, CORE_ADDR addr,
- gdb_byte *buf, int len)
+ gdb::array_view<gdb_byte> buffer)
{
- read_memory (addr, buf, len);
+ read_memory (addr, buffer.data (), buffer.size ());
}
LONGEST
bool
safe_frame_unwind_memory (struct frame_info *this_frame,
- CORE_ADDR addr, gdb_byte *buf, int len)
+ CORE_ADDR addr, gdb::array_view<gdb_byte> buffer)
{
/* NOTE: target_read_memory returns zero on success! */
- return target_read_memory (addr, buf, len) == 0;
+ return target_read_memory (addr, buffer.data (), buffer.size ()) == 0;
}
/* Architecture methods. */
frame_stash_create ();
- gdb::observers::target_changed.attach (frame_observer_target_changed);
+ gdb::observers::target_changed.attach (frame_observer_target_changed,
+ "frame");
add_basic_prefix_cmd ("backtrace", class_maintenance, _("\
Set backtrace specific variables.\n\
Configure backtrace variables such as the backtrace limit"),
- &set_backtrace_cmdlist, "set backtrace ",
+ &set_backtrace_cmdlist,
0/*allow-unknown*/, &setlist);
add_show_prefix_cmd ("backtrace", class_maintenance, _("\
Show backtrace specific variables.\n\
Show backtrace variables such as the backtrace limit."),
- &show_backtrace_cmdlist, "show backtrace ",
+ &show_backtrace_cmdlist,
0/*allow-unknown*/, &showlist);
add_setshow_uinteger_cmd ("limit", class_obscure,