/* GDB CLI command scripting.
- Copyright (C) 1986-2014 Free Software Foundation, Inc.
+ Copyright (C) 1986-2016 Free Software Foundation, Inc.
This file is part of GDB.
#include <ctype.h>
#include "ui-out.h"
-#include <string.h>
-#include "exceptions.h"
#include "top.h"
#include "breakpoint.h"
#include "cli/cli-cmds.h"
#include "extension.h"
#include "interps.h"
+#include "compile/compile.h"
/* Prototypes for local functions. */
case while_control:
case while_stepping_control:
case commands_control:
+ case compile_control:
case python_control:
case guile_control:
return 1;
error (_("if/while commands require arguments."));
gdb_assert (args != NULL);
- cmd = (struct command_line *) xmalloc (sizeof (struct command_line));
+ cmd = XNEW (struct command_line);
cmd->next = NULL;
cmd->control_type = type;
cmd->body_count = 1;
- cmd->body_list
- = (struct command_line **) xmalloc (sizeof (struct command_line *)
- * cmd->body_count);
- memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
+ cmd->body_list = XCNEWVEC (struct command_line *, cmd->body_count);
cmd->line = xstrdup (args);
return cmd;
continue;
}
+ if (list->control_type == compile_control)
+ {
+ ui_out_field_string (uiout, NULL, "compile expression");
+ ui_out_text (uiout, "\n");
+ print_command_lines (uiout, *list->body_list, 0);
+ if (depth)
+ ui_out_spaces (uiout, 2 * depth);
+ ui_out_field_string (uiout, NULL, "end");
+ ui_out_text (uiout, "\n");
+ list = list->next;
+ continue;
+ }
+
if (list->control_type == guile_control)
{
ui_out_field_string (uiout, NULL, "guile");
static void
clear_hook_in_cleanup (void *data)
{
- struct cmd_list_element *c = data;
+ struct cmd_list_element *c = (struct cmd_list_element *) data;
c->hook_in = 0; /* Allow hook to work again once it is complete. */
}
static void
do_restore_user_call_depth (void * call_depth)
{
- int *depth = call_depth;
+ int *depth = (int *) call_depth;
(*depth)--;
if ((*depth) == 0)
not confused with Insight. */
in_user_command = 1;
- make_cleanup_restore_integer (&interpreter_async);
- interpreter_async = 0;
+ make_cleanup_restore_integer (¤t_ui->async);
+ current_ui->async = 0;
command_nest_depth++;
while (cmdlines)
case while_control:
{
int len = strlen (cmd->line) + 7;
- char *buffer = alloca (len);
+ char *buffer = (char *) alloca (len);
xsnprintf (buffer, len, "while %s", cmd->line);
print_command_trace (buffer);
case if_control:
{
int len = strlen (cmd->line) + 4;
- char *buffer = alloca (len);
+ char *buffer = (char *) alloca (len);
xsnprintf (buffer, len, "if %s", cmd->line);
print_command_trace (buffer);
break;
}
+ case compile_control:
+ eval_compile_command (cmd, NULL, cmd->control_u.compile.scope,
+ cmd->control_u.compile.scope_data);
+ ret = simple_control;
+ break;
+
case python_control:
case guile_control:
{
if (command == NULL)
return;
- old_chain = make_cleanup_restore_integer (&interpreter_async);
- interpreter_async = 0;
+ old_chain = make_cleanup_restore_integer (¤t_ui->async);
+ current_ui->async = 0;
execute_control_command_untraced (command);
free_command_lines (&command);
if (command == NULL)
return;
- old_chain = make_cleanup_restore_integer (&interpreter_async);
- interpreter_async = 0;
+ old_chain = make_cleanup_restore_integer (¤t_ui->async);
+ current_ui->async = 0;
execute_control_command_untraced (command);
free_command_lines (&command);
struct cleanup *old_chain;
unsigned int arg_count = 0;
- args = (struct user_args *) xmalloc (sizeof (struct user_args));
+ args = XNEW (struct user_args);
memset (args, 0, sizeof (struct user_args));
args->next = user_args;
{
while ((p = strchr (p, '$')))
{
- if (strncmp (p, "$arg", 4) == 0
+ if (startswith (p, "$arg")
&& (isdigit (p[4]) || p[4] == 'c'))
return p;
p++;
if (new_length <= n)
return;
- body_list = (struct command_line **)
- xmalloc (sizeof (struct command_line *) * new_length);
+ body_list = XCNEWVEC (struct command_line *, new_length);
memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
- memset (body_list + n, 0, sizeof (struct command_line *) * (new_length - n));
xfree (command->body_list);
command->body_list = body_list;
command->body_count = new_length;
}
-/* Read next line from stdout. Passed to read_command_line_1 and
+/* Read next line from stdin. Passed to read_command_line_1 and
recurse_read_control_structure whenever we need to read commands
- from stdout. */
+ from stdin. */
static char *
read_next_line (void)
/* 'end' is always recognized, regardless of parse_commands value.
We also permit whitespace before end and after. */
- if (p_end - p_start == 3 && !strncmp (p_start, "end", 3))
+ if (p_end - p_start == 3 && startswith (p_start, "end"))
return end_command;
if (parse_commands)
return nop_command;
/* Is the else clause of an if control structure? */
- if (p_end - p == 4 && !strncmp (p, "else", 4))
+ if (p_end - p == 4 && startswith (p, "else"))
return else_command;
/* Check for while, if, break, continue, etc and build a new
command line structure for them. */
- if ((p_end - p >= 14 && !strncmp (p, "while-stepping", 14))
- || (p_end - p >= 8 && !strncmp (p, "stepping", 8))
- || (p_end - p >= 2 && !strncmp (p, "ws", 2)))
+ if ((p_end - p >= 14 && startswith (p, "while-stepping"))
+ || (p_end - p >= 8 && startswith (p, "stepping"))
+ || (p_end - p >= 2 && startswith (p, "ws")))
{
/* Because validate_actionline and encode_action lookup
command's line as command, we need the line to
not. */
*command = build_command_line (while_stepping_control, p);
}
- else if (p_end - p > 5 && !strncmp (p, "while", 5))
+ else if (p_end - p > 5 && startswith (p, "while"))
{
char *first_arg;
first_arg++;
*command = build_command_line (while_control, first_arg);
}
- else if (p_end - p > 2 && !strncmp (p, "if", 2))
+ else if (p_end - p > 2 && startswith (p, "if"))
{
char *first_arg;
first_arg++;
*command = build_command_line (if_control, first_arg);
}
- else if (p_end - p >= 8 && !strncmp (p, "commands", 8))
+ else if (p_end - p >= 8 && startswith (p, "commands"))
{
char *first_arg;
first_arg++;
*command = build_command_line (commands_control, first_arg);
}
- else if (p_end - p == 6 && !strncmp (p, "python", 6))
+ else if (p_end - p == 6 && startswith (p, "python"))
{
/* Note that we ignore the inline "python command" form
here. */
*command = build_command_line (python_control, "");
}
- else if (p_end - p == 5 && !strncmp (p, "guile", 5))
+ else if (p_end - p == 6 && startswith (p, "compile"))
+ {
+ /* Note that we ignore the inline "compile command" form
+ here. */
+ *command = build_command_line (compile_control, "");
+ (*command)->control_u.compile.scope = COMPILE_I_INVALID_SCOPE;
+ }
+
+ else if (p_end - p == 5 && startswith (p, "guile"))
{
/* Note that we ignore the inline "guile command" form here. */
*command = build_command_line (guile_control, "");
}
- else if (p_end - p == 10 && !strncmp (p, "loop_break", 10))
+ else if (p_end - p == 10 && startswith (p, "loop_break"))
{
- *command = (struct command_line *)
- xmalloc (sizeof (struct command_line));
+ *command = XNEW (struct command_line);
(*command)->next = NULL;
(*command)->line = NULL;
(*command)->control_type = break_control;
(*command)->body_count = 0;
(*command)->body_list = NULL;
}
- else if (p_end - p == 13 && !strncmp (p, "loop_continue", 13))
+ else if (p_end - p == 13 && startswith (p, "loop_continue"))
{
- *command = (struct command_line *)
- xmalloc (sizeof (struct command_line));
+ *command = XNEW (struct command_line);
(*command)->next = NULL;
(*command)->line = NULL;
(*command)->control_type = continue_control;
if (!parse_commands || not_handled)
{
/* A normal command. */
- *command = (struct command_line *)
- xmalloc (sizeof (struct command_line));
+ *command = XNEW (struct command_line);
(*command)->next = NULL;
(*command)->line = savestring (p, p_end - p);
(*command)->control_type = simple_control;
if (validator)
{
- volatile struct gdb_exception ex;
- TRY_CATCH (ex, RETURN_MASK_ALL)
+ TRY
{
validator ((*command)->line, closure);
}
- if (ex.reason < 0)
+ CATCH (ex, RETURN_MASK_ALL)
{
xfree (*command);
throw_exception (ex);
}
+ END_CATCH
}
/* Nothing special. */
next = NULL;
val = process_next_line (read_next_line_func (), &next,
current_cmd->control_type != python_control
- && current_cmd->control_type != guile_control,
+ && current_cmd->control_type != guile_control
+ && current_cmd->control_type != compile_control,
validator, closure);
/* Just skip blanks and comments. */
static void
do_free_command_lines_cleanup (void *arg)
{
- free_command_lines (arg);
+ free_command_lines ((struct command_line **) arg);
}
struct cleanup *
if (cmds)
{
- result = (struct command_line *) xmalloc (sizeof (struct command_line));
+ result = XNEW (struct command_line);
result->next = copy_command_lines (cmds->next);
result->line = xstrdup (cmds->line);
{
int i;
- result->body_list = (struct command_line **)
- xmalloc (sizeof (struct command_line *) * cmds->body_count);
+ result->body_list = XNEWVEC (struct command_line *, cmds->body_count);
for (i = 0; i < cmds->body_count; i++)
result->body_list[i] = copy_command_lines (cmds->body_list[i]);
{
int q;
- if (c->class == class_user || c->class == class_alias)
+ if (c->theclass == class_user || c->theclass == class_alias)
q = query (_("Redefine command \"%s\"? "), c->name);
else
q = query (_("Really redefine built-in command \"%s\"? "), c->name);
"Type commands for definition of \"%s\".", comfull);
cmds = read_command_lines (tmpbuf, from_tty, 1, 0, 0);
- if (c && c->class == class_user)
+ if (c && c->theclass == class_user)
free_command_lines (&c->user_commands);
newc = add_cmd (comname, class_user, user_defined_command,
- (c && c->class == class_user)
+ (c && c->theclass == class_user)
? c->doc : xstrdup ("User-defined."), list);
newc->user_commands = cmds;
tem = comname;
c = lookup_cmd (&tem, *list, "", 0, 1);
- if (c->class != class_user)
+ if (c->theclass != class_user)
error (_("Command \"%s\" is built-in."), comfull);
xsnprintf (tmpbuf, sizeof (tmpbuf), "Type documentation for \"%s\".",
source_line_number = 0;
source_file_name = file;
- make_cleanup_restore_integer (&interpreter_async);
- interpreter_async = 0;
+ make_cleanup_restore_integer (¤t_ui->async);
+ current_ui->async = 0;
{
- volatile struct gdb_exception e;
- TRY_CATCH (e, RETURN_MASK_ERROR)
+ TRY
{
read_command_file (stream);
}
- switch (e.reason)
+ CATCH (e, RETURN_MASK_ERROR)
{
- case 0:
- break;
- case RETURN_ERROR:
/* Re-throw the error, but with the file name information
prepended. */
throw_error (e.error,
_("%s:%d: Error in sourced command file:\n%s"),
source_file_name, source_line_number, e.message);
- default:
- internal_error (__FILE__, __LINE__, _("bad reason"));
}
+ END_CATCH
}
do_cleanups (old_cleanups);
const char *prefixname = c->prefixname;
for (c = *c->prefixlist; c != NULL; c = c->next)
- if (c->class == class_user || c->prefixlist != NULL)
+ if (c->theclass == class_user || c->prefixlist != NULL)
show_user_1 (c, prefixname, c->name, gdb_stdout);
return;
}
cmdlines = c->user_commands;
- if (!cmdlines)
- return;
fprintf_filtered (stream, "User command \"%s%s\":\n", prefix, name);
+ if (!cmdlines)
+ return;
print_command_lines (current_uiout, cmdlines, 1);
fputs_filtered ("\n", stream);
}