From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10310 invoked by alias); 9 May 2013 18:49:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 10301 invoked by uid 89); 9 May 2013 18:49:12 -0000 X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,TW_FN,TW_RG autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 09 May 2013 18:49:11 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r49InAUK017622 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 9 May 2013 14:49:10 -0400 Received: from barimba (ovpn-113-133.phx2.redhat.com [10.3.113.133]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r49In7I4009717 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 9 May 2013 14:49:08 -0400 From: Tom Tromey From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 02/40] some cleanup checker fixes In-Reply-To: References: Message-Id: Date: Thu, 09 May 2013 18:49:00 -0000 MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-05/txt/msg00317.txt.bz2 Fix some bugs pointed out by the cleanup checker. This one just fixes some simple CLI reports, where CLI commands know that their caller will do cleanups. This an older style with few instances, so it is simpler to fix them up than to teach the checker about it. * cli/cli-cmds.c (cd_command, alias_command): Call do_cleanups. * cli/cli-dump.c (restore_binary_file): Call do_cleanups. * interps.c (interpreter_exec_cmd): Call do_cleanups. * source.c (show_substitute_path_command): Call do_cleanups. (unset_substitute_path_command, set_substitute_path_command): Likewise. * symfile.c (load_command): Call do_cleanups. --- gdb/cli/cli-cmds.c | 10 ++++++++-- gdb/cli/cli-dump.c | 3 ++- gdb/interps.c | 5 ++++- gdb/source.c | 15 ++++++++++++--- gdb/symfile.c | 4 ++++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index cf88b6d..6ee7673 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -357,6 +357,7 @@ cd_command (char *dir, int from_tty) /* Found something other than leading repetitions of "/..". */ int found_real_path; char *p; + struct cleanup *cleanup; /* If the new directory is absolute, repeat is a no-op; if relative, repeat might be useful but is more likely to be a mistake. */ @@ -366,7 +367,7 @@ cd_command (char *dir, int from_tty) dir = "~"; dir = tilde_expand (dir); - make_cleanup (xfree, dir); + cleanup = make_cleanup (xfree, dir); if (chdir (dir) < 0) perror_with_name (dir); @@ -450,6 +451,8 @@ cd_command (char *dir, int from_tty) if (from_tty) pwd_command ((char *) 0, 1); + + do_cleanups (cleanup); } /* Show the current value of the 'script-extension' option. */ @@ -1327,13 +1330,14 @@ alias_command (char *args, int from_tty) char *args2, *equals, *alias, *command; char **alias_argv, **command_argv; dyn_string_t alias_dyn_string, command_dyn_string; + struct cleanup *cleanup; static const char usage[] = N_("Usage: alias [-a] [--] ALIAS = COMMAND"); if (args == NULL || strchr (args, '=') == NULL) error (_(usage)); args2 = xstrdup (args); - make_cleanup (xfree, args2); + cleanup = make_cleanup (xfree, args2); equals = strchr (args2, '='); *equals = '\0'; alias_argv = gdb_buildargv (args2); @@ -1440,6 +1444,8 @@ alias_command (char *args, int from_tty) command_argv[command_argc - 1], class_alias, abbrev_flag, c_command->prefixlist); } + + do_cleanups (cleanup); } /* Print a list of files and line numbers which a user may choose from diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index 529e0a0..208916c 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -508,6 +508,7 @@ restore_section_callback (bfd *ibfd, asection *isec, void *args) static void restore_binary_file (char *filename, struct callback_data *data) { + struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); FILE *file = fopen_with_cleanup (filename, FOPEN_RB); gdb_byte *buf; long len; @@ -553,7 +554,7 @@ restore_binary_file (char *filename, struct callback_data *data) len = target_write_memory (data->load_start + data->load_offset, buf, len); if (len != 0) warning (_("restore: memory write failed (%s)."), safe_strerror (len)); - return; + do_cleanups (cleanup); } static void diff --git a/gdb/interps.c b/gdb/interps.c index bd23118..25500d6 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -409,12 +409,13 @@ interpreter_exec_cmd (char *args, int from_tty) unsigned int nrules; unsigned int i; int old_quiet, use_quiet; + struct cleanup *cleanup; if (args == NULL) error_no_arg (_("interpreter-exec command")); prules = gdb_buildargv (args); - make_cleanup_freeargv (prules); + cleanup = make_cleanup_freeargv (prules); nrules = 0; for (trule = prules; *trule != NULL; trule++) @@ -452,6 +453,8 @@ interpreter_exec_cmd (char *args, int from_tty) interp_set (old_interp, 0); interp_set_quiet (interp_to_use, use_quiet); interp_set_quiet (old_interp, old_quiet); + + do_cleanups (cleanup); } /* List the possible interpreters which could complete the given text. */ diff --git a/gdb/source.c b/gdb/source.c index 710b90c..161a6c4 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1840,9 +1840,10 @@ show_substitute_path_command (char *args, int from_tty) struct substitute_path_rule *rule = substitute_path_rules; char **argv; char *from = NULL; + struct cleanup *cleanup; argv = gdb_buildargv (args); - make_cleanup_freeargv (argv); + cleanup = make_cleanup_freeargv (argv); /* We expect zero or one argument. */ @@ -1866,6 +1867,8 @@ show_substitute_path_command (char *args, int from_tty) printf_filtered (" `%s' -> `%s'.\n", rule->from, rule->to); rule = rule->next; } + + do_cleanups (cleanup); } /* Implement the "unset substitute-path" command. */ @@ -1877,10 +1880,11 @@ unset_substitute_path_command (char *args, int from_tty) char **argv = gdb_buildargv (args); char *from = NULL; int rule_found = 0; + struct cleanup *cleanup; /* This function takes either 0 or 1 argument. */ - make_cleanup_freeargv (argv); + cleanup = make_cleanup_freeargv (argv); if (argv != NULL && argv[0] != NULL && argv[1] != NULL) error (_("Incorrect usage, too many arguments in command")); @@ -1918,6 +1922,8 @@ unset_substitute_path_command (char *args, int from_tty) error (_("No substitution rule defined for `%s'"), from); forget_cached_source_info (); + + do_cleanups (cleanup); } /* Add a new source path substitution rule. */ @@ -1927,9 +1933,10 @@ set_substitute_path_command (char *args, int from_tty) { char **argv; struct substitute_path_rule *rule; + struct cleanup *cleanup; argv = gdb_buildargv (args); - make_cleanup_freeargv (argv); + cleanup = make_cleanup_freeargv (argv); if (argv == NULL || argv[0] == NULL || argv [1] == NULL) error (_("Incorrect usage, too few arguments in command")); @@ -1956,6 +1963,8 @@ set_substitute_path_command (char *args, int from_tty) add_substitute_path_rule (argv[0], argv[1]); forget_cached_source_info (); + + do_cleanups (cleanup); } diff --git a/gdb/symfile.c b/gdb/symfile.c index 32d6ad0..f93d857 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1813,6 +1813,8 @@ find_sym_fns (bfd *abfd) static void load_command (char *arg, int from_tty) { + struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); + dont_repeat (); /* The user might be reloading because the binary has changed. Take @@ -1862,6 +1864,8 @@ load_command (char *arg, int from_tty) /* After re-loading the executable, we don't really know which overlays are mapped any more. */ overlay_cache_invalid = 1; + + do_cleanups (cleanup); } /* This version of "load" should be usable for any target. Currently -- 1.8.1.4