From patchwork Mon Jan 29 12:46:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roirand X-Patchwork-Id: 25663 Received: (qmail 113665 invoked by alias); 29 Jan 2018 12:47:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 113652 invoked by uid 89); 29 Jan 2018 12:47:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f194.google.com Received: from mail-wr0-f194.google.com (HELO mail-wr0-f194.google.com) (209.85.128.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Jan 2018 12:47:05 +0000 Received: by mail-wr0-f194.google.com with SMTP id 41so5644585wrc.9 for ; Mon, 29 Jan 2018 04:47:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GOiI09C36ppDuqEngEyXuXiftUdxL8g/MEAXx9B1OvI=; b=mluDo/BsSp7zxmFB7gu0xFxoyc+x/FVPATaWtM19ZJXOV3w9iVa9OOy6Z5eIhkbJ7J O4aUrcg1Myn0jnr7H3ezz56qesAvmc8qoo+PilhUBBN5UCa+kHpPNqwfAC6vjJ2ja4mP U/PvuxeLisxtq+2+NAp5T9xjkUFUoWoKOFiphXtzd7A1IGd7JCFtOQYhIM3JsjXLn7sv 0GCGrOQf0cdxzeQ9OlGmaTczniUDxYljafqxYatqBV7jCaEKAQ1E8w51+atwZMbX55/w mfebdq76B2mpc4MIN6lYMJVZg4TIhamgYkPViL7V2ETgC3uuryhINu8pH9iorhykvEkx UBHA== X-Gm-Message-State: AKwxytdb4MANO3OLBZvq52Qw97pMzsYfjRgN2f0pYz0OBqSvO7kkPgD7 c8nd48JO2iiwH5TE3kaNmHqIO7Pq X-Google-Smtp-Source: AH8x224Rbsf6SEjSPWIiyipQ/or6aJ9uatHOfeOyOJXgo/WujtH/X9nx+3De6YaSq8+23zL6NZ+9mA== X-Received: by 10.223.189.15 with SMTP id j15mr16533935wrh.1.1517230023129; Mon, 29 Jan 2018 04:47:03 -0800 (PST) Received: from adacore.com ([46.18.100.10]) by smtp.gmail.com with ESMTPSA id w83sm7499474wma.47.2018.01.29.04.47.01 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 29 Jan 2018 04:47:02 -0800 (PST) Received: by adacore.com (sSMTP sendmail emulation); Mon, 29 Jan 2018 13:47:00 +0100 From: Xavier Roirand To: gdb-patches@sourceware.org Cc: Xavier Roirand , brobecker@adacore.com Subject: [PATCH 3/4] (Ada) C++fy conditional string when catching exception. Date: Mon, 29 Jan 2018 13:46:59 +0100 Message-Id: <1517230019-30061-1-git-send-email-roirand@adacore.com> In-Reply-To: <20180123114306.b6w2csxzygomqlnd@adacore.com> References: <20180123114306.b6w2csxzygomqlnd@adacore.com> X-IsSubscribed: yes This commit C++fy the conditional string used when catching Ada exception. gdb/ChangeLog: * ada-lang.c (catch_ada_exception_command_split) (create_ada_exception_catchpoint) : Change parameter type. Update code accordingly. (catch_ada_exception_command, catch_ada_handlers_command): Use C++ string instead of char* for conditional var. (catch_ada_assert_command_split) : Change parameter type. Update code accordingly. (catch_assert_command): Use C++ string instead of char* for conditional var. * ada-lang.h (create_ada_exception_catchpoint) : Update declaration. * mi/mi-cmd-catch.c (mi_cmd_catch_assert, mi_cmd_catch_exception: Use std::string instead of char* for condition string. Tested on x86_64-linux. --- gdb/ada-lang.c | 27 ++++++++++++++------------- gdb/ada-lang.h | 4 ++-- gdb/mi/mi-cmd-catch.c | 18 ++++++------------ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 3ff7169..0da58d9 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13142,7 +13142,7 @@ catch_ada_exception_command_split (const char *args, bool is_catch_handlers_cmd, enum ada_exception_catchpoint_kind *ex, char **excep_string, - char **cond_string) + std::string &cond_string) { struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); char *exception_name; @@ -13209,7 +13209,8 @@ catch_ada_exception_command_split (const char *args, *ex = ada_catch_exception; *excep_string = exception_name; } - *cond_string = cond; + if (cond != NULL) + cond_string.assign (cond); } /* Return the name of the symbol on which we should break in order to @@ -13400,7 +13401,7 @@ void create_ada_exception_catchpoint (struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind, char *excep_string, - char *cond_string, + const std::string &cond_string, int tempflag, int disabled, int from_tty) @@ -13415,8 +13416,8 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch, ops, tempflag, disabled, from_tty); c->excep_string = excep_string; create_excep_cond_exprs (c.get (), ex_kind); - if (cond_string != NULL) - set_breakpoint_condition (c.get (), cond_string, from_tty); + if (!cond_string.empty ()) + set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty); install_breakpoint (0, std::move (c), 1); } @@ -13431,14 +13432,14 @@ catch_ada_exception_command (const char *arg_entry, int from_tty, int tempflag; enum ada_exception_catchpoint_kind ex_kind; char *excep_string = NULL; - char *cond_string = NULL; + std::string cond_string; tempflag = get_cmd_context (command) == CATCH_TEMPORARY; if (!arg) arg = ""; catch_ada_exception_command_split (arg, false, &ex_kind, &excep_string, - &cond_string); + cond_string); create_ada_exception_catchpoint (gdbarch, ex_kind, excep_string, cond_string, tempflag, 1 /* enabled */, @@ -13456,14 +13457,14 @@ catch_ada_handlers_command (const char *arg_entry, int from_tty, int tempflag; enum ada_exception_catchpoint_kind ex_kind; char *excep_string = NULL; - char *cond_string = NULL; + std::string cond_string; tempflag = get_cmd_context (command) == CATCH_TEMPORARY; if (!arg) arg = ""; catch_ada_exception_command_split (arg, true, &ex_kind, &excep_string, - &cond_string); + cond_string); create_ada_exception_catchpoint (gdbarch, ex_kind, excep_string, cond_string, tempflag, 1 /* enabled */, @@ -13479,7 +13480,7 @@ catch_ada_handlers_command (const char *arg_entry, int from_tty, (the memory needs to be deallocated after use). */ static void -catch_ada_assert_command_split (const char *args, char **cond_string) +catch_ada_assert_command_split (const char *args, std::string &cond_string) { args = skip_spaces (args); @@ -13491,7 +13492,7 @@ catch_ada_assert_command_split (const char *args, char **cond_string) args = skip_spaces (args); if (args[0] == '\0') error (_("condition missing after `if' keyword")); - *cond_string = xstrdup (args); + cond_string.assign (args); } /* Otherwise, there should be no other argument at the end of @@ -13509,13 +13510,13 @@ catch_assert_command (const char *arg_entry, int from_tty, const char *arg = arg_entry; struct gdbarch *gdbarch = get_current_arch (); int tempflag; - char *cond_string = NULL; + std::string cond_string; tempflag = get_cmd_context (command) == CATCH_TEMPORARY; if (!arg) arg = ""; - catch_ada_assert_command_split (arg, &cond_string); + catch_ada_assert_command_split (arg, cond_string); create_ada_exception_catchpoint (gdbarch, ada_catch_assert, NULL, cond_string, tempflag, 1 /* enabled */, diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index bac6c06..1f6ea77 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -379,8 +379,8 @@ extern std::string ada_name_for_lookup (const char *name); extern void create_ada_exception_catchpoint (struct gdbarch *gdbarch, enum ada_exception_catchpoint_kind ex_kind, - char *excep_string, char *cond_string, int tempflag, int disabled, - int from_tty); + char *excep_string, const std::string &cond_string, int tempflag, + int disabled, int from_tty); /* Some information about a given Ada exception. */ diff --git a/gdb/mi/mi-cmd-catch.c b/gdb/mi/mi-cmd-catch.c index 38b96cc..a0f311a 100644 --- a/gdb/mi/mi-cmd-catch.c +++ b/gdb/mi/mi-cmd-catch.c @@ -32,7 +32,7 @@ void mi_cmd_catch_assert (const char *cmd, char *argv[], int argc) { struct gdbarch *gdbarch = get_current_arch(); - char *condition = NULL; + std::string condition; int enabled = 1; int temp = 0; @@ -62,7 +62,7 @@ mi_cmd_catch_assert (const char *cmd, char *argv[], int argc) switch ((enum opt) opt) { case OPT_CONDITION: - condition = oarg; + condition.assign (oarg); break; case OPT_DISABLED: enabled = 0; @@ -79,10 +79,6 @@ mi_cmd_catch_assert (const char *cmd, char *argv[], int argc) error (_("Invalid argument: %s"), argv[oind]); scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting (); - /* create_ada_exception_catchpoint needs CONDITION to be xstrdup'ed, - and will assume control of its lifetime. */ - if (condition != NULL) - condition = xstrdup (condition); create_ada_exception_catchpoint (gdbarch, ada_catch_assert, NULL, condition, temp, enabled, 0); } @@ -93,7 +89,7 @@ void mi_cmd_catch_exception (const char *cmd, char *argv[], int argc) { struct gdbarch *gdbarch = get_current_arch(); - char *condition = NULL; + std::string condition; int enabled = 1; char *exception_name = NULL; int temp = 0; @@ -128,7 +124,7 @@ mi_cmd_catch_exception (const char *cmd, char *argv[], int argc) switch ((enum opt) opt) { case OPT_CONDITION: - condition = oarg; + condition.assign (oarg); break; case OPT_DISABLED: enabled = 0; @@ -156,12 +152,10 @@ mi_cmd_catch_exception (const char *cmd, char *argv[], int argc) error (_("\"-e\" and \"-u\" are mutually exclusive")); scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting (); - /* create_ada_exception_catchpoint needs EXCEPTION_NAME and CONDITION - to be xstrdup'ed, and will assume control of their lifetime. */ + /* create_ada_exception_catchpoint needs EXCEPTION_NAME to be + xstrdup'ed, and will assume control of its lifetime. */ if (exception_name != NULL) exception_name = xstrdup (exception_name); - if (condition != NULL) - condition = xstrdup (condition); create_ada_exception_catchpoint (gdbarch, ex_kind, exception_name, condition, temp, enabled, 0);