From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122964 invoked by alias); 19 Oct 2016 01:12:26 -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 122797 invoked by uid 89); 19 Oct 2016 01:12:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=1029, 1457,7, 14577, sk:clear_b X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Oct 2016 01:12:24 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B91181F03 for ; Wed, 19 Oct 2016 01:12:23 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9J1CJjY019701 for ; Tue, 18 Oct 2016 21:12:22 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 03/31] breakpoint.c:commands_command_1 constification and cleanup Date: Wed, 19 Oct 2016 01:13:00 -0000 Message-Id: <1476839539-8374-4-git-send-email-palves@redhat.com> In-Reply-To: <1476839539-8374-1-git-send-email-palves@redhat.com> References: <1476839539-8374-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-10/txt/msg00541.txt.bz2 This is constification needed for next patch. Adjust commands_command_1 to use std::string too because the "arg" parameter is currently overwritten and then passed to make_cleanup. The constification alone would trigger a compile error in the make_cleanup call otherwise (passing const char * to void * parameter). Using std::string gets rid of the cleanup in the first place, resulting in simpler code. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * breakpoint.c (struct commands_info) : Constify. (commands_command_1): Constify 'arg' parameter. Use std::string and string_printf. (commands_from_control_command): Constify 'arg' parameter. (map_breakpoint_numbers): Constify 'args' parameter. * breakpoint.h (commands_from_control_command): Constify 'arg' parameter. --- gdb/breakpoint.c | 42 +++++++++++++++++------------------------- gdb/breakpoint.h | 2 +- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 32d6a95..c9b151f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -102,8 +102,9 @@ static void disable_command (char *, int); static void enable_command (char *, int); -static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, - void *), +static void map_breakpoint_numbers (const char *, + void (*) (struct breakpoint *, + void *), void *); static void ignore_command (char *, int); @@ -1338,7 +1339,7 @@ struct commands_info int from_tty; /* The breakpoint range spec. */ - char *arg; + const char *arg; /* Non-NULL if the body of the commands are being read from this already-parsed command. */ @@ -1399,7 +1400,7 @@ do_map_commands_command (struct breakpoint *b, void *data) } static void -commands_command_1 (char *arg, int from_tty, +commands_command_1 (const char *arg, int from_tty, struct command_line *control) { struct cleanup *cleanups; @@ -1412,32 +1413,22 @@ commands_command_1 (char *arg, int from_tty, extra reference to the commands that we must clean up. */ cleanups = make_cleanup_decref_counted_command_line (&info.cmd); + std::string new_arg; + if (arg == NULL || !*arg) { if (breakpoint_count - prev_breakpoint_count > 1) - arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, - breakpoint_count); + new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, + breakpoint_count); else if (breakpoint_count > 0) - arg = xstrprintf ("%d", breakpoint_count); - else - { - /* So that we don't try to free the incoming non-NULL - argument in the cleanup below. Mapping breakpoint - numbers will fail in this case. */ - arg = NULL; - } + new_arg = string_printf ("%d", breakpoint_count); } else - /* The command loop has some static state, so we need to preserve - our argument. */ - arg = xstrdup (arg); - - if (arg != NULL) - make_cleanup (xfree, arg); + new_arg = arg; - info.arg = arg; + info.arg = new_arg.c_str (); - map_breakpoint_numbers (arg, do_map_commands_command, &info); + map_breakpoint_numbers (info.arg, do_map_commands_command, &info); if (info.cmd == NULL) error (_("No breakpoints specified.")); @@ -1457,7 +1448,7 @@ commands_command (char *arg, int from_tty) This is used by cli-script.c to DTRT with breakpoint commands that are part of if and while bodies. */ enum command_control_type -commands_from_control_command (char *arg, struct command_line *cmd) +commands_from_control_command (const char *arg, struct command_line *cmd) { commands_command_1 (arg, 0, cmd); return simple_control; @@ -14769,8 +14760,9 @@ ignore_command (char *args, int from_tty) whose numbers are given in ARGS. */ static void -map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, - void *), +map_breakpoint_numbers (const char *args, + void (*function) (struct breakpoint *, + void *), void *data) { int num; diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h index aaff3d5..ebaf1e3 100644 --- a/gdb/breakpoint.h +++ b/gdb/breakpoint.h @@ -1456,7 +1456,7 @@ extern void enable_breakpoints_after_startup (void); after they've already read the commands into a struct command_line. */ extern enum command_control_type commands_from_control_command - (char *arg, struct command_line *cmd); + (const char *arg, struct command_line *cmd); extern void clear_breakpoint_hit_counts (void); -- 2.5.5