/* MI Command Set.
- Copyright (C) 2000-2005, 2007-2012 Free Software Foundation, Inc.
+ Copyright (C) 2000-2013 Free Software Foundation, Inc.
Contributed by Cygnus Solutions (a Red Hat company).
#include "osdata.h"
#include "splay-tree.h"
#include "tracepoint.h"
+#include "ctf.h"
#include "ada-lang.h"
#include "linespec.h"
+#ifdef HAVE_PYTHON
+#include "python/python-internal.h"
+#endif
#include <ctype.h>
#include <sys/time.h>
switch_to_thread (thread->ptid);
clear_proceed_status ();
- proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
+ proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0);
}
static int
struct osdata_item *item;
int ix_items;
struct ui_out *uiout = current_uiout;
+ struct cleanup *cleanup;
/* This keeps a map from integer (pid) to VEC (struct osdata_item *)*
The vector contains information about all threads for the given pid.
/* get_osdata will throw if it cannot return data. */
data = get_osdata ("processes");
- make_cleanup_osdata_free (data);
+ cleanup = make_cleanup_osdata_free (data);
if (recurse)
{
do_cleanups (back_to);
}
+
+ do_cleanups (cleanup);
}
void
{
struct gdbarch *gdbarch = get_frame_arch (frame);
struct ui_out *uiout = current_uiout;
- CORE_ADDR addr;
- enum lval_type lval;
- struct ui_stream *stb;
struct value *val;
- stb = ui_out_stream_new (uiout);
-
if (format == 'N')
format = 0;
else
{
struct value_print_options opts;
+ struct ui_file *stb;
+ struct cleanup *old_chain;
+
+ stb = mem_fileopen ();
+ old_chain = make_cleanup_ui_file_delete (stb);
get_formatted_print_options (&opts, format);
opts.deref_ref = 1;
val_print (value_type (val),
value_contents_for_printing (val),
value_embedded_offset (val), 0,
- stb->stream, 0, val, &opts, current_language);
+ stb, 0, val, &opts, current_language);
ui_out_field_stream (uiout, "value", stb);
- ui_out_stream_delete (stb);
+ do_cleanups (old_chain);
}
}
struct regcache *regcache;
struct gdbarch *gdbarch;
int numregs, i;
- char format;
/* Note that the test for a valid register must include checking the
gdbarch_register_name because gdbarch_num_regs may be allocated
error (_("-data-write-register-values: Usage: -data-write-register-"
"values <format> [<regnum1> <value1>...<regnumN> <valueN>]"));
- format = (int) argv[0][0];
-
if (!target_has_registers)
error (_("-data-write-register-values: No registers."));
mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
{
struct expression *expr;
- struct cleanup *old_chain = NULL;
+ struct cleanup *old_chain;
struct value *val;
- struct ui_stream *stb = NULL;
+ struct ui_file *stb;
struct value_print_options opts;
struct ui_out *uiout = current_uiout;
- stb = ui_out_stream_new (uiout);
+ stb = mem_fileopen ();
+ old_chain = make_cleanup_ui_file_delete (stb);
if (argc != 1)
- {
- ui_out_stream_delete (stb);
- error (_("-data-evaluate-expression: "
- "Usage: -data-evaluate-expression expression"));
- }
+ error (_("-data-evaluate-expression: "
+ "Usage: -data-evaluate-expression expression"));
expr = parse_expression (argv[0]);
- old_chain = make_cleanup (free_current_contents, &expr);
+ make_cleanup (free_current_contents, &expr);
val = evaluate_expression (expr);
/* Print the result of the expression evaluation. */
get_user_print_options (&opts);
opts.deref_ref = 0;
- common_val_print (val, stb->stream, 0, &opts, current_language);
+ common_val_print (val, stb, 0, &opts, current_language);
ui_out_field_stream (uiout, "value", stb);
- ui_out_stream_delete (stb);
do_cleanups (old_chain);
}
/* Build the result as a two dimentional table. */
{
- struct ui_stream *stream = ui_out_stream_new (uiout);
- struct cleanup *cleanup_list_memory;
+ struct ui_file *stream;
+ struct cleanup *cleanup_stream;
int row;
int row_byte;
- cleanup_list_memory = make_cleanup_ui_out_list_begin_end (uiout, "memory");
+ stream = mem_fileopen ();
+ cleanup_stream = make_cleanup_ui_file_delete (stream);
+
+ make_cleanup_ui_out_list_begin_end (uiout, "memory");
for (row = 0, row_byte = 0;
row < nr_rows;
row++, row_byte += nr_cols * word_size)
}
else
{
- ui_file_rewind (stream->stream);
+ ui_file_rewind (stream);
print_scalar_formatted (mbuf + col_byte, word_type, &opts,
- word_asize, stream->stream);
+ word_asize, stream);
ui_out_field_stream (uiout, NULL, stream);
}
}
{
int byte;
- ui_file_rewind (stream->stream);
+ ui_file_rewind (stream);
for (byte = row_byte;
byte < row_byte + word_size * nr_cols; byte++)
{
if (byte >= nr_bytes)
- fputc_unfiltered ('X', stream->stream);
+ fputc_unfiltered ('X', stream);
else if (mbuf[byte] < 32 || mbuf[byte] > 126)
- fputc_unfiltered (aschar, stream->stream);
+ fputc_unfiltered (aschar, stream);
else
- fputc_unfiltered (mbuf[byte], stream->stream);
+ fputc_unfiltered (mbuf[byte], stream);
}
ui_out_field_stream (uiout, "ascii", stream);
}
do_cleanups (cleanup_tuple);
}
- ui_out_stream_delete (stream);
- do_cleanups (cleanup_list_memory);
+ do_cleanups (cleanup_stream);
}
do_cleanups (cleanups);
}
struct gdbarch *gdbarch = get_current_arch ();
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
CORE_ADDR addr;
- char word_format;
long word_size;
/* FIXME: ezannoni 2000-02-17 LONGEST could possibly not be big
enough when using a compiler other than GCC. */
/* Extract all the arguments. */
/* Start address of the memory dump. */
addr = parse_and_eval_address (argv[0]);
- /* The format character to use when displaying a memory word. See
- the ``x'' command. */
- word_format = argv[1][0];
/* The size of the memory word. */
word_size = atol (argv[2]);
old_chain = make_cleanup (xfree, buffer);
store_signed_integer (buffer, word_size, byte_order, value);
/* Write it down to memory. */
- write_memory (addr, buffer, word_size);
+ write_memory_with_notification (addr, buffer, word_size);
/* Free the buffer. */
do_cleanups (old_chain);
}
/* Implementation of the -data-write-memory-bytes command.
ADDR: start address
- DATA: string of bytes to write at that address. */
+ DATA: string of bytes to write at that address
+ COUNT: number of bytes to be filled (decimal integer). */
void
mi_cmd_data_write_memory_bytes (char *command, char **argv, int argc)
CORE_ADDR addr;
char *cdata;
gdb_byte *data;
- int len, r, i;
+ gdb_byte *databuf;
+ size_t len, i, steps, remainder;
+ long int count, j;
struct cleanup *back_to;
- if (argc != 2)
- error (_("Usage: ADDR DATA."));
+ if (argc != 2 && argc != 3)
+ error (_("Usage: ADDR DATA [COUNT]."));
addr = parse_and_eval_address (argv[0]);
cdata = argv[1];
+ if (strlen (cdata) % 2)
+ error (_("Hex-encoded '%s' must have an even number of characters."),
+ cdata);
+
len = strlen (cdata)/2;
+ if (argc == 3)
+ count = strtoul (argv[2], NULL, 10);
+ else
+ count = len;
- data = xmalloc (len);
- back_to = make_cleanup (xfree, data);
+ databuf = xmalloc (len * sizeof (gdb_byte));
+ back_to = make_cleanup (xfree, databuf);
for (i = 0; i < len; ++i)
{
int x;
- sscanf (cdata + i * 2, "%02x", &x);
- data[i] = (gdb_byte) x;
+ if (sscanf (cdata + i * 2, "%02x", &x) != 1)
+ error (_("Invalid argument"));
+ databuf[i] = (gdb_byte) x;
+ }
+
+ if (len < count)
+ {
+ /* Pattern is made of less bytes than count:
+ repeat pattern to fill memory. */
+ data = xmalloc (count);
+ make_cleanup (xfree, data);
+
+ steps = count / len;
+ remainder = count % len;
+ for (j = 0; j < steps; j++)
+ memcpy (data + j * len, databuf, len);
+
+ if (remainder > 0)
+ memcpy (data + steps * len, databuf, remainder);
+ }
+ else
+ {
+ /* Pattern is longer than or equal to count:
+ just copy len bytes. */
+ data = databuf;
}
- r = target_write_memory (addr, data, len);
- if (r != 0)
- error (_("Could not write memory"));
+ write_memory_with_notification (addr, data, count);
do_cleanups (back_to);
}
ui_out_field_string (uiout, NULL, "ada-task-info");
#if HAVE_PYTHON
- ui_out_field_string (uiout, NULL, "python");
+ if (gdb_python_initialized)
+ ui_out_field_string (uiout, NULL, "python");
#endif
do_cleanups (cleanup);
}
void
-mi_execute_command (char *cmd, int from_tty)
+mi_execute_command (const char *cmd, int from_tty)
{
char *token;
struct mi_parse *command = NULL;
provide --thread if it wishes to operate on a specific
thread. */
if (inf->pid != 0)
- tp = any_thread_of_process (inf->pid);
+ tp = any_live_thread_of_process (inf->pid);
switch_to_thread (tp ? tp->ptid : null_ptid);
set_current_program_space (inf->pspace);
}
current_context = parse;
- if (strncmp (parse->command, "break-", sizeof ("break-") - 1 ) == 0)
+ if (parse->cmd->suppress_notification != NULL)
{
- make_cleanup_restore_integer (&mi_suppress_breakpoint_notifications);
- mi_suppress_breakpoint_notifications = 1;
+ make_cleanup_restore_integer (parse->cmd->suppress_notification);
+ *parse->cmd->suppress_notification = 1;
}
if (parse->cmd->argv_func != NULL)
mi_cmd_trace_define_variable (char *command, char **argv, int argc)
{
struct expression *expr;
- struct cleanup *back_to;
LONGEST initval = 0;
struct trace_state_variable *tsv;
char *name = 0;
if (argc != 1 && argc != 2)
error (_("Usage: -trace-define-variable VARIABLE [VALUE]"));
- expr = parse_expression (argv[0]);
- back_to = make_cleanup (xfree, expr);
+ name = argv[0];
+ if (*name++ != '$')
+ error (_("Name of trace variable should start with '$'"));
- if (expr->nelts == 3 && expr->elts[0].opcode == OP_INTERNALVAR)
- {
- struct internalvar *intvar = expr->elts[1].internalvar;
-
- if (intvar)
- name = internalvar_name (intvar);
- }
-
- if (!name || *name == '\0')
- error (_("Invalid name of trace variable"));
+ validate_trace_state_variable_name (name);
tsv = find_trace_state_variable (name);
if (!tsv)
initval = value_as_long (parse_and_eval (argv[1]));
tsv->initial_value = initval;
-
- do_cleanups (back_to);
}
void
if (argc != 2)
error (_("Line is required"));
- sals = decode_line_spec (argv[1], DECODE_LINE_FUNFIRSTLINE);
+ sals = decode_line_with_current_source (argv[1],
+ DECODE_LINE_FUNFIRSTLINE);
back_to = make_cleanup (xfree, sals.sals);
sal = sals.sals[0];
mi_cmd_trace_save (char *command, char **argv, int argc)
{
int target_saves = 0;
+ int generate_ctf = 0;
char *filename;
+ int oind = 0;
+ char *oarg;
- if (argc != 1 && argc != 2)
- error (_("Usage: -trace-save [-r] filename"));
-
- if (argc == 2)
+ enum opt
+ {
+ TARGET_SAVE_OPT, CTF_OPT
+ };
+ static const struct mi_opt opts[] =
{
- filename = argv[1];
- if (strcmp (argv[0], "-r") == 0)
- target_saves = 1;
- else
- error (_("Invalid option: %s"), argv[0]);
- }
- else
+ {"r", TARGET_SAVE_OPT, 0},
+ {"ctf", CTF_OPT, 0},
+ { 0, 0, 0 }
+ };
+
+ while (1)
{
- filename = argv[0];
+ int opt = mi_getopt ("-trace-save", argc, argv, opts,
+ &oind, &oarg);
+
+ if (opt < 0)
+ break;
+ switch ((enum opt) opt)
+ {
+ case TARGET_SAVE_OPT:
+ target_saves = 1;
+ break;
+ case CTF_OPT:
+ generate_ctf = 1;
+ break;
+ }
}
+ filename = argv[oind];
- trace_save (filename, target_saves);
+ if (generate_ctf)
+ trace_save_ctf (filename, target_saves);
+ else
+ trace_save_tfile (filename, target_saves);
}
void