#include "gdbcmd.h"
#include "observer.h"
#include "common/gdb_optional.h"
+#include "common/byte-vector.h"
#include <ctype.h>
#include "run-time-clock.h"
#include <chrono>
+#include "progspace-and-thread.h"
+#include "common/rsp-low.h"
enum
{
command was issued. */
int mi_proceeded;
-extern void _initialize_mi_main (void);
static void mi_cmd_execute (struct mi_parse *parse);
static void mi_execute_cli_command (const char *cmd, int args_p,
See comment on infcmd.c:proceed_thread_callback for rationale. */
if (current_context->all || current_context->thread_group != -1)
{
+ scoped_restore_current_thread restore_thread;
int pid = 0;
- struct cleanup *back_to = make_cleanup_restore_current_thread ();
if (!current_context->all)
{
pid = inf->pid;
}
iterate_over_threads (proceed_thread_callback, &pid);
- do_cleanups (back_to);
}
else
{
if (current_context->all)
{
- struct cleanup *back_to = save_current_space_and_thread ();
+ scoped_restore_current_pspace_and_thread restore_pspace_thread;
iterate_over_inferiors (run_one_inferior, &start_p);
- do_cleanups (back_to);
}
else
{
if (!VEC_empty (int, data.cores))
{
int *b, *e;
- struct cleanup *back_to_2 =
- make_cleanup_ui_out_list_begin_end (uiout, "cores");
+ ui_out_emit_list list_emitter (uiout, "cores");
qsort (VEC_address (int, data.cores),
VEC_length (int, data.cores), sizeof (int),
for (; b != e; ++b)
uiout->field_int (NULL, *b);
-
- do_cleanups (back_to_2);
}
if (top_data->recurse)
static void
output_cores (struct ui_out *uiout, const char *field_name, const char *xcores)
{
- struct cleanup *back_to = make_cleanup_ui_out_list_begin_end (uiout,
- field_name);
- char *cores = xstrdup (xcores);
- char *p = cores;
-
- make_cleanup (xfree, cores);
+ ui_out_emit_list list_emitter (uiout, field_name);
+ gdb::unique_xmalloc_ptr<char> cores (xstrdup (xcores));
+ char *p = cores.get ();
for (p = strtok (p, ","); p; p = strtok (NULL, ","))
uiout->field_string (NULL, p);
-
- do_cleanups (back_to);
}
static void
}
}
- make_cleanup_ui_out_list_begin_end (uiout, "groups");
+ ui_out_emit_list list_emitter (uiout, "groups");
for (ix_items = 0;
VEC_iterate (osdata_item_s, data->items,
struct osdata_item *child;
int ix_child;
- make_cleanup_ui_out_list_begin_end (uiout, "threads");
+ ui_out_emit_list thread_list_emitter (uiout, "threads");
for (ix_child = 0;
VEC_iterate (osdata_item_s, children, ix_child, child);
print everything, or several explicit ids. In both cases,
we print more than one group, and have to use 'groups'
as the top-level element. */
- make_cleanup_ui_out_list_begin_end (uiout, "groups");
+ ui_out_emit_list list_emitter (uiout, "groups");
update_thread_list ();
iterate_over_inferiors (print_one_inferior, &data);
}
struct ui_out *uiout = current_uiout;
int regnum, numregs;
int i;
- struct cleanup *cleanup;
/* Note that the test for a valid register must include checking the
gdbarch_register_name because gdbarch_num_regs may be allocated
gdbarch = get_current_arch ();
numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
- cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-names");
+ ui_out_emit_list list_emitter (uiout, "register-names");
if (argc == 0) /* No args, just do all the regs. */
{
else
uiout->field_string (NULL, gdbarch_register_name (gdbarch, regnum));
}
- do_cleanups (cleanup);
}
void
gdbarch = get_regcache_arch (this_regs);
numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
- make_cleanup_ui_out_list_begin_end (uiout, "changed-registers");
+ ui_out_emit_list list_emitter (uiout, "changed-registers");
if (argc == 0)
{
struct regcache *this_regs)
{
struct gdbarch *gdbarch = get_regcache_arch (this_regs);
- gdb_byte prev_buffer[MAX_REGISTER_SIZE];
- gdb_byte this_buffer[MAX_REGISTER_SIZE];
- enum register_status prev_status;
- enum register_status this_status;
+ struct value *prev_value, *this_value;
+ int ret;
/* First time through or after gdbarch change consider all registers
as changed. */
return 1;
/* Get register contents and compare. */
- prev_status = regcache_cooked_read (prev_regs, regnum, prev_buffer);
- this_status = regcache_cooked_read (this_regs, regnum, this_buffer);
+ prev_value = prev_regs->cooked_read_value (regnum);
+ this_value = this_regs->cooked_read_value (regnum);
+ gdb_assert (prev_value != NULL);
+ gdb_assert (this_value != NULL);
- if (this_status != prev_status)
- return 1;
- else if (this_status == REG_VALID)
- return memcmp (prev_buffer, this_buffer,
- register_size (gdbarch, regnum)) != 0;
- else
- return 0;
+ ret = value_contents_eq (prev_value, 0, this_value, 0,
+ register_size (gdbarch, regnum)) == 0;
+
+ release_value (prev_value);
+ release_value (this_value);
+ value_free (prev_value);
+ value_free (this_value);
+ return ret;
}
/* Return a list of register number and value pairs. The valid
struct gdbarch *gdbarch;
int regnum, numregs, format;
int i;
- struct cleanup *list_cleanup;
int skip_unavailable = 0;
int oind = 0;
enum opt
gdbarch = get_frame_arch (frame);
numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
- list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "register-values");
+ ui_out_emit_list list_emitter (uiout, "register-values");
if (argc - oind == 1)
{
else
error (_("bad register number"));
}
- do_cleanups (list_cleanup);
}
/* Output one register REGNUM's contents in the desired FORMAT. If
/* Create a buffer and read it in. */
total_bytes = word_size * nr_rows * nr_cols;
- std::unique_ptr<gdb_byte[]> mbuf (new gdb_byte[total_bytes]);
+ gdb::byte_vector mbuf (total_bytes);
/* Dispatch memory reads to the topmost target, not the flattened
current_target. */
nr_bytes = target_read (current_target.beneath,
- TARGET_OBJECT_MEMORY, NULL, mbuf.get (),
+ TARGET_OBJECT_MEMORY, NULL, mbuf.data (),
addr, total_bytes);
if (nr_bytes <= 0)
error (_("Unable to read memory."));
{
int row;
int row_byte;
- struct cleanup *cleanup_list;
string_file stream;
- cleanup_list = make_cleanup_ui_out_list_begin_end (uiout, "memory");
+ ui_out_emit_list list_emitter (uiout, "memory");
for (row = 0, row_byte = 0;
row < nr_rows;
row++, row_byte += nr_cols * word_size)
{
int col;
int col_byte;
- struct cleanup *cleanup_list_data;
struct value_print_options opts;
ui_out_emit_tuple tuple_emitter (uiout, NULL);
uiout->field_core_addr ("addr", gdbarch, addr + row_byte);
/* ui_out_field_core_addr_symbolic (uiout, "saddr", addr +
row_byte); */
- cleanup_list_data = make_cleanup_ui_out_list_begin_end (uiout, "data");
- get_formatted_print_options (&opts, word_format);
- for (col = 0, col_byte = row_byte;
- col < nr_cols;
- col++, col_byte += word_size)
- {
- if (col_byte + word_size > nr_bytes)
- {
- uiout->field_string (NULL, "N/A");
- }
- else
- {
- stream.clear ();
- print_scalar_formatted (&mbuf[col_byte], word_type, &opts,
- word_asize, &stream);
- uiout->field_stream (NULL, stream);
- }
- }
- do_cleanups (cleanup_list_data);
+ {
+ ui_out_emit_list list_data_emitter (uiout, "data");
+ get_formatted_print_options (&opts, word_format);
+ for (col = 0, col_byte = row_byte;
+ col < nr_cols;
+ col++, col_byte += word_size)
+ {
+ if (col_byte + word_size > nr_bytes)
+ {
+ uiout->field_string (NULL, "N/A");
+ }
+ else
+ {
+ stream.clear ();
+ print_scalar_formatted (&mbuf[col_byte], word_type, &opts,
+ word_asize, &stream);
+ uiout->field_stream (NULL, stream);
+ }
+ }
+ }
+
if (aschar)
{
int byte;
uiout->field_stream ("ascii", stream);
}
}
- do_cleanups (cleanup_list);
}
}
if (VEC_length (memory_read_result_s, result) == 0)
error (_("Unable to read memory."));
- make_cleanup_ui_out_list_begin_end (uiout, "memory");
+ ui_out_emit_list list_emitter (uiout, "memory");
for (ix = 0;
VEC_iterate (memory_read_result_s, result, ix, read_result);
++ix)
/* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
enough when using a compiler other than GCC. */
LONGEST value;
- gdb_byte *buffer;
- struct cleanup *old_chain;
long offset = 0;
int oind = 0;
char *oarg;
/* Get the value as a number. */
value = parse_and_eval_address (argv[3]);
/* Get the value into an array. */
- buffer = (gdb_byte *) xmalloc (word_size);
- old_chain = make_cleanup (xfree, buffer);
- store_signed_integer (buffer, word_size, byte_order, value);
+ gdb::byte_vector buffer (word_size);
+ store_signed_integer (buffer.data (), word_size, byte_order, value);
/* Write it down to memory. */
- write_memory_with_notification (addr, buffer, word_size);
- /* Free the buffer. */
- do_cleanups (old_chain);
+ write_memory_with_notification (addr, buffer.data (), word_size);
}
/* Implementation of the -data-write-memory-bytes command.
{
if (argc == 0)
{
- struct cleanup *cleanup = NULL;
struct ui_out *uiout = current_uiout;
- cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
+ ui_out_emit_list list_emitter (uiout, "features");
uiout->field_string (NULL, "frozen-varobjs");
uiout->field_string (NULL, "pending-breakpoints");
uiout->field_string (NULL, "thread-info");
if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
uiout->field_string (NULL, "python");
- do_cleanups (cleanup);
return;
}
{
if (argc == 0)
{
- struct cleanup *cleanup = NULL;
struct ui_out *uiout = current_uiout;
- cleanup = make_cleanup_ui_out_list_begin_end (uiout, "features");
+ ui_out_emit_list list_emitter (uiout, "features");
if (mi_async_p ())
uiout->field_string (NULL, "async");
if (target_can_execute_reverse)
uiout->field_string (NULL, "reverse");
- do_cleanups (cleanup);
return;
}
error (_("Invalid frame id: %d"), frame);
}
+ gdb::optional<scoped_restore_current_language> lang_saver;
if (parse->language != language_unknown)
{
- make_cleanup_restore_current_language ();
+ lang_saver.emplace ();
set_language (parse->language);
}
static char *previous_sect_name = NULL;
int new_section;
struct ui_out *saved_uiout;
- struct ui_out *uiout;
struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
/* This function is called through deprecated_show_load_progress
of this function. */
saved_uiout = current_uiout;
+ std::unique_ptr<ui_out> uiout;
+
if (current_interp_named_p (INTERP_MI)
|| current_interp_named_p (INTERP_MI2))
- current_uiout = mi_out_new (2);
+ uiout.reset (mi_out_new (2));
else if (current_interp_named_p (INTERP_MI1))
- current_uiout = mi_out_new (1);
+ uiout.reset (mi_out_new (1));
else if (current_interp_named_p (INTERP_MI3))
- current_uiout = mi_out_new (3);
+ uiout.reset (mi_out_new (3));
else
return;
- uiout = current_uiout;
+ current_uiout = uiout.get ();
new_section = (previous_sect_name ?
strcmp (previous_sect_name, section_name) : 1);
fputs_unfiltered (current_token, mi->raw_stdout);
fputs_unfiltered ("+download", mi->raw_stdout);
{
- ui_out_emit_tuple tuple_emitter (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout.get (), NULL);
uiout->field_string ("section", section_name);
uiout->field_int ("section-size", total_section);
uiout->field_int ("total-size", grand_total);
}
- mi_out_put (uiout, mi->raw_stdout);
+ mi_out_put (uiout.get (), mi->raw_stdout);
fputs_unfiltered ("\n", mi->raw_stdout);
gdb_flush (mi->raw_stdout);
}
fputs_unfiltered (current_token, mi->raw_stdout);
fputs_unfiltered ("+download", mi->raw_stdout);
{
- ui_out_emit_tuple tuple_emitter (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout.get (), NULL);
uiout->field_string ("section", section_name);
uiout->field_int ("section-sent", sent_so_far);
uiout->field_int ("section-size", total_section);
uiout->field_int ("total-sent", total_sent);
uiout->field_int ("total-size", grand_total);
}
- mi_out_put (uiout, mi->raw_stdout);
+ mi_out_put (uiout.get (), mi->raw_stdout);
fputs_unfiltered ("\n", mi->raw_stdout);
gdb_flush (mi->raw_stdout);
}
- xfree (uiout);
current_uiout = saved_uiout;
}
}
else if (strcmp (mode, "line") == 0)
{
- struct symtabs_and_lines sals;
- struct symtab_and_line sal;
- static CORE_ADDR start_pc, end_pc;
- struct cleanup *back_to;
-
if (argc != 2)
error (_("Line is required"));
- sals = decode_line_with_current_source (argv[1],
- DECODE_LINE_FUNFIRSTLINE);
- back_to = make_cleanup (xfree, sals.sals);
-
- sal = sals.sals[0];
+ std::vector<symtab_and_line> sals
+ = decode_line_with_current_source (argv[1],
+ DECODE_LINE_FUNFIRSTLINE);
+ const symtab_and_line &sal = sals[0];
if (sal.symtab == 0)
error (_("Could not find the specified line"));
+ CORE_ADDR start_pc, end_pc;
if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc))
tfind_1 (tfind_range, 0, start_pc, end_pc - 1, 0);
else
error (_("Could not find the specified line"));
-
- do_cleanups (back_to);
}
else
error (_("Invalid mode '%s'"), mode);
void
mi_cmd_trace_frame_collected (const char *command, char **argv, int argc)
{
- struct cleanup *old_chain;
struct bp_location *tloc;
int stepping_frame;
struct collection_list *clist;
/* This command only makes sense for the current frame, not the
selected frame. */
- old_chain = make_cleanup_restore_current_thread ();
+ scoped_restore_current_thread restore_thread;
select_frame (get_current_frame ());
encode_actions (tloc, &tracepoint_list, &stepping_list);
/* Explicitly wholly collected variables. */
{
- struct cleanup *list_cleanup;
int i;
- list_cleanup = make_cleanup_ui_out_list_begin_end (uiout,
- "explicit-variables");
-
+ ui_out_emit_list list_emitter (uiout, "explicit-variables");
const std::vector<std::string> &wholly_collected
= clist->wholly_collected ();
for (size_t i = 0; i < wholly_collected.size (); i++)
const std::string &str = wholly_collected[i];
print_variable_or_computed (str.c_str (), var_print_values);
}
-
- do_cleanups (list_cleanup);
}
/* Computed expressions. */
{
- struct cleanup *list_cleanup;
char *p;
int i;
- list_cleanup
- = make_cleanup_ui_out_list_begin_end (uiout,
- "computed-expressions");
+ ui_out_emit_list list_emitter (uiout, "computed-expressions");
const std::vector<std::string> &computed = clist->computed ();
for (size_t i = 0; i < computed.size (); i++)
const std::string &str = computed[i];
print_variable_or_computed (str.c_str (), comp_print_values);
}
-
- do_cleanups (list_cleanup);
}
/* Registers. Given pseudo-registers, and that some architectures
the trace frame info, but instead consult the register cache for
register availability. */
{
- struct cleanup *list_cleanup;
struct frame_info *frame;
struct gdbarch *gdbarch;
int regnum;
int numregs;
- list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "registers");
+ ui_out_emit_list list_emitter (uiout, "registers");
frame = get_selected_frame (NULL);
gdbarch = get_frame_arch (frame);
output_register (frame, regnum, registers_format, 1);
}
-
- do_cleanups (list_cleanup);
}
/* Trace state variables. */
{
- struct cleanup *list_cleanup;
+ struct cleanup *cleanups;
int tvar;
char *tsvname;
int i;
- list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "tvars");
+ ui_out_emit_list list_emitter (uiout, "tvars");
tsvname = NULL;
- make_cleanup (free_current_contents, &tsvname);
+ cleanups = make_cleanup (free_current_contents, &tsvname);
for (i = 0; VEC_iterate (int, tinfo->tvars, i, tvar); i++)
{
}
}
- do_cleanups (list_cleanup);
+ do_cleanups (cleanups);
}
/* Memory. */
{
- struct cleanup *list_cleanup;
+ struct cleanup *cleanups;
VEC(mem_range_s) *available_memory = NULL;
struct mem_range *r;
int i;
traceframe_available_memory (&available_memory, 0, ULONGEST_MAX);
- make_cleanup (VEC_cleanup(mem_range_s), &available_memory);
+ cleanups = make_cleanup (VEC_cleanup(mem_range_s), &available_memory);
- list_cleanup = make_cleanup_ui_out_list_begin_end (uiout, "memory");
+ ui_out_emit_list list_emitter (uiout, "memory");
for (i = 0; VEC_iterate (mem_range_s, available_memory, i, r); i++)
{
- struct cleanup *cleanup_child;
- gdb_byte *data;
struct gdbarch *gdbarch = target_gdbarch ();
- cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
uiout->field_core_addr ("address", gdbarch, r->start);
uiout->field_int ("length", r->length);
- data = (gdb_byte *) xmalloc (r->length);
- make_cleanup (xfree, data);
+ gdb::byte_vector data (r->length);
if (memory_contents)
{
- if (target_read_memory (r->start, data, r->length) == 0)
+ if (target_read_memory (r->start, data.data (), r->length) == 0)
{
- int m;
- char *data_str, *p;
-
- data_str = (char *) xmalloc (r->length * 2 + 1);
- make_cleanup (xfree, data_str);
-
- for (m = 0, p = data_str; m < r->length; ++m, p += 2)
- sprintf (p, "%02x", data[m]);
- uiout->field_string ("contents", data_str);
+ std::string data_str = bin2hex (data.data (), r->length);
+ uiout->field_string ("contents", data_str.c_str ());
}
else
uiout->field_skip ("contents");
}
- do_cleanups (cleanup_child);
}
- do_cleanups (list_cleanup);
+ do_cleanups (cleanups);
}
-
- do_cleanups (old_chain);
}
void