diff options
author | Tom Tromey <tom@tromey.com> | 2017-04-05 21:14:09 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-04-12 11:16:17 -0600 |
commit | 93921405a46c0a58eae19fffb92e02416082801a (patch) | |
tree | c3a9c2a4407cb09bc571d5af47dce812a68169b0 /gdb/cli | |
parent | ffc2605c41d026cf5710704848b7c3b1cdbdcf49 (diff) | |
download | gdb-93921405a46c0a58eae19fffb92e02416082801a.zip gdb-93921405a46c0a58eae19fffb92e02416082801a.tar.gz gdb-93921405a46c0a58eae19fffb92e02416082801a.tar.bz2 |
Introduce command_line_up
This introduces command_line_up, a unique_ptr for command_line
objects, and changes many places to use it. This removes a number of
cleanups.
Command lines are funny in that sometimes they are reference counted.
Once there is more C++-ification of some of the users, perhaps all of
these can be changed to use shared_ptr instead.
gdb/ChangeLog
2017-04-12 Tom Tromey <tom@tromey.com>
* tracepoint.c (actions_command): Update.
* python/python.c (python_command, python_interactive_command):
Update.
* mi/mi-cmd-break.c (mi_cmd_break_commands): Update.
* guile/guile.c (guile_command): Update.
* defs.h (read_command_lines, read_command_lines_1): Return
command_line_up.
(command_lines_deleter): New struct.
(command_line_up): New typedef.
* compile/compile.c (compile_code_command)
(compile_print_command): Update.
* cli/cli-script.h (get_command_line, copy_command_lines): Return
command_line_up.
(make_cleanup_free_command_lines): Remove.
* cli/cli-script.c (get_command_line, read_command_lines_1)
(copy_command_lines): Return command_line_up.
(while_command, if_command, read_command_lines, define_command)
(document_command): Update.
(do_free_command_lines_cleanup, make_cleanup_free_command_lines):
Remove.
* breakpoint.h (breakpoint_set_commands): Change type of
"commands".
* breakpoint.c (breakpoint_set_commands): Change type of
"commands". Update.
(do_map_commands_command, update_dprintf_command_list)
(create_tracepoint_from_upload): Update.
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-script.c | 85 | ||||
-rw-r--r-- | gdb/cli/cli-script.h | 9 |
2 files changed, 29 insertions, 65 deletions
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 33b657d..e0e27ef 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -165,27 +165,20 @@ build_command_line (enum command_control_type type, const char *args) /* Build and return a new command structure for the control commands such as "if" and "while". */ -struct command_line * +command_line_up get_command_line (enum command_control_type type, const char *arg) { - struct command_line *cmd; - struct cleanup *old_chain = NULL; - /* Allocate and build a new command line structure. */ - cmd = build_command_line (type, arg); - - old_chain = make_cleanup_free_command_lines (&cmd); + command_line_up cmd (build_command_line (type, arg)); /* Read in the body of this command. */ - if (recurse_read_control_structure (read_next_line, cmd, 0, 0) + if (recurse_read_control_structure (read_next_line, cmd.get (), 0, 0) == invalid_control) { warning (_("Error reading in canned sequence of commands.")); - do_cleanups (old_chain); return NULL; } - discard_cleanups (old_chain); return cmd; } @@ -677,18 +670,15 @@ execute_control_command_untraced (struct command_line *cmd) static void while_command (char *arg, int from_tty) { - struct command_line *command = NULL; - control_level = 1; - command = get_command_line (while_control, arg); + command_line_up command = get_command_line (while_control, arg); if (command == NULL) return; scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); - execute_control_command_untraced (command); - free_command_lines (&command); + execute_control_command_untraced (command.get ()); } /* "if" command support. Execute either the true or false arm depending @@ -697,19 +687,15 @@ while_command (char *arg, int from_tty) static void if_command (char *arg, int from_tty) { - struct command_line *command = NULL; - struct cleanup *old_chain; - control_level = 1; - command = get_command_line (if_control, arg); + command_line_up command = get_command_line (if_control, arg); if (command == NULL) return; scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); - execute_control_command_untraced (command); - free_command_lines (&command); + execute_control_command_untraced (command.get ()); } /* Bind the incoming arguments for a user defined command to $arg0, @@ -1208,12 +1194,10 @@ restore_interp (void *arg) #define END_MESSAGE "End with a line saying just \"end\"." -struct command_line * +command_line_up read_command_lines (char *prompt_arg, int from_tty, int parse_commands, void (*validator)(char *, void *), void *closure) { - struct command_line *head; - if (from_tty && input_interactive_p (current_ui)) { if (deprecated_readline_begin_hook) @@ -1232,6 +1216,7 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands, /* Reading commands assumes the CLI behavior, so temporarily override the current interpreter with CLI. */ + command_line_up head; if (current_interp_named_p (INTERP_CONSOLE)) head = read_command_lines_1 (read_next_line, parse_commands, validator, closure); @@ -1256,17 +1241,17 @@ read_command_lines (char *prompt_arg, int from_tty, int parse_commands, /* Act the same way as read_command_lines, except that each new line is obtained using READ_NEXT_LINE_FUNC. */ -struct command_line * +command_line_up read_command_lines_1 (char * (*read_next_line_func) (void), int parse_commands, void (*validator)(char *, void *), void *closure) { - struct command_line *head, *tail, *next; - struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); + struct command_line *tail, *next; + command_line_up head; enum command_control_type ret; enum misc_command_type val; control_level = 0; - head = tail = NULL; + tail = NULL; while (1) { @@ -1307,18 +1292,15 @@ read_command_lines_1 (char * (*read_next_line_func) (void), int parse_commands, } else { - head = next; - make_cleanup_free_command_lines (&head); + head.reset (next); } tail = next; } dont_repeat (); - if (ret != invalid_control) - discard_cleanups (old_chain); - else - do_cleanups (old_chain); + if (ret == invalid_control) + return NULL; return head; } @@ -1349,19 +1331,7 @@ free_command_lines (struct command_line **lptr) *lptr = NULL; } -static void -do_free_command_lines_cleanup (void *arg) -{ - free_command_lines ((struct command_line **) arg); -} - -struct cleanup * -make_cleanup_free_command_lines (struct command_line **arg) -{ - return make_cleanup (do_free_command_lines_cleanup, arg); -} - -struct command_line * +command_line_up copy_command_lines (struct command_line *cmds) { struct command_line *result = NULL; @@ -1370,7 +1340,7 @@ copy_command_lines (struct command_line *cmds) { result = XNEW (struct command_line); - result->next = copy_command_lines (cmds->next); + result->next = copy_command_lines (cmds->next).release (); result->line = xstrdup (cmds->line); result->control_type = cmds->control_type; result->body_count = cmds->body_count; @@ -1381,13 +1351,14 @@ copy_command_lines (struct command_line *cmds) 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]); + result->body_list[i] + = copy_command_lines (cmds->body_list[i]).release (); } else result->body_list = NULL; } - return result; + return command_line_up (result); } /* Validate that *COMNAME is a valid name for a command. Return the @@ -1460,7 +1431,6 @@ define_command (char *comname, int from_tty) CMD_PRE_HOOK, CMD_POST_HOOK }; - struct command_line *cmds; struct cmd_list_element *c, *newc, *hookc = 0, **list; char *tem, *comfull; const char *tem_c; @@ -1536,7 +1506,7 @@ define_command (char *comname, int from_tty) xsnprintf (tmpbuf, sizeof (tmpbuf), "Type commands for definition of \"%s\".", comfull); - cmds = read_command_lines (tmpbuf, from_tty, 1, 0, 0); + command_line_up cmds = read_command_lines (tmpbuf, from_tty, 1, 0, 0); if (c && c->theclass == class_user) free_command_lines (&c->user_commands); @@ -1544,7 +1514,7 @@ define_command (char *comname, int from_tty) newc = add_cmd (comname, class_user, user_defined_command, (c && c->theclass == class_user) ? c->doc : xstrdup ("User-defined."), list); - newc->user_commands = cmds; + newc->user_commands = cmds.release (); /* If this new command is a hook, then mark both commands as being tied. */ @@ -1571,7 +1541,6 @@ define_command (char *comname, int from_tty) static void document_command (char *comname, int from_tty) { - struct command_line *doclines; struct cmd_list_element *c, **list; const char *tem; char *comfull; @@ -1588,7 +1557,7 @@ document_command (char *comname, int from_tty) xsnprintf (tmpbuf, sizeof (tmpbuf), "Type documentation for \"%s\".", comfull); - doclines = read_command_lines (tmpbuf, from_tty, 0, 0, 0); + command_line_up doclines = read_command_lines (tmpbuf, from_tty, 0, 0, 0); if (c->doc) xfree ((char *) c->doc); @@ -1598,13 +1567,13 @@ document_command (char *comname, int from_tty) int len = 0; char *doc; - for (cl1 = doclines; cl1; cl1 = cl1->next) + for (cl1 = doclines.get (); cl1; cl1 = cl1->next) len += strlen (cl1->line) + 1; doc = (char *) xmalloc (len + 1); *doc = 0; - for (cl1 = doclines; cl1; cl1 = cl1->next) + for (cl1 = doclines.get (); cl1; cl1 = cl1->next) { strcat (doc, cl1->line); if (cl1->next) @@ -1613,8 +1582,6 @@ document_command (char *comname, int from_tty) c->doc = doc; } - - free_command_lines (&doclines); } struct source_cleanup_lines_args diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h index c885976..9514938 100644 --- a/gdb/cli/cli-script.h +++ b/gdb/cli/cli-script.h @@ -38,16 +38,13 @@ extern enum command_control_type extern enum command_control_type execute_control_command_untraced (struct command_line *cmd); -extern struct command_line *get_command_line (enum command_control_type, - const char *); +extern command_line_up get_command_line (enum command_control_type, + const char *); extern void print_command_lines (struct ui_out *, struct command_line *, unsigned int); -extern struct command_line * copy_command_lines (struct command_line *cmds); - -extern struct cleanup * - make_cleanup_free_command_lines (struct command_line **arg); +extern command_line_up copy_command_lines (struct command_line *cmds); /* Exported to gdb/infrun.c */ |