Use function_view in cli-script.c
This changes some functions in cli-script.c to use function_view rather than a function pointer and closure argument. This simplifies the code a bit and is useful in a subsequent patch. ChangeLog 2018-05-04 Tom Tromey <tom@tromey.com> * tracepoint.c (actions_command): Update. * mi/mi-cmd-break.c (mi_command_line_array) (mi_command_line_array_cnt, mi_command_line_array_ptr) (mi_read_next_line): Remove. (mi_cmd_break_commands): Update. * cli/cli-script.h (read_command_lines, read_command_lines_1): Use function_view. * cli/cli-script.c (get_command_line): Update. (process_next_line): Use function_view. Constify. (recurse_read_control_structure, read_command_lines) (read_command_lines_1): Change argument types to function_view. (do_define_command, document_command): Update. * breakpoint.h (check_tracepoint_command): Don't declare. * breakpoint.c (check_tracepoint_command): Remove. (commands_command_1, create_tracepoint_from_upload): Update.
This commit is contained in:
parent
7a2c85f259
commit
60b3cef2e4
@ -1,3 +1,21 @@
|
|||||||
|
2018-05-04 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* tracepoint.c (actions_command): Update.
|
||||||
|
* mi/mi-cmd-break.c (mi_command_line_array)
|
||||||
|
(mi_command_line_array_cnt, mi_command_line_array_ptr)
|
||||||
|
(mi_read_next_line): Remove.
|
||||||
|
(mi_cmd_break_commands): Update.
|
||||||
|
* cli/cli-script.h (read_command_lines, read_command_lines_1): Use
|
||||||
|
function_view.
|
||||||
|
* cli/cli-script.c (get_command_line): Update.
|
||||||
|
(process_next_line): Use function_view. Constify.
|
||||||
|
(recurse_read_control_structure, read_command_lines)
|
||||||
|
(read_command_lines_1): Change argument types to function_view.
|
||||||
|
(do_define_command, document_command): Update.
|
||||||
|
* breakpoint.h (check_tracepoint_command): Don't declare.
|
||||||
|
* breakpoint.c (check_tracepoint_command): Remove.
|
||||||
|
(commands_command_1, create_tracepoint_from_upload): Update.
|
||||||
|
|
||||||
2018-05-04 Tom Tromey <tom@tromey.com>
|
2018-05-04 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
PR gdb/11750:
|
PR gdb/11750:
|
||||||
|
@ -1216,14 +1216,6 @@ breakpoint_set_task (struct breakpoint *b, int task)
|
|||||||
gdb::observers::breakpoint_modified.notify (b);
|
gdb::observers::breakpoint_modified.notify (b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
check_tracepoint_command (char *line, void *closure)
|
|
||||||
{
|
|
||||||
struct breakpoint *b = (struct breakpoint *) closure;
|
|
||||||
|
|
||||||
validate_actionline (line, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
commands_command_1 (const char *arg, int from_tty,
|
commands_command_1 (const char *arg, int from_tty,
|
||||||
struct command_line *control)
|
struct command_line *control)
|
||||||
@ -1256,10 +1248,15 @@ commands_command_1 (const char *arg, int from_tty,
|
|||||||
"%s, one per line."),
|
"%s, one per line."),
|
||||||
arg);
|
arg);
|
||||||
|
|
||||||
cmd = read_command_lines (str.c_str (), from_tty, 1,
|
auto do_validate = [=] (const char *line)
|
||||||
(is_tracepoint (b)
|
{
|
||||||
? check_tracepoint_command : 0),
|
validate_actionline (line, b);
|
||||||
b);
|
};
|
||||||
|
gdb::function_view<void (const char *)> validator;
|
||||||
|
if (is_tracepoint (b))
|
||||||
|
validator = do_validate;
|
||||||
|
|
||||||
|
cmd = read_command_lines (str.c_str (), from_tty, 1, validator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14783,7 +14780,7 @@ create_tracepoint_from_upload (struct uploaded_tp *utp)
|
|||||||
this_utp = utp;
|
this_utp = utp;
|
||||||
next_cmd = 0;
|
next_cmd = 0;
|
||||||
|
|
||||||
cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL);
|
cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL);
|
||||||
|
|
||||||
breakpoint_set_commands (tp, std::move (cmd_list));
|
breakpoint_set_commands (tp, std::move (cmd_list));
|
||||||
}
|
}
|
||||||
|
@ -1608,10 +1608,6 @@ extern int is_tracepoint (const struct breakpoint *b);
|
|||||||
it. */
|
it. */
|
||||||
extern VEC(breakpoint_p) *static_tracepoints_here (CORE_ADDR addr);
|
extern VEC(breakpoint_p) *static_tracepoints_here (CORE_ADDR addr);
|
||||||
|
|
||||||
/* Function that can be passed to read_command_line to validate
|
|
||||||
that each command is suitable for tracepoint command list. */
|
|
||||||
extern void check_tracepoint_command (char *line, void *closure);
|
|
||||||
|
|
||||||
/* Create an instance of this to start registering breakpoint numbers
|
/* Create an instance of this to start registering breakpoint numbers
|
||||||
for a later "commands" command. */
|
for a later "commands" command. */
|
||||||
|
|
||||||
|
@ -39,10 +39,10 @@
|
|||||||
/* Prototypes for local functions. */
|
/* Prototypes for local functions. */
|
||||||
|
|
||||||
static enum command_control_type
|
static enum command_control_type
|
||||||
recurse_read_control_structure (char * (*read_next_line_func) (void),
|
recurse_read_control_structure
|
||||||
struct command_line *current_cmd,
|
(gdb::function_view<const char * ()> read_next_line_func,
|
||||||
void (*validator)(char *, void *),
|
struct command_line *current_cmd,
|
||||||
void *closure);
|
gdb::function_view<void (const char *)> validator);
|
||||||
|
|
||||||
static void do_define_command (const char *comname, int from_tty,
|
static void do_define_command (const char *comname, int from_tty,
|
||||||
const counted_command_line *commands);
|
const counted_command_line *commands);
|
||||||
@ -163,7 +163,7 @@ get_command_line (enum command_control_type type, const char *arg)
|
|||||||
command_lines_deleter ());
|
command_lines_deleter ());
|
||||||
|
|
||||||
/* Read in the body of this command. */
|
/* Read in the body of this command. */
|
||||||
if (recurse_read_control_structure (read_next_line, cmd.get (), 0, 0)
|
if (recurse_read_control_structure (read_next_line, cmd.get (), 0)
|
||||||
== invalid_control)
|
== invalid_control)
|
||||||
{
|
{
|
||||||
warning (_("Error reading in canned sequence of commands."));
|
warning (_("Error reading in canned sequence of commands."));
|
||||||
@ -897,11 +897,13 @@ line_first_arg (const char *p)
|
|||||||
Otherwise, only "end" is recognized. */
|
Otherwise, only "end" is recognized. */
|
||||||
|
|
||||||
static enum misc_command_type
|
static enum misc_command_type
|
||||||
process_next_line (char *p, struct command_line **command, int parse_commands,
|
process_next_line (const char *p, struct command_line **command,
|
||||||
void (*validator)(char *, void *), void *closure)
|
int parse_commands,
|
||||||
|
gdb::function_view<void (const char *)> validator)
|
||||||
|
|
||||||
{
|
{
|
||||||
char *p_end;
|
const char *p_end;
|
||||||
char *p_start;
|
const char *p_start;
|
||||||
int not_handled = 0;
|
int not_handled = 0;
|
||||||
|
|
||||||
/* Not sure what to do here. */
|
/* Not sure what to do here. */
|
||||||
@ -1013,10 +1015,9 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
|
|||||||
|
|
||||||
if (validator)
|
if (validator)
|
||||||
{
|
{
|
||||||
|
|
||||||
TRY
|
TRY
|
||||||
{
|
{
|
||||||
validator ((*command)->line, closure);
|
validator ((*command)->line);
|
||||||
}
|
}
|
||||||
CATCH (ex, RETURN_MASK_ALL)
|
CATCH (ex, RETURN_MASK_ALL)
|
||||||
{
|
{
|
||||||
@ -1035,10 +1036,9 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
|
|||||||
obtain lines of the command. */
|
obtain lines of the command. */
|
||||||
|
|
||||||
static enum command_control_type
|
static enum command_control_type
|
||||||
recurse_read_control_structure (char * (*read_next_line_func) (void),
|
recurse_read_control_structure (gdb::function_view<const char * ()> read_next_line_func,
|
||||||
struct command_line *current_cmd,
|
struct command_line *current_cmd,
|
||||||
void (*validator)(char *, void *),
|
gdb::function_view<void (const char *)> validator)
|
||||||
void *closure)
|
|
||||||
{
|
{
|
||||||
enum misc_command_type val;
|
enum misc_command_type val;
|
||||||
enum command_control_type ret;
|
enum command_control_type ret;
|
||||||
@ -1061,7 +1061,7 @@ recurse_read_control_structure (char * (*read_next_line_func) (void),
|
|||||||
current_cmd->control_type != python_control
|
current_cmd->control_type != python_control
|
||||||
&& current_cmd->control_type != guile_control
|
&& current_cmd->control_type != guile_control
|
||||||
&& current_cmd->control_type != compile_control,
|
&& current_cmd->control_type != compile_control,
|
||||||
validator, closure);
|
validator);
|
||||||
|
|
||||||
/* Just skip blanks and comments. */
|
/* Just skip blanks and comments. */
|
||||||
if (val == nop_command)
|
if (val == nop_command)
|
||||||
@ -1114,7 +1114,7 @@ recurse_read_control_structure (char * (*read_next_line_func) (void),
|
|||||||
{
|
{
|
||||||
control_level++;
|
control_level++;
|
||||||
ret = recurse_read_control_structure (read_next_line_func, next,
|
ret = recurse_read_control_structure (read_next_line_func, next,
|
||||||
validator, closure);
|
validator);
|
||||||
control_level--;
|
control_level--;
|
||||||
|
|
||||||
if (ret != simple_control)
|
if (ret != simple_control)
|
||||||
@ -1140,7 +1140,7 @@ recurse_read_control_structure (char * (*read_next_line_func) (void),
|
|||||||
|
|
||||||
counted_command_line
|
counted_command_line
|
||||||
read_command_lines (const char *prompt_arg, int from_tty, int parse_commands,
|
read_command_lines (const char *prompt_arg, int from_tty, int parse_commands,
|
||||||
void (*validator)(char *, void *), void *closure)
|
gdb::function_view<void (const char *)> validator)
|
||||||
{
|
{
|
||||||
if (from_tty && input_interactive_p (current_ui))
|
if (from_tty && input_interactive_p (current_ui))
|
||||||
{
|
{
|
||||||
@ -1163,13 +1163,13 @@ read_command_lines (const char *prompt_arg, int from_tty, int parse_commands,
|
|||||||
counted_command_line head (nullptr, command_lines_deleter ());
|
counted_command_line head (nullptr, command_lines_deleter ());
|
||||||
if (current_interp_named_p (INTERP_CONSOLE))
|
if (current_interp_named_p (INTERP_CONSOLE))
|
||||||
head = read_command_lines_1 (read_next_line, parse_commands,
|
head = read_command_lines_1 (read_next_line, parse_commands,
|
||||||
validator, closure);
|
validator);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
scoped_restore_interp interp_restorer (INTERP_CONSOLE);
|
scoped_restore_interp interp_restorer (INTERP_CONSOLE);
|
||||||
|
|
||||||
head = read_command_lines_1 (read_next_line, parse_commands,
|
head = read_command_lines_1 (read_next_line, parse_commands,
|
||||||
validator, closure);
|
validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from_tty && input_interactive_p (current_ui)
|
if (from_tty && input_interactive_p (current_ui)
|
||||||
@ -1184,8 +1184,9 @@ read_command_lines (const char *prompt_arg, int from_tty, int parse_commands,
|
|||||||
obtained using READ_NEXT_LINE_FUNC. */
|
obtained using READ_NEXT_LINE_FUNC. */
|
||||||
|
|
||||||
counted_command_line
|
counted_command_line
|
||||||
read_command_lines_1 (char * (*read_next_line_func) (void), int parse_commands,
|
read_command_lines_1 (gdb::function_view<const char * ()> read_next_line_func,
|
||||||
void (*validator)(char *, void *), void *closure)
|
int parse_commands,
|
||||||
|
gdb::function_view<void (const char *)> validator)
|
||||||
{
|
{
|
||||||
struct command_line *tail, *next;
|
struct command_line *tail, *next;
|
||||||
counted_command_line head (nullptr, command_lines_deleter ());
|
counted_command_line head (nullptr, command_lines_deleter ());
|
||||||
@ -1199,7 +1200,7 @@ read_command_lines_1 (char * (*read_next_line_func) (void), int parse_commands,
|
|||||||
{
|
{
|
||||||
dont_repeat ();
|
dont_repeat ();
|
||||||
val = process_next_line (read_next_line_func (), &next, parse_commands,
|
val = process_next_line (read_next_line_func (), &next, parse_commands,
|
||||||
validator, closure);
|
validator);
|
||||||
|
|
||||||
/* Ignore blank lines or comments. */
|
/* Ignore blank lines or comments. */
|
||||||
if (val == nop_command)
|
if (val == nop_command)
|
||||||
@ -1221,7 +1222,7 @@ read_command_lines_1 (char * (*read_next_line_func) (void), int parse_commands,
|
|||||||
{
|
{
|
||||||
control_level++;
|
control_level++;
|
||||||
ret = recurse_read_control_structure (read_next_line_func, next,
|
ret = recurse_read_control_structure (read_next_line_func, next,
|
||||||
validator, closure);
|
validator);
|
||||||
control_level--;
|
control_level--;
|
||||||
|
|
||||||
if (ret == invalid_control)
|
if (ret == invalid_control)
|
||||||
@ -1407,7 +1408,7 @@ do_define_command (const char *comname, int from_tty,
|
|||||||
{
|
{
|
||||||
std::string prompt
|
std::string prompt
|
||||||
= string_printf ("Type commands for definition of \"%s\".", comfull);
|
= string_printf ("Type commands for definition of \"%s\".", comfull);
|
||||||
cmds = read_command_lines (prompt.c_str (), from_tty, 1, 0, 0);
|
cmds = read_command_lines (prompt.c_str (), from_tty, 1, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cmds = *commands;
|
cmds = *commands;
|
||||||
@ -1464,7 +1465,7 @@ document_command (const char *comname, int from_tty)
|
|||||||
std::string prompt = string_printf ("Type documentation for \"%s\".",
|
std::string prompt = string_printf ("Type documentation for \"%s\".",
|
||||||
comfull);
|
comfull);
|
||||||
counted_command_line doclines = read_command_lines (prompt.c_str (),
|
counted_command_line doclines = read_command_lines (prompt.c_str (),
|
||||||
from_tty, 0, 0, 0);
|
from_tty, 0, 0);
|
||||||
|
|
||||||
if (c->doc)
|
if (c->doc)
|
||||||
xfree ((char *) c->doc);
|
xfree ((char *) c->doc);
|
||||||
|
@ -106,12 +106,11 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern counted_command_line read_command_lines (const char *, int, int,
|
extern counted_command_line read_command_lines
|
||||||
void (*)(char *, void *),
|
(const char *, int, int, gdb::function_view<void (const char *)>);
|
||||||
void *);
|
extern counted_command_line read_command_lines_1
|
||||||
extern counted_command_line read_command_lines_1 (char * (*) (void), int,
|
(gdb::function_view<const char * ()>, int,
|
||||||
void (*)(char *, void *),
|
gdb::function_view<void (const char *)>);
|
||||||
void *);
|
|
||||||
|
|
||||||
|
|
||||||
/* Exported to cli/cli-cmds.c */
|
/* Exported to cli/cli-cmds.c */
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "linespec.h"
|
#include "linespec.h"
|
||||||
#include "gdb_obstack.h"
|
#include "gdb_obstack.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include "tracepoint.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -468,24 +469,6 @@ mi_cmd_break_watch (const char *command, char **argv, int argc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The mi_read_next_line consults these variable to return successive
|
|
||||||
command lines. While it would be clearer to use a closure pointer,
|
|
||||||
it is not expected that any future code will use read_command_lines_1,
|
|
||||||
therefore no point of overengineering. */
|
|
||||||
|
|
||||||
static char **mi_command_line_array;
|
|
||||||
static int mi_command_line_array_cnt;
|
|
||||||
static int mi_command_line_array_ptr;
|
|
||||||
|
|
||||||
static char *
|
|
||||||
mi_read_next_line (void)
|
|
||||||
{
|
|
||||||
if (mi_command_line_array_ptr == mi_command_line_array_cnt)
|
|
||||||
return NULL;
|
|
||||||
else
|
|
||||||
return mi_command_line_array[mi_command_line_array_ptr++];
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mi_cmd_break_commands (const char *command, char **argv, int argc)
|
mi_cmd_break_commands (const char *command, char **argv, int argc)
|
||||||
{
|
{
|
||||||
@ -509,15 +492,24 @@ mi_cmd_break_commands (const char *command, char **argv, int argc)
|
|||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
error (_("breakpoint %d not found."), bnum);
|
error (_("breakpoint %d not found."), bnum);
|
||||||
|
|
||||||
mi_command_line_array = argv;
|
int count = 1;
|
||||||
mi_command_line_array_ptr = 1;
|
auto reader
|
||||||
mi_command_line_array_cnt = argc;
|
= [&] ()
|
||||||
|
{
|
||||||
|
const char *result = nullptr;
|
||||||
|
if (count < argc)
|
||||||
|
result = argv[count++];
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
if (is_tracepoint (b))
|
if (is_tracepoint (b))
|
||||||
break_command = read_command_lines_1 (mi_read_next_line, 1,
|
break_command = read_command_lines_1 (reader, 1,
|
||||||
check_tracepoint_command, b);
|
[=] (const char *line)
|
||||||
|
{
|
||||||
|
validate_actionline (line, b);
|
||||||
|
});
|
||||||
else
|
else
|
||||||
break_command = read_command_lines_1 (mi_read_next_line, 1, 0, 0);
|
break_command = read_command_lines_1 (reader, 1, 0);
|
||||||
|
|
||||||
breakpoint_set_commands (b, std::move (break_command));
|
breakpoint_set_commands (b, std::move (break_command));
|
||||||
}
|
}
|
||||||
|
@ -579,8 +579,10 @@ actions_command (const char *args, int from_tty)
|
|||||||
|
|
||||||
counted_command_line l = read_command_lines (tmpbuf.c_str (),
|
counted_command_line l = read_command_lines (tmpbuf.c_str (),
|
||||||
from_tty, 1,
|
from_tty, 1,
|
||||||
check_tracepoint_command,
|
[=] (const char *line)
|
||||||
t);
|
{
|
||||||
|
validate_actionline (line, t);
|
||||||
|
});
|
||||||
breakpoint_set_commands (t, std::move (l));
|
breakpoint_set_commands (t, std::move (l));
|
||||||
}
|
}
|
||||||
/* else just return */
|
/* else just return */
|
||||||
|
Loading…
Reference in New Issue
Block a user