#include "extension.h"
#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,
const char *args);
-static void mi_execute_async_cli_command (char *cli_command,
+static void mi_execute_async_cli_command (const char *cli_command,
char **argv, int argc);
static int register_changed_p (int regnum, struct regcache *,
struct regcache *);
struct mi_timestamp *end);
void
-mi_cmd_gdb_exit (char *command, char **argv, int argc)
+mi_cmd_gdb_exit (const char *command, char **argv, int argc)
{
- struct mi_interp *mi
- = (struct mi_interp *) interp_data (current_interpreter ());
+ struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
/* We have to print everything right here because we never return. */
if (current_token)
}
void
-mi_cmd_exec_next (char *command, char **argv, int argc)
+mi_cmd_exec_next (const char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
}
void
-mi_cmd_exec_next_instruction (char *command, char **argv, int argc)
+mi_cmd_exec_next_instruction (const char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
}
void
-mi_cmd_exec_step (char *command, char **argv, int argc)
+mi_cmd_exec_step (const char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
}
void
-mi_cmd_exec_step_instruction (char *command, char **argv, int argc)
+mi_cmd_exec_step_instruction (const char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
}
void
-mi_cmd_exec_finish (char *command, char **argv, int argc)
+mi_cmd_exec_finish (const char *command, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
if (argc > 0 && strcmp(argv[0], "--reverse") == 0)
}
void
-mi_cmd_exec_return (char *command, char **argv, int argc)
+mi_cmd_exec_return (const char *command, char **argv, int argc)
{
/* This command doesn't really execute the target, it just pops the
specified number of frames. */
}
void
-mi_cmd_exec_jump (char *args, char **argv, int argc)
+mi_cmd_exec_jump (const char *args, char **argv, int argc)
{
/* FIXME: Should call a libgdb function, not a cli wrapper. */
mi_execute_async_cli_command ("jump", argv, argc);
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
{
}
}
-static void
-exec_direction_forward (void *notused)
-{
- execution_direction = EXEC_FORWARD;
-}
-
static void
exec_reverse_continue (char **argv, int argc)
{
enum exec_direction_kind dir = execution_direction;
- struct cleanup *old_chain;
if (dir == EXEC_REVERSE)
error (_("Already in reverse mode."));
if (!target_can_execute_reverse)
error (_("Target %s does not support this command."), target_shortname);
- old_chain = make_cleanup (exec_direction_forward, NULL);
- execution_direction = EXEC_REVERSE;
+ scoped_restore save_exec_dir = make_scoped_restore (&execution_direction,
+ EXEC_REVERSE);
exec_continue (argv, argc);
- do_cleanups (old_chain);
}
void
-mi_cmd_exec_continue (char *command, char **argv, int argc)
+mi_cmd_exec_continue (const char *command, char **argv, int argc)
{
if (argc > 0 && strcmp (argv[0], "--reverse") == 0)
exec_reverse_continue (argv + 1, argc - 1);
mi_cmd_execute. */
void
-mi_cmd_exec_interrupt (char *command, char **argv, int argc)
+mi_cmd_exec_interrupt (const char *command, char **argv, int argc)
{
/* In all-stop mode, everything stops, so we don't need to try
anything specific. */
}
void
-mi_cmd_exec_run (char *command, char **argv, int argc)
+mi_cmd_exec_run (const char *command, char **argv, int argc)
{
int start_p = 0;
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
{
}
void
-mi_cmd_target_detach (char *command, char **argv, int argc)
+mi_cmd_target_detach (const char *command, char **argv, int argc)
{
if (argc != 0 && argc != 1)
error (_("Usage: -target-detach [pid | thread-group]"));
}
void
-mi_cmd_target_flash_erase (char *command, char **argv, int argc)
+mi_cmd_target_flash_erase (const char *command, char **argv, int argc)
{
flash_erase_command (NULL, 0);
}
void
-mi_cmd_thread_select (char *command, char **argv, int argc)
+mi_cmd_thread_select (const char *command, char **argv, int argc)
{
enum gdb_rc rc;
char *mi_error_message;
}
void
-mi_cmd_thread_list_ids (char *command, char **argv, int argc)
+mi_cmd_thread_list_ids (const char *command, char **argv, int argc)
{
enum gdb_rc rc;
char *mi_error_message;
}
void
-mi_cmd_thread_info (char *command, char **argv, int argc)
+mi_cmd_thread_info (const char *command, char **argv, int argc)
{
if (argc != 0 && argc != 1)
error (_("Invalid MI command"));
compare_positive_ints))
{
struct collect_cores_data data;
- struct cleanup *back_to
- = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
uiout->field_fmt ("id", "i%d", inferior->num);
uiout->field_string ("type", "process");
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)
print_thread_info (uiout, NULL, inferior->pid);
-
- do_cleanups (back_to);
}
return 0;
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,
ix_items, item);
ix_items++)
{
- struct cleanup *back_to;
-
const char *pid = get_osdata_column (item, "pid");
const char *cmd = get_osdata_column (item, "command");
const char *user = get_osdata_column (item, "user");
continue;
- back_to = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
uiout->field_fmt ("id", "%s", pid);
uiout->field_string ("type", "process");
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);
++ix_child)
{
- struct cleanup *back_to_2 =
- make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
const char *tid = get_osdata_column (child, "tid");
const char *tcore = get_osdata_column (child, "core");
uiout->field_string ("id", tid);
if (tcore)
uiout->field_string ("core", tcore);
-
- do_cleanups (back_to_2);
}
}
}
-
- do_cleanups (back_to);
}
do_cleanups (cleanup);
}
void
-mi_cmd_list_thread_groups (char *command, char **argv, int argc)
+mi_cmd_list_thread_groups (const char *command, char **argv, int argc)
{
struct ui_out *uiout = current_uiout;
struct cleanup *back_to;
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);
}
}
void
-mi_cmd_data_list_register_names (char *command, char **argv, int argc)
+mi_cmd_data_list_register_names (const char *command, char **argv, int argc)
{
struct gdbarch *gdbarch;
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
-mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
+mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc)
{
static struct regcache *this_regs = NULL;
struct ui_out *uiout = current_uiout;
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
their values is returned. */
void
-mi_cmd_data_list_register_values (char *command, char **argv, int argc)
+mi_cmd_data_list_register_values (const char *command, char **argv, int argc)
{
struct ui_out *uiout = current_uiout;
struct frame_info *frame;
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
{
struct ui_out *uiout = current_uiout;
struct value *val = value_of_register (regnum, frame);
- struct cleanup *tuple_cleanup;
struct value_print_options opts;
if (skip_unavailable && !value_entirely_available (val))
return;
- tuple_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
uiout->field_int ("number", regnum);
if (format == 'N')
value_embedded_offset (val), 0,
&stb, 0, val, &opts, current_language);
uiout->field_stream ("value", stb);
-
- do_cleanups (tuple_cleanup);
}
/* Write given values into registers. The registers and values are
-data-write-register-values <format>
[<regnum1> <value1>...<regnumN> <valueN>] */
void
-mi_cmd_data_write_register_values (char *command, char **argv, int argc)
+mi_cmd_data_write_register_values (const char *command, char **argv, int argc)
{
struct regcache *regcache;
struct gdbarch *gdbarch;
included in double quotes. */
void
-mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
+mi_cmd_data_evaluate_expression (const char *command, char **argv, int argc)
{
struct value *val;
struct value_print_options opts;
The number of bytes read is SIZE*ROW*COL. */
void
-mi_cmd_data_read_memory (char *command, char **argv, int argc)
+mi_cmd_data_read_memory (const char *command, char **argv, int argc)
{
struct gdbarch *gdbarch = get_current_arch ();
struct ui_out *uiout = current_uiout;
/* 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_tuple;
- struct cleanup *cleanup_list_data;
struct value_print_options opts;
- cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ 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_tuple);
}
- do_cleanups (cleanup_list);
}
}
void
-mi_cmd_data_read_memory_bytes (char *command, char **argv, int argc)
+mi_cmd_data_read_memory_bytes (const char *command, char **argv, int argc)
{
struct gdbarch *gdbarch = get_current_arch ();
struct ui_out *uiout = current_uiout;
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)
{
- struct cleanup *t = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
char *data, *p;
int i;
int alloc_len;
}
uiout->field_string ("contents", data);
xfree (data);
- do_cleanups (t);
}
do_cleanups (cleanups);
}
Prints nothing. */
void
-mi_cmd_data_write_memory (char *command, char **argv, int argc)
+mi_cmd_data_write_memory (const char *command, char **argv, int argc)
{
struct gdbarch *gdbarch = get_current_arch ();
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* 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.
COUNT: number of bytes to be filled (decimal integer). */
void
-mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
+mi_cmd_data_write_memory_bytes (const char *command, char **argv, int argc)
{
CORE_ADDR addr;
char *cdata;
}
void
-mi_cmd_enable_timings (char *command, char **argv, int argc)
+mi_cmd_enable_timings (const char *command, char **argv, int argc)
{
if (argc == 0)
do_timings = 1;
}
void
-mi_cmd_list_features (char *command, char **argv, int argc)
+mi_cmd_list_features (const char *command, char **argv, int argc)
{
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;
}
}
void
-mi_cmd_list_target_features (char *command, char **argv, int argc)
+mi_cmd_list_target_features (const char *command, char **argv, int argc)
{
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;
}
}
void
-mi_cmd_add_inferior (char *command, char **argv, int argc)
+mi_cmd_add_inferior (const char *command, char **argv, int argc)
{
struct inferior *inf;
}
void
-mi_cmd_remove_inferior (char *command, char **argv, int argc)
+mi_cmd_remove_inferior (const char *command, char **argv, int argc)
{
int id;
struct inferior *inf;
static void
captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
{
- struct mi_interp *mi = (struct mi_interp *) interp_data (command_interp ());
+ struct mi_interp *mi = (struct mi_interp *) command_interp ();
struct cleanup *cleanup;
if (do_timings)
/* Echo the command on the console. */
fprintf_unfiltered (gdb_stdlog, "%s\n", context->command);
/* Call the "console" interpreter. */
- argv[0] = INTERP_CONSOLE;
+ argv[0] = (char *) INTERP_CONSOLE;
argv[1] = context->command;
mi_cmd_interpreter_exec ("-interpreter-exec", argv, 2);
static void
mi_print_exception (const char *token, struct gdb_exception exception)
{
- struct mi_interp *mi
- = (struct mi_interp *) interp_data (current_interpreter ());
+ struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
fputs_unfiltered (token, mi->raw_stdout);
fputs_unfiltered ("^error,msg=\"", mi->raw_stdout);
mi_execute_command (const char *cmd, int from_tty)
{
char *token;
- struct mi_parse *command = NULL;
+ std::unique_ptr<struct mi_parse> command;
/* This is to handle EOF (^D). We just quit gdb. */
/* FIXME: we should call some API function here. */
if (command != NULL)
{
ptid_t previous_ptid = inferior_ptid;
- struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
- command->token = token;
+ gdb::optional<scoped_restore_tmpl<int>> restore_suppress;
if (command->cmd != NULL && command->cmd->suppress_notification != NULL)
- {
- make_cleanup_restore_integer (command->cmd->suppress_notification);
- *command->cmd->suppress_notification = 1;
- }
+ restore_suppress.emplace (command->cmd->suppress_notification, 1);
+
+ command->token = token;
if (do_timings)
{
TRY
{
- captured_mi_execute_command (current_uiout, command);
+ captured_mi_execute_command (current_uiout, command.get ());
}
CATCH (result, RETURN_MASK_ALL)
{
&& thread_count () != 0
/* If the command already reports the thread change, no need to do it
again. */
- && !command_notifies_uscc_observer (command))
+ && !command_notifies_uscc_observer (command.get ()))
{
- struct mi_interp *mi
- = (struct mi_interp *) top_level_interpreter_data ();
+ struct mi_interp *mi = (struct mi_interp *) top_level_interpreter ();
int report_change = 0;
if (command->thread == -1)
(USER_SELECTED_THREAD | USER_SELECTED_FRAME);
}
}
-
- mi_parse_free (command);
-
- do_cleanups (cleanup);
}
}
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);
}
}
void
-mi_execute_async_cli_command (char *cli_command, char **argv, int argc)
+mi_execute_async_cli_command (const char *cli_command, char **argv, int argc)
{
struct cleanup *old_cleanups;
char *run;
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 *) interp_data (current_interpreter ());
+ struct mi_interp *mi = (struct mi_interp *) current_interpreter ();
/* This function is called through deprecated_show_load_progress
which means uiout may not be correct. Fix it for the duration
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);
if (new_section)
{
- struct cleanup *cleanup_tuple;
-
xfree (previous_sect_name);
previous_sect_name = xstrdup (section_name);
if (current_token)
fputs_unfiltered (current_token, mi->raw_stdout);
fputs_unfiltered ("+download", mi->raw_stdout);
- cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
- uiout->field_string ("section", section_name);
- uiout->field_int ("section-size", total_section);
- uiout->field_int ("total-size", grand_total);
- do_cleanups (cleanup_tuple);
- mi_out_put (uiout, mi->raw_stdout);
+ {
+ 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.get (), mi->raw_stdout);
fputs_unfiltered ("\n", mi->raw_stdout);
gdb_flush (mi->raw_stdout);
}
steady_clock::time_point time_now = steady_clock::now ();
if (time_now - last_update > milliseconds (500))
{
- struct cleanup *cleanup_tuple;
-
last_update = time_now;
if (current_token)
fputs_unfiltered (current_token, mi->raw_stdout);
fputs_unfiltered ("+download", mi->raw_stdout);
- cleanup_tuple = make_cleanup_ui_out_tuple_begin_end (uiout, 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);
- do_cleanups (cleanup_tuple);
- mi_out_put (uiout, mi->raw_stdout);
+ {
+ 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.get (), mi->raw_stdout);
fputs_unfiltered ("\n", mi->raw_stdout);
gdb_flush (mi->raw_stdout);
}
- xfree (uiout);
current_uiout = saved_uiout;
}
}
void
-mi_cmd_trace_define_variable (char *command, char **argv, int argc)
+mi_cmd_trace_define_variable (const char *command, char **argv, int argc)
{
LONGEST initval = 0;
struct trace_state_variable *tsv;
}
void
-mi_cmd_trace_list_variables (char *command, char **argv, int argc)
+mi_cmd_trace_list_variables (const char *command, char **argv, int argc)
{
if (argc != 0)
error (_("-trace-list-variables: no arguments allowed"));
}
void
-mi_cmd_trace_find (char *command, char **argv, int argc)
+mi_cmd_trace_find (const char *command, char **argv, int argc)
{
char *mode;
}
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_save (char *command, char **argv, int argc)
+mi_cmd_trace_save (const char *command, char **argv, int argc)
{
int target_saves = 0;
int generate_ctf = 0;
}
void
-mi_cmd_trace_start (char *command, char **argv, int argc)
+mi_cmd_trace_start (const char *command, char **argv, int argc)
{
start_tracing (NULL);
}
void
-mi_cmd_trace_status (char *command, char **argv, int argc)
+mi_cmd_trace_status (const char *command, char **argv, int argc)
{
trace_status_mi (0);
}
void
-mi_cmd_trace_stop (char *command, char **argv, int argc)
+mi_cmd_trace_stop (const char *command, char **argv, int argc)
{
stop_tracing (NULL);
trace_status_mi (1);
/* Implement the "-ada-task-info" command. */
void
-mi_cmd_ada_task_info (char *command, char **argv, int argc)
+mi_cmd_ada_task_info (const char *command, char **argv, int argc)
{
if (argc != 0 && argc != 1)
error (_("Invalid MI command"));
static void
print_variable_or_computed (const char *expression, enum print_values values)
{
- struct cleanup *old_chain;
struct value *val;
struct type *type;
struct ui_out *uiout = current_uiout;
else
val = evaluate_expression (expr.get ());
- old_chain = make_cleanup (null_cleanup, NULL);
+ gdb::optional<ui_out_emit_tuple> tuple_emitter;
if (values != PRINT_NO_VALUES)
- make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ tuple_emitter.emplace (uiout, nullptr);
uiout->field_string ("name", expression);
switch (values)
}
break;
}
-
- do_cleanups (old_chain);
}
/* Implement the "-trace-frame-collected" command. */
void
-mi_cmd_trace_frame_collected (char *command, char **argv, int argc)
+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++)
{
- struct cleanup *cleanup_child;
struct trace_state_variable *tsv;
tsv = find_trace_state_variable_by_number (tvar);
- cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_emit_tuple tuple_emitter (uiout, NULL);
if (tsv != NULL)
{
uiout->field_skip ("name");
uiout->field_skip ("current");
}
-
- do_cleanups (cleanup_child);
}
- 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